Debian Codegraph @

src/doc/new-egos.rst

raw
1 ******************
2 A Guide to Affixes
3 ******************
4
5 Introduction
6 ============
7
8 This work was based on some ideas vaguely expressed in http://angband-dev.blogspot.com/2011/09/so-what-exactly-is-ego-item-anyway.html
9 (editor's note: that was done in the context of the v4 branch of Angband's
10 development; what follows has been left as is; ego items in Angband 4
11 remain broadly similar to the Angband 3.3 implementation mentioned here but
12 there's been some renaming and restructuring of the lines in ego_item.txt).
13
14 It started off with wanting to address some pet peeves with ego item generation
15 (the hackish OBJECT_XTRA_TYPE\_ defines, the rigid nature of the better ego
16 types, etc.). It was also inspired by Eytan Zweig's item prefixes (#587), and
17 grew from there. The basic idea is to allow for a greater variety of magical
18 items and smoother progression from a dagger (1d4) (+0,+0) to a 6d5 Holy
19 Avenger (and so on for other equipment).
20
21 What hasn't changed
22 ===================
23
24 All the old objects and ego items are still generatable almost exactly as they
25 used to look. Slay weapons, branded weapons, Defender/HA/Gondolin/Westernesse
26 weapons, Elvenkind armours and boots, Robes of Permanence, etc. At the moment
27 (subject to any rebalancing we may wish to do) they are still generated with
28 the same flags and on the same object types as they used to. (So only Maces
29 can get the Of Disruption suffix, only Scythes can get Of Slicing, only robes
30 can get Of Permanence etc.)
31
32 What has changed
33 ================
34
35 I say "almost" because there are two noticeable differences. Some of the
36 high-end items will have all four IGNORE\_ flags where they only used to have
37 one or two (e.g. Gondolin). More significantly, most items will have lower
38 to-hit/to-dam values than under the old system - though this can now be
39 balanced purely through editing ego_item.txt and ego_themes.txt
40
41 The ego_item type
42 -----------------
43
44 Ah yes, themes. Let's get down to the code. The ego_item type still exists, and
45 they're still stored in the global e_info[] array, but they're not called egos
46 any more, they're called affixes (because you can have MAX_AFFIXES of them).
47 There are some (IMO) useful changes to the type:
48
49 * The C: line now takes seven parameters rather than three. As well as
50 to_h/to_d/to_a, you can now modify base AC, weight, dice and sides. The
51 first two of these are percentage mods (and are signed so can be negative),
52 the last two are just extra dice and sides (but can also be negative). Full
53 credit to Eytan Zweig for inspiring these.
54 * The M: line is assumed to be NO_MINIMUM:NO_MINIMUM:NO_MINIMUM if it's absent.
55 So no worries about accidentally removing armour penalties.
56 * The X: line is gone. Rarity is no longer used, and random flags are now
57 done by R: or R2: lines. R: lines specify OFT\_ flag types (sustains, high
58 resists, etc. - now in src/object/list-flag-types.h), while R2: lines
59 allow specification of an exact flag mask. So if you want, you can have an
60 affix that adds one of SUST_STR or SUST_CON but nothing else. You cannot
61 add pval flags this way though - I wrote a spec for a Z: line to do this,
62 but it is difficult to box around MAX_PVALS so I have left this for another
63 day.
64 * The T: line now deals with rarity as well as kind legality. For each
65 tval/min-sval/max-sval group, you can specify an alloc_prob and a min and
66 max depth. EGO_TVALS_MAX has been increased accordingly (and could go
67 further). So you can have the same affix appear with different likelihood
68 and at different depths for different items. Acid-resistant shields can be
69 much rarer (or less rare) than acid-resistant cloaks, for example.
70 * The T: line also includes a "level" field, which specifies how good the
71 affix is considered for this object group at these depths. So far I've
72 defined four levels: "good", "great", "uber" and "artifact", but we could
73 have more. The last is in case we want to have affixes only found on
74 randarts (e.g. immunities). More on levels in a minute, but one point to
75 note is that you can redefine the same object group here. So:
76 | T:soft armour:0:99:great:10:1 to 25
77 | T:soft armour:0:99:good:25:26 to 100
78 would mean that this affix is considered "great" at low levels but merely
79 "good" at deeper depths - for soft armour.
80
81 Ok, so those are affixes. I stripped out all the compound egos, with multiple
82 attributes, and boiled affixes right down, so that each only provides one or
83 two things. Resist affixes still give the IGNORE\_ flag, and the five x3 brands
84 still give both RESIST\_ and IGNORE\_ flags, but otherwise most affixes only
85 provide one flag. I've added the EyAngband prefixes, which modify the base
86 properties of armour and weapons (AC, hit/dam, dice/sides) - I left out only
87 the inappropriate race-specific ones (Ey has lots of weird races), and
88 guesstimated on some. (N.B. I was concentrating on implementation, not on
89 balance, so there is a ton of room for tweaking the values of any of the
90 Ey affixes, and any others.) I also stripped out base objects which are
91 obviously other base objects with affixes: Lead-Filled Mace, Mithril
92 Chain/Plate, Adamantite Plate, Mace of Disruption, Scythe of Slicing.
93 These are all now affixes (but see below for more to do on this).
94
95 N.B. There is no base item called "Blade", so the "of Chaos" affix can be
96 applied to the top three swords (Katana, Zweihander and Executioner IIRC).
97 Though there's no reason not to allow Daggers of Chaos, if we want to.
98
99 *make_object* and *make_artifact*
100 ---------------------------------
101
102 Having improved the type and reduced the egos down to simple affixes, I set
103 about changing object generation. First I rewrote kind_is_good to look for
104 OF_GOOD, so that powerful items like DSMs are automatically considered
105 "good" and never "average". This doesn't actually have much impact on the
106 obj_alloc_great table though, since all armour and weapon types were
107 already in it (but see below for more thoughts on this).
108
109 Then I sorted out artifact generation, combining special and normal
110 artifacts. This distinction only ever existed because all normal
111 artifacts were only ever generated after the object kind was chosen,
112 and specials were attempted before. Now *make_object* tries for an
113 artifact first, and *make_artifact* now creates an allocation table of
114 all possible artifacts (i.e. not yet created, in-depth, out-of-depth
115 checks etc.) before choosing one. If the kind is already chosen (e.g.
116 from specified monster drops) then the allocation table looks a lot
117 smaller because it only contains artifacts legal for that kind.
118
119 Please note: artifact generation will need quite a bit of balancing,
120 because not only did I unify the generation functions (which will
121 fundamentally change how many are generated), but I also recalibrated
122 the alloc_prob scale to 1000 rather than 100, and reflected the fact
123 that these are now checked independently of base items. So Bladeturner's
124 old rarity accounted for the fact that its base item was very rare: now
125 it has to be even rarer. I implemented multiple A: lines for artifacts,
126 so we now have finer control over their findability (because they can
127 have different rarities at different depths).
128
129 Choosing and applying affixes
130 -----------------------------
131 So, if we're not an artifact we now set the number and quality of an
132 object's affixes in *apply_magic*. Note that the call to *apply_magic*
133 from *make_object* deliberately sets allow_artifacts to FALSE, because
134 we've already tried for an artifact there. But if it's called directly
135 (for a specified item), then we still get a shot at becoming an artifact.
136
137 One important change is that **all** items can now get "good" affixes.
138 This is because *apply_magic_weapon/armour()* have been removed, and
139 plusses now come from first-grade affixes (Quality, Sharp, Brutal etc.),
140 but you can now get minor abilities like Feather Falling on what would
141 previously have been just "good" items. Forced-great items automatically
142 get access to great affixes, and good items do so 25% of the time. There's
143 also a depth-dependent chance for increment, so uber affixes are (i) only
144 available on good or great drops and (ii) much less likely early on.
145
146 The number of affixes is a function of depth (0 to (1 + lev / 25)), plus
147 one or two if good, or three or four if great (minus one if we have
148 OF_GOOD). These numbers can be rebalanced, of course. There might not
149 actually be many "great" drops, so we might want to be more generous to
150 normal or good items, and tone down the great items to only a couple of
151 extra affixes. But note that "normal" drops get much more interesting
152 with depth, so this may not be necessary.
153
154 I haven't done a lot of renaming yet, but I've renamed *make_ego_item*
155 to *obj_add_affix* because it wasn't called from anywhere else except
156 *apply_magic*. It checks that we're not trying to add an affix to an
157 artifact, a themed item, or an item with MAX_AFFIXES already. It also
158 does that weird GREAT_EGO level boost, for a one-in-20 chance of a
159 potentially huge level boost (though that doesn't boost the affix level
160 yet - if it did, this would create interesting possibilities for randarts,
161 noted below). Importantly, we copy the object, so we don't have to worry
162 about affixes creating broken items - if that happens we just roll back
163 and don't add anything.
164
165 We choose which affix to apply in *obj_find_affix*, which is
166 *ego_find_random* renamed and rewritten to allow for the new T: lines
167 above. Like *make_artifact*, it builds an allocation table from the
168 affixes which are legal for this item at this depth and affix level.
169
170 We actually apply the affix in *ego_apply_magic* (which I didn't rename
171 yet 'cos it's called from a few places) - it deals with the extra stuff
172 outlined above (base ac / weight / dice / sides, and random flags) but
173 is otherwise recognisable. We now check minima both before and after
174 application, to ensure that a min_pval of 2 gives correct results when
175 applied to an existing pval of, say, -1. We also check flags at the end,
176 to remove contradictory elemental flags (RES_FOO and VULN_FOO etc.),
177 and to strip lots of mods off ammo (so that we don't have to replicate
178 affixes and themes for ammo). Oh, I fixed #1531 as well.
179
180 If we didn't break anything, we look to see if the object can now get a
181 theme.
182
183 Themes
184 ------
185
186 Without themes, we can have very powerful items, but they're like
187 randarts - random collections of attributes. Themes allow us to decide,
188 during an item's creation, that it's going down a particular path. So I
189 wrote ego_themes.txt, which sets out what these themes are. At the moment
190 they're all recognisable, because they're the high-end/compound egos I
191 removed from ego_item.txt earlier on.
192
193 Themes[] are a global array like e_info[], which have N: and D: lines
194 exactly like ego_item.txt. They also have T: lines, but these only have
195 tval, svals and depths - no "level" or "commonness". So far so obvious.
196 *obj_find_theme* builds an allocation table of legal themes just like
197 *make_artifact* and *obj_find_affix*, checking depth and tval/sval.
198
199 But there the similarity ends - themes don't have an inherent commonness,
200 they have a number of component affixes, each of which has a weighting.
201 We check the object to see if it has any of these affixes already, and
202 record their weight. Then we multiply by the proportion of total weight
203 to get the actual likelihood of acquiring that theme. These weightings
204 were chosen very carefully, because often only one theme will be
205 available to an object, and we have to have an absolute percent chance
206 of getting it, as well as an allocation table if there are several to
207 choose from. The total weight of the relevant affixes on the item is
208 multiplied by (itself x 4 / total weight of all affixes in the theme)
209 to get the percent chance (in the code we use x8 and use randint0(200)
210 so we're using half-percent granularity).
211
212 So here's a worked example: the theme "of Resistance". It has six
213 constituent affixes: the four resists (each weighted 7), Reinforced
214 (for the to_a boost, weighted 2) and Durable (for the IGNORE flags,
215 weighted 4). Durable items contribute to a lot of themes, but usually
216 with very small probability - this is actually the largest weighting
217 of Durable, because it reflects the nature of the theme. So the total
218 weighting of all affixes in this theme is 34.
219
220 If we have only one of them, we can't get the theme. You need at least
221 two affixes to get any theme.
222
223 If we have two of the resists, we have a total weight of 14. The percent
224 chance of acquiring the theme is (14*14*4)/(34*100) = 23%.
225
226 If we have three of the resists, we have weight of 21. The percent chance
227 of acquiring the theme is (21*21*4)/(34*100) = 51.5%.
228
229 If we have all four resists, we have a (28*28*4)/(34*100) = 92% chance
230 of acquiring the theme. (If we tweaked the weightings of Durable and
231 Reinforced down to 2 and 1 respectively, this would be over 100%, which
232 is probably what we want.)
233
234 By contrast, if the two affixes we have are Reinforced and Durable, we
235 have weight of 6, which gives a (6*6*4)/(34*100) = 4% chance of acquiring
236 the theme. Both of them and one resist makes 19% - less useful than having
237 two of the resists.
238
239 Another example worth mentioning is lanterns of True Sight - a theme which
240 has only two affixes. Both have weights of 100, so if we get them, we will
241 automatically get this theme.
242
243 Blessed weapons have three affixes, but one of them has a weighting of zero
244 (of Dweomercraft, the one which provides the random ability - also on
245 Gondolin and \*Slay\* Evil weapons, Lothlorien bows etc.). This means it
246 doesn't contribute to the weighting, but it is applied in *obj_apply_theme*
247 after the theme is chosen. This function simply cycles through all the
248 affixes in the theme and applies all the ones that aren't already on the
249 item. Since you can specify the same affix more than once in a theme
250 (e.g. for extra combat bonuses, or extra random flags), we allow the
251 second and subsequent ones to be applied.
252
253 Note that *obj_apply_theme* doesn't actually set the o_ptr->affix for
254 the affixes it applies. This is deliberate: many themes have more than
255 MAX_AFFIXES. Also, once we acquire a theme we're unable to modify the
256 item further (like an artifact), so it doesn't really matter too much.
257 Note also that branding spells **will** (currently) work on non-themed
258 items, providing they have < MAX_AFFIXES. I like this, but others might
259 not (more below).
260
261 ID, naming and saving
262 ---------------------
263
264 ID-by-use works reasonably well for affixes, though I had to write
265 *object_affix_is_known* to check from first principles whether we know
266 all about an affix. The IDENT\_ flags don't work because we don't know
267 how many affixes we're trying to know, and I decided against recording
268 o_ptr->known_affixes in favour of working it out on the fly.
269 *object_theme_is_known* is just a wrapper which makes sure that we know
270 all the affixes in a theme. This is pretty basic but actually seems to
271 work ok - both magical ID and ID-by-use seem to work ok, and the ego
272 knowledge menu shows affixes once they're known (it doesn't talk about
273 the new mods to weight/base AC/dice/sides, but otherwise works ok).
274
275 Finally, with noz's help, we sorted out the prefix and suffix names of
276 the object, which are the theme or the best affixes in the absence of a
277 theme (so you can get Emerald weapons of Gondolin, or Broken ones, etc.).
278 There is still some thinking to do here in relation to ID and naming,
279 some of which was discussed on IRC (d_m/fizzix suggested "synthetic"
280 affixes which change the name but no properties - this seems like a
281 good solution, but it would be a shame to lose all the flavour of the
282 affix names).
283
284 The savefile now stores the indices of the theme (in the old
285 o_ptr->ego->eidx slot) and the affixes. I also took a cue from Gabe and
286 we now record all of MAX_PVALS, MAX_AFFIXES, OF_SIZE and OF_BYTES in the
287 savefile, so if they change we don't have to write a new function. Oh, and
288 we also store o_ptr->extent, which is food/fuel/charges/gold/chest level,
289 fixing #1540. Ego items in old savefiles will retain all their actual
290 properties (flags, plusses etc.), but will lose their names. I'm happy
291 to write a converter to restore these names if people think it's
292 important, but it looks like we might be heading for major savefile
293 breakage for 4.0 anyway.
294
295 Next steps
296 ==========
297
298 Code cleanup
299 ------------
300 I need to get rid of remaining references to o_ptr->ego and remove it
301 from the object_type struct. Also renaming ego_stuff to affix_stuff
302 would be helpful - I've been a bit lazy about this, in case the whole
303 thing was rejected. I also need to write accessors or #defines for
304 things like AFFIX_IS_PREFIX and so on.
305
306 I'm also wondering whether it's possible/desirable to de-globalise the
307 themes[] and e_info[] arrays, and make them local to obj-make (or
308 wherever). I don't know enough about C to know how important or difficult
309 this would be. Similarly, there are lots of comments in the code about
310 making arrays read-only (e.g. #1202) - again, I'm not sure I really
311 understand this issue properly.
312
313 Knowledge and ID
314 ----------------
315
316 Update: the ego knowledge menu now works properly, as does the object
317 knowledge menu. An item's affixes are now listed in the 'I'nspect screen
318 (this may or may not be desirable long-term, but is certainly useful for
319 testing). Flavour text is also shown for all affixes where it exists.
320
321 Rune-based ID is now working, with a separate knowledge menu for known
322 runes. Unknown runes will soon have random names (#1574), and both
323 known and unknown runes will be listed on the Inspect screen.
324
325 IMO we should no longer show the base AC or dice of an object, because
326 these are no longer so static - lots of the Ey prefixes change one or
327 the other. This fits nicely with reducing the amount of info available
328 and forcing people to walk over and fetch stuff. Interested in people's
329 thoughts on this (and see also #1551).
330
331 Naming and base items
332 ---------------------
333
334 We need to agree a strategy for naming items with multiple affixes.
335 Personally I favour adopting the position that an object's displayed
336 name does not give you complete information about all its properties,
337 but others may disagree. Also, affixes can be applied more than once
338 (meaningless for flag affixes, but important for hit/dam/ac etc.). I
339 like the idea of Sharp, *Sharp* and **Sharp** or something, to denote
340 multiple applications of an affix. UPDATE: this is now the single most
341 important outstanding issue. There is consensus that it is unrealistic
342 to convey all information in the item's name, but no consensus on a
343 naming hierarchy or categorisation.
344
345 Randarts and randomness
346 -----------------------
347
348 My original intention was that themes were more random, i.e. that not
349 all affixes in a theme would be applied every time. I didn't implement
350 themes like this because I didn't want the outcry of "my Gondolin weapon
351 doesn't have RES_DARK" etc. But I still think it would be good to have
352 more variation. If we want to use themes to guide randart generation,
353 this would become more important. One way is to add a third field to
354 the A: lines in ego_themes.txt and specify the percent chance of adding
355 that affix during obj_apply_theme. We could keep the wolves at bay by
356 ensuring that these were all 100 for the traditional ego types.
357
358 The consideration of randarts divides into three separate issues:
359
360 * how many of the standart set to use (sub-divides into all, none or
361 some (which further subdivides into a set proportion or a chosen
362 proportion))
363 * how many randarts to generate (sub-divides into none, the same number
364 as the number of unused standarts, or infinite)
365 * how much to randomise any standarts (straight choice between completely
366 random, i.e. new base item / name / properties, or partially random,
367 i.e. same base item and name, with some core attributes kept and
368 others randomised)
369
370 The GREAT_EGO check could be used for generating infinite randarts
371 (since it could lift the affix level from "uber" to "artifact").
372
373 Object modification
374 -------------------
375
376 This branch opens up a lot of possibilities w.r.t. alchemy, forging etc.
377 (See also #1550). Nothing to worry about immediately, except whether to
378 retain or remove the branding spells/prayers. Arguably the prayer (for
379 branding melee weapons) is now actually useful where it wasn't before.
380 It now checks that the object doesn't already have a brand. The ammo
381 branding spell was already too good, and is probably even more so now
382 (but we could always temper it by making it reduce o_ptr->number by 50%,
383 or something like that).
384
385 My view remains that we should allow spells and effects to modify objects,
386 and just be careful to limit their power. (We could use a limit lower
387 than MAX_AFFIXES, for instance.)
388
389 Balancing
390 ---------
391
392 Finally, of course, there's a ton of balancing tweaking to be done.
393 Some affixes are available on items which weren't before (e.g. of
394 Warding), and others aren't (e.g. of Dweomercraft), purely because
395 of what I was testing when I added them. Doing this balancing means
396 adjusting the stats code to record affix and theme indices (it
397 already records all the actual item info). I am quite happy for
398 people to crawl all over ego_items.txt and ego_themes.txt and adjust
399 all the T: lines, as I have not spent long checking what affixes
400 are available on which items at which depth and affix level:
401 mithril shields don't seem to be able to acquire any affixes at all!
402
403 A spreadsheet of the current affix distribution is at
404 https://docs.google.com/spreadsheet/ccc?key=0AlI-IK5uLWbEdEItWWRZY0RqSVhoeHpBWjU3OG02UHc&hl=en_US
405 . To see what is available on any particular type of item, scroll up
406 and down (and order by depth if you like). This immediately tells us
407 that we need more affixes on cloaks, gloves, boots and launchers. We
408 probably need more armour affixes in general: there are 12 AC/weight
409 affixes for armour (two bad), compared with 28 hit/dam/dice affixes
410 for weapons (which need much more careful distribution). We can
411 probably also converge some of the affixes: there is now no need for
412 special affixes for launchers or ammo (Accuracy, Power, Wounding).
413
414 There's a "proposed" spreadsheet at
415 https://docs.google.com/spreadsheet/ccc?key=0AlI-IK5uLWbEdFV2UzJKSjdKZmEtLWlkTXF2amd6b3c&hl=en_US
416 , which contains my first partial attempt at balancing the distribution.
417
418 I also think that we need to check the balance between obj_alloc
419 (the allocation table for all objects) and obj_alloc_great (the one
420 for "good" or "great" objects). Some potions/scrolls with the
421 OF_GOOD flag may now be too common, and some others perhaps ought to
422 get it (and some devices).
423
424 Finally, I haven't done much with the old "cursed" egos - they've
425 been re-enabled as affixes, but not split up into themes. Once we've
426 settled on our "new curses" system I'll come back and sort out affixes
427 for proper mixed-blessing items. In the meantime I will disable them
428 prior to any release.
429
430 Other issues
431 ------------
432
433 A bunch of things occurred to me while doing all this stuff (I'll make
434 tickets post-merge)
435
436 * the slay cache can now go, as we're not constrained to a small number
437 of slay combinations which are worth caching
438 * we could have a low-level code module for generating lookup tables
439 like flag names (currently duplicated in obj-flag.c and init2.c)
440 and tvals (which we could now do from object_base.txt, removing the
441 need for hard-coding - we could also seek to remove tvalsval.h ...)
442 * affixes could change the display colour of an object (Ey has this,
443 and fizzix thought of it too - #837)
444 * affixes could be used to generate ego jewelry, which allows
445 re-thinking of what non-ego jewelry ought to be ... (it would be
446 easy to regenerate the existing rings/amulets using affixes and
447 themes, while enjoying the extra randomness)
448 * allocation of kinds could use the alloc_entry struct (presumably it
449 was written before that struct?)
450 * items with alloc_prob 0 should not appear in knowledge menus (the old
451 Bronze DSM problem, now occurring with stuff like Adamantite Plate and
452 Maces of Disruption) - not sure if this is related to fizzix's bug
453 report
454 * should maxima really be sparse? z_info->e_max is set not as the number
455 of e_info entries but the index of the highest. Is this necessary?
456
457 Backporting to V 3.x
458 ====================
459
460 There is a problem with using this code to generate only the items found
461 in 3.3.x's ego_item.txt. In order to get a theme, an item must already
462 have at least two of that theme's affixes. If we take the example of
463 \*slay\* dragon, none of its three affixes (+CON, RES_FEAR or KILL_DRAGON)
464 are ever found separately on weapons in 3.3.x. So you could never create
465 an item with this theme using this system.
466
467 If you got rid of themes altogether and simply turned them back into rare
468 affixes, you would need to make sure that an item could only have one
469 affix (so that it could not get both Gondolin and Defender, for example) -
470 thereby losing the point of affixes altogether. At that point you just
471 have a minor variation on the old ego system, with some parser changes.