1 /** 2 * \file object.h 3 * \brief basic object structs and enums 4 */ 5 #ifndef INCLUDED_OBJECT_H 6 #define INCLUDED_OBJECT_H 7 8 #include "z-type.h" 9 #include "z-quark.h" 10 #include "z-bitflag.h" 11 #include "z-dice.h" 12 #include "obj-properties.h" 13 14 15 /*** Game constants ***/ 16 17 /** 18 * Elements 19 */ 20 enum 21 { 22 #define ELEM(a) ELEM_##a, 23 #include "list-elements.h" 24 #undef ELEM 25 26 ELEM_MAX 27 }; 28 29 #define ELEM_BASE_MIN ELEM_ACID 30 #define ELEM_BASE_MAX (ELEM_COLD + 1) 31 #define ELEM_HIGH_MIN ELEM_POIS 32 #define ELEM_HIGH_MAX (ELEM_DISEN + 1) 33 34 /** 35 * Object origin kinds 36 */ 37 38 enum { 39 #define ORIGIN(a, b, c) ORIGIN_##a, 40 #include "list-origins.h" 41 #undef ORIGIN 42 43 ORIGIN_MAX 44 }; 45 46 47 /*** Structures ***/ 48 49 /** 50 * Effect 51 */ 52 struct effect { 53 struct effect *next; 54 u16b index; /**< The effect index */ 55 dice_t *dice; /**< Dice expression used in the effect */ 56 int y; /**< Y coordinate or distance */ 57 int x; /**< X coordinate or distance */ 58 int subtype; /**< Projection type, timed effect type, etc. */ 59 int radius; /**< Radius of the effect (if it has one) */ 60 int other; /**< Extra parameter to be passed to the handler */ 61 char *msg; /**< Message for deth or whatever */ 62 }; 63 64 /** 65 * Chests 66 */ 67 struct chest_trap { 68 struct chest_trap *next; 69 char *name; 70 char *code; 71 int level; 72 struct effect *effect; 73 int pval; 74 bool destroy; 75 bool magic; 76 char *msg; 77 char *msg_death; 78 }; 79 80 /** 81 * Brand type 82 */ 83 struct brand { 84 char *code; 85 char *name; 86 char *verb; 87 int resist_flag; 88 int vuln_flag; 89 int multiplier; 90 int o_multiplier; 91 int power; 92 struct brand *next; 93 }; 94 95 /** 96 * Slay type 97 */ 98 struct slay { 99 char *code; 100 char *name; 101 char *base; 102 char *melee_verb; 103 char *range_verb; 104 int race_flag; 105 int multiplier; 106 int o_multiplier; 107 int power; 108 struct slay *next; 109 }; 110 111 /** 112 * Curse type 113 */ 114 struct curse { 115 struct curse *next; 116 char *name; 117 bool *poss; 118 struct object *obj; 119 char *conflict; 120 bitflag conflict_flags[OF_SIZE]; 121 char *desc; 122 }; 123 124 enum { 125 EL_INFO_HATES = 0x01, 126 EL_INFO_IGNORE = 0x02, 127 EL_INFO_RANDOM = 0x04, 128 }; 129 130 /** 131 * Element info type 132 */ 133 struct element_info { 134 s16b res_level; 135 bitflag flags; 136 }; 137 138 /** 139 * Activation structure 140 */ 141 struct activation { 142 struct activation *next; 143 char *name; 144 int index; 145 bool aim; 146 int power; 147 struct effect *effect; 148 char *message; 149 char *desc; 150 }; 151 152 extern struct activation *activations; 153 154 /** 155 * Information about object types, like rods, wands, etc. 156 */ 157 struct object_base { 158 char *name; 159 160 int tval; 161 struct object_base *next; 162 163 int attr; 164 165 bitflag flags[OF_SIZE]; 166 bitflag kind_flags[KF_SIZE]; /**< Kind flags */ 167 struct element_info el_info[ELEM_MAX]; 168 169 int break_perc; 170 int max_stack; 171 int num_svals; 172 }; 173 174 extern struct object_base *kb_info; 175 176 /** 177 * Information about object kinds, including player knowledge. 178 * 179 * TODO: split out the user-changeable bits into a separate struct so this 180 * one can be read-only. 181 */ 182 struct object_kind { 183 char *name; 184 char *text; 185 186 struct object_base *base; 187 188 struct object_kind *next; 189 u32b kidx; 190 191 int tval; /**< General object type (see TV_ macros) */ 192 int sval; /**< Object sub-type */ 193 194 random_value pval; /* Item extra-parameter */ 195 196 random_value to_h; /**< Bonus to hit */ 197 random_value to_d; /**< Bonus to damage */ 198 random_value to_a; /**< Bonus to armor */ 199 int ac; /**< Base armor */ 200 201 int dd; /**< Damage dice */ 202 int ds; /**< Damage sides */ 203 int weight; /**< Weight, in 1/10lbs */ 204 205 int cost; /**< Object base cost */ 206 207 bitflag flags[OF_SIZE]; /**< Flags */ 208 bitflag kind_flags[KF_SIZE]; /**< Kind flags */ 209 210 random_value modifiers[OBJ_MOD_MAX]; 211 struct element_info el_info[ELEM_MAX]; 212 213 bool *brands; 214 bool *slays; 215 int *curses; /**< Array of curse powers */ 216 217 byte d_attr; /**< Default object attribute */ 218 wchar_t d_char; /**< Default object character */ 219 220 int alloc_prob; /**< Allocation: commonness */ 221 int alloc_min; /**< Highest normal dungeon level */ 222 int alloc_max; /**< Lowest normal dungeon level */ 223 int level; /**< Level (difficulty of activation) */ 224 225 struct activation *activation; /**< Artifact-like activation */ 226 struct effect *effect; /**< Effect this item produces (effects.c) */ 227 int power; /**< Power of the item's effect */ 228 char *effect_msg; 229 char *vis_msg; 230 random_value time; /**< Recharge time (rods/activation) */ 231 random_value charge; /**< Number of charges (staves/wands) */ 232 233 int gen_mult_prob; /**< Probability of generating more than one */ 234 random_value stack_size;/**< Number to generate */ 235 236 struct flavor *flavor; /**< Special object flavor (or zero) */ 237 238 /** Also saved in savefile **/ 239 240 quark_t note_aware; /**< Autoinscription quark number */ 241 quark_t note_unaware; /**< Autoinscription quark number */ 242 243 bool aware; /**< Set if player is aware of the kind's effects */ 244 bool tried; /**< Set if kind has been tried */ 245 246 byte ignore; /**< Ignore settings */ 247 bool everseen; /**< Kind has been seen (to despoilify ignore menus) */ 248 }; 249 250 extern struct object_kind *k_info; 251 extern struct object_kind *unknown_item_kind; 252 extern struct object_kind *unknown_gold_kind; 253 extern struct object_kind *pile_kind; 254 extern struct object_kind *curse_object_kind; 255 256 /** 257 * Information about artifacts. 258 * 259 * Note that ::cur_num is written to the savefile. 260 * 261 * TODO: Fix this max_num/cur_num crap and just have a big boolean array of 262 * which artifacts have been created and haven't, so this can become read-only. 263 */ 264 struct artifact { 265 char *name; 266 char *text; 267 268 u32b aidx; 269 270 struct artifact *next; 271 272 int tval; /**< General artifact type (see TV_ macros) */ 273 int sval; /**< Artifact sub-type */ 274 275 int to_h; /**< Bonus to hit */ 276 int to_d; /**< Bonus to damage */ 277 int to_a; /**< Bonus to armor */ 278 int ac; /**< Base armor */ 279 280 int dd; /**< Base damage dice */ 281 int ds; /**< Base damage sides */ 282 283 int weight; /**< Weight in 1/10lbs */ 284 285 int cost; /**< Artifact (pseudo-)worth */ 286 287 bitflag flags[OF_SIZE]; /**< Flags */ 288 289 int modifiers[OBJ_MOD_MAX]; 290 struct element_info el_info[ELEM_MAX]; 291 292 bool *brands; 293 bool *slays; 294 int *curses; /**< Array of curse powers */ 295 296 int level; /** Difficulty level for activation */ 297 298 int alloc_prob; /** Chance of being generated (i.e. rarity) */ 299 int alloc_min; /** Minimum depth (can appear earlier) */ 300 int alloc_max; /** Maximum depth (will NEVER appear deeper) */ 301 302 bool created; /**< Whether this artifact has been created */ 303 bool seen; /**< Whether this artifact has been seen this game */ 304 bool everseen; /**< Whether this artifact has ever been seen */ 305 306 struct activation *activation; /**< Artifact activation */ 307 char *alt_msg; 308 309 random_value time; /**< Recharge time (if appropriate) */ 310 }; 311 312 /** 313 * The artifact arrays 314 */ 315 extern struct artifact *a_info; 316 317 318 /** 319 * Structure for possible object kinds for an ego item 320 */ 321 struct poss_item { 322 u32b kidx; 323 struct poss_item *next; 324 }; 325 326 /** 327 * Information about ego-items. 328 */ 329 struct ego_item { 330 struct ego_item *next; 331 332 char *name; 333 char *text; 334 335 u32b eidx; 336 337 int cost; /* Ego-item "cost" */ 338 339 bitflag flags[OF_SIZE]; /**< Flags */ 340 bitflag flags_off[OF_SIZE]; /**< Flags to remove */ 341 bitflag kind_flags[KF_SIZE]; /**< Kind flags */ 342 343 random_value modifiers[OBJ_MOD_MAX]; 344 int min_modifiers[OBJ_MOD_MAX]; 345 struct element_info el_info[ELEM_MAX]; 346 347 bool *brands; 348 bool *slays; 349 int *curses; /**< Array of curse powers */ 350 351 int rating; /* Level rating boost */ 352 int alloc_prob; /** Chance of being generated (i.e. rarity) */ 353 int alloc_min; /** Minimum depth (can appear earlier) */ 354 int alloc_max; /** Maximum depth (will NEVER appear deeper) */ 355 356 struct poss_item *poss_items; 357 358 random_value to_h; /* Extra to-hit bonus */ 359 random_value to_d; /* Extra to-dam bonus */ 360 random_value to_a; /* Extra to-ac bonus */ 361 362 int min_to_h; /* Minimum to-hit value */ 363 int min_to_d; /* Minimum to-dam value */ 364 int min_to_a; /* Minimum to-ac value */ 365 366 struct effect *effect; /**< Effect this item produces (effects.c) */ 367 char *effect_msg; 368 random_value time; /**< Recharge time (rods/activation) */ 369 370 bool everseen; /* Do not spoil ignore menus */ 371 }; 372 373 /* 374 * The ego-item arrays 375 */ 376 extern struct ego_item *e_info; 377 378 /** 379 * Flags for the obj->notice field 380 */ 381 enum { 382 OBJ_NOTICE_WORN = 0x01, 383 OBJ_NOTICE_ASSESSED = 0x02, 384 OBJ_NOTICE_IGNORE = 0x04, 385 OBJ_NOTICE_IMAGINED = 0x08, 386 }; 387 388 struct curse_data { 389 int power; 390 int timeout; 391 }; 392 393 /** 394 * Object information, for a specific object. 395 * 396 * Note that inscriptions are now handled via the "quark_str()" function 397 * applied to the "note" field, which will return NULL if "note" is zero. 398 * 399 * Each cave grid points to one (or zero) objects via the "obj" field in 400 * its "squares" struct. Each object then points to one (or zero) objects 401 * via the "next" field, and (aside from the first) back via its "prev" 402 * field, forming a doubly linked list, which in game terms represents a 403 * stack of objects in the same grid. 404 * 405 * Each monster points to one (or zero) objects via the "held_obj" 406 * field (see monster.h). Each object then points to one (or zero) objects 407 * and back to previous objects by its own "next" and "prev" fields, 408 * forming a doubly linked list, which in game terms represents the 409 * monster's inventory. 410 * 411 * The "held_m_idx" field is used to indicate which monster, if any, 412 * is holding the object. Objects being held have (0, 0) as a grid. 413 * 414 * Note that object records are not now copied, but allocated on object 415 * creation and freed on object destruction. These records are handed 416 * around between player and monster inventories and the floor on a fairly 417 * regular basis, and care must be taken when handling such objects. 418 */ 419 struct object { 420 struct object_kind *kind; /**< Kind of the object */ 421 struct ego_item *ego; /**< Ego item info of the object, if any */ 422 struct artifact *artifact; /**< Artifact info of the object, if any */ 423 424 struct object *prev; /**< Previous object in a pile */ 425 struct object *next; /**< Next object in a pile */ 426 struct object *known; /**< Known version of this object */ 427 428 u16b oidx; /**< Item list index, if any */ 429 430 struct loc grid; /**< position on map, or (0, 0) */ 431 432 byte tval; /**< Item type (from kind) */ 433 byte sval; /**< Item sub-type (from kind) */ 434 435 s16b pval; /**< Item extra-parameter */ 436 437 s16b weight; /**< Item weight */ 438 439 byte dd; /**< Number of damage dice */ 440 byte ds; /**< Number of sides on each damage die */ 441 s16b ac; /**< Normal AC */ 442 s16b to_a; /**< Plusses to AC */ 443 s16b to_h; /**< Plusses to hit */ 444 s16b to_d; /**< Plusses to damage */ 445 446 bitflag flags[OF_SIZE]; /**< Object flags */ 447 s16b modifiers[OBJ_MOD_MAX]; /**< Object modifiers*/ 448 struct element_info el_info[ELEM_MAX]; /**< Object element info */ 449 bool *brands; /**< Array of brand structures */ 450 bool *slays; /**< Array of slay structures */ 451 struct curse_data *curses; /**< Array of curse powers and timeouts */ 452 453 struct effect *effect; /**< Effect this item produces (effects.c) */ 454 char *effect_msg; /**< Message on use */ 455 struct activation *activation; /**< Artifact activation, if applicable */ 456 random_value time; /**< Recharge time (rods/activation) */ 457 s16b timeout; /**< Timeout Counter */ 458 459 byte number; /**< Number of items */ 460 bitflag notice; /**< Attention paid to the object */ 461 462 s16b held_m_idx; /**< Monster holding us (if any) */ 463 s16b mimicking_m_idx; /**< Monster mimicking us (if any) */ 464 465 byte origin; /**< How this item was found */ 466 byte origin_depth; /**< What depth the item was found at */ 467 struct monster_race *origin_race; /**< Monster race that dropped it */ 468 469 quark_t note; /**< Inscription index */ 470 }; 471 472 /** 473 * Null object constant, for safe initialization. 474 */ 475 static struct object const OBJECT_NULL = { 476 .kind = NULL, 477 .ego = NULL, 478 .artifact = NULL, 479 .prev = NULL, 480 .next = NULL, 481 .known = NULL, 482 .oidx = 0, 483 .grid = { 0, 0 }, 484 .tval = 0, 485 .sval = 0, 486 .pval = 0, 487 .weight = 0, 488 .dd = 0, 489 .ds = 0, 490 .ac = 0, 491 .to_a = 0, 492 .to_h = 0, 493 .to_d = 0, 494 .flags = { 0 }, 495 .modifiers = { 0 }, 496 .el_info = { { 0, 0 } }, 497 .brands = NULL, 498 .slays = NULL, 499 .curses = NULL, 500 .effect = NULL, 501 .effect_msg = NULL, 502 .activation = NULL, 503 .time = { 0, 0, 0, 0 }, 504 .timeout = 0, 505 .number = 0, 506 .notice = 0, 507 .held_m_idx = 0, 508 .mimicking_m_idx = 0, 509 .origin = 0, 510 .origin_depth = 0, 511 .origin_race = NULL, 512 .note = 0, 513 }; 514 515 struct flavor 516 { 517 char *text; 518 struct flavor *next; 519 unsigned int fidx; 520 521 byte tval; /* Associated object type */ 522 byte sval; /* Associated object sub-type */ 523 524 byte d_attr; /* Default flavor attribute */ 525 wchar_t d_char; /* Default flavor character */ 526 }; 527 528 extern struct flavor *flavors; 529 530 531 typedef bool (*item_tester)(const struct object *); 532 533 534 #endif /* !INCLUDED_OBJECT_H */ 535