forked from crawl/crawl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground_creation.txt
133 lines (109 loc) · 5.88 KB
/
background_creation.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
Written by Cerol, 2017/02/07
Backgrounds are one of the simplest gameplay elements to modify in the DCSS
codebase, as they only really determine things at character creation. Within the
code itself, they're usually referred to as jobs, not backgrounds, so I'll be
using these terms interchangeably. There's no code that checks for your starting
job later on, they just boost your stats a little and supply you with your
starting gear. I'll write up how to add a new background to the game here.
Note that this is meant to be a technical explanation of how to do this, and not
a game design discussion. Everything being implemented isn't meant to be a
serious addition to the game, just an example of how to add your own ideas.
We're going to add in a Shepherd job today. I feel there's a lack of peaceful,
relaxing jobs in the game, so we'll fill that space with our new job.
First we need to edit job-type.h to tell the game our new job exists. Search
for "enum job_type", and we'll add in an entry right before the NUM_JOBS line.
This should look like:
JOB_ABYSSAL_KNIGHT,
#if TAG_MAJOR_VERSION == 34
JOB_JESTER,
#endif
JOB_SHEPHERD,
NUM_JOBS, // always after the last job
Two side-notes here. First, you'll see that TAG_MAJOR_VERSION thing all over the
code base. Don't bother adding it in yourself. It's mostly used as shorthand to
mark code that isn't being used or could be removed. Second, the NUM_JOBS entry
in the enum list is a special value used pretty often in the codebase. Make sure
your new entry is right above NUM_JOBS for save compatibility reasons. Changing
the list in any other way might cause saved characters to change jobs mid-game
or throw errors later.
Second, we need to add the actual data for the background. For this, we go into
job-data.h. This struct in this file is reasonably well-explained:
struct job_def
{
const char* abbrev; ///< Two-letter abbreviation
const char* name; ///< Long name
int s, i, d; ///< Starting Str, Int, and Dex
/// Which species are good at it
/// No recommended species = job is disabled
vector<species_type> recommended_species;
/// What spells start out in their library?
/// The first spell in the list will be memorised at the start of the game,
/// if it's level 1 and not useless.
vector<spell_type> library;
/// Guaranteed starting equipment. Uses vault spec syntax, with the plus:,
/// charges:, q:, and ego: tags supported.
vector<string> equipment;
weapon_choice wchoice; ///< how the weapon is chosen, if any
vector<pair<skill_type, int>> skills; ///< starting skills
};
The best thing to do is to copy an existing class and edit its entries, just
to make sure you get the structure right. Also note that this file sorts the
entries alphabetically, so we'll follow suit here. Let's fill in our typical
herd-watcher:
// First, the basics:
{ JOB_SHEPHERD, {
"Sh", "Shepherd",
// Fieldwork keeps shepherds in good shape, and gives them lots of
// time to think.
12, 11, 12,
// Most shepherds are common folk.
{ SP_HUMAN, SP_MINOTAUR, SP_TENGU, SP_TROLL, SP_NAGA,
SP_VINE_STALKER, },
// Shepherds aren't skilled at magic, beyond a cantrip or two.
{ SPELL_CHAIN_LIGHTNING, SPELL_SHATTER,
SPELL_POLAR_VORTEX, SPELL_FIRE_STORM },
// They should have a light breezy garment, something to read to
// pass the time, and a staff to protect their flock
{ "gold dragon scales plus:9", "scroll of acquirement q:10",
"greatsword plus:9 ego:flaming" },
WCHOICE_NONE,
// and just a couple skill points in stuff you might do around a field.
{ { SK_FIGHTING, 6 }, { SK_SUMMONING, 8 }, { SK_SPELLCASTING, 3 },
{ SK_DODGING, 3 }, { SK_ARMOUR, 4 } { SK_STEALTH, 1 }, },
} },
That looks like what I expect a shepherd to look like: lightly armed, lightly
armoured, and just a speck of potential. Other bits of code will ensure any
weapons and armour are automatically equipped at creation (but not staves or
other equippables!).
If you skip one of the above steps, you'll hit an ASSERT error after running
the game. This is the typical way DCSS handles errors: Check for things that
shouldn't be and crash early with a clear message instead of crashing later
with a cryptic code dump.
The last step is to add it to the start-up menu. This is handled in newgame.cc,
and we need to edit the jobs_order[] array to add ours in. I think Shepherds
count as a Adventurer, so I'll update the entry for them:
{
"Adventurer",
coord_def(0, 7), 15,
{ JOB_ARTIFICER, JOB_WANDERER, JOB_DELVER, JOB_SHEPHERD }
},
And we're done. Compile and enjoy your new background!
... Unless your background has some other, more complicated starting situation
the way that Abyssal Knights and Chaos Knights do. Those can be set
in ng-setup.cc. If you have some limitations or restrictions on your job (like
locking out a species for some reason, or if a piece of gear would be limited by
some racial element), you can add those checks into ng-restr.cc. Finally,
the only other job-related special case is the Monk, which gets its piety
bonus handled in religion.cc.
Wanderers are special, and get their own file. There are 7 total files that
backgrounds touch on for their stuff right now. In most cases you should
only have to edit 3.
Summary and checklist:
- job-type.h to add the background to the list
- job-data.h to fill in info about the job.
- newgame.cc to add it to the selection menu.
- ng-setup.cc for any factors you can't set in the job struct.
(and/or religion.cc if you're messing with piety after character
creation like the monk.)
- ng-restr.cc for limitations to your background.
- ng-wanderer.cc for wanderer nonsense.