1 /* NetHack 3.7	mextra.h	$NHDT-Date: 1596498545 2020/08/03 23:49:05 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.30 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Michael Allison, 2006. */
4 /* NetHack may be freely redistributed.  See license for details. */
5 
6 #ifndef MEXTRA_H
7 #define MEXTRA_H
8 
9 #ifndef ALIGN_H
10 #include "align.h"
11 #endif
12 
13 /*
14  *  Adding new mextra structures:
15  *
16  *       1. Add the structure definition and any required macros in this
17  *          file above the mextra struct.
18  *       2. Add a pointer to your new struct to the mextra struct in this
19  *          file.
20  *       3. Add a referencing macro at bottom of this file after the mextra
21  *          struct (see MGIVENNAME, EGD, EPRI, ESHK, EMIN, or EDOG for
22  *          examples).
23  *       4. If your new field isn't a pointer and requires a non-zero value
24  *          on initialization, add code to init_mextra() in src/makemon.c
25  *       5. Create a newXX(mtmp) function and possibly a free_XX(mtmp)
26  *          function in an appropriate new or existing source file and add
27  *          a prototype for it to include/extern.h.
28  *
29  *              void newXX(struct monst *);
30  *              void free_XX(struct monst *);
31  *
32  *              void
33  *              newXX(mtmp)
34  *              struct monst *mtmp;
35  *              {
36  *                  if (!mtmp->mextra)
37  *                      mtmp->mextra = newmextra();
38  *                  if (!XX(mtmp)) {
39  *                      XX(mtmp) = (struct XX *) alloc(sizeof (struct XX));
40  *                      (void) memset((genericptr_t) XX(mtmp),
41  *                                    0, sizeof (struct XX));
42  *                  }
43  *              }
44  *
45  *       6. Consider adding a new makemon flag MM_XX flag to include/hack.h
46  *          and a corresponding change to makemon() if you require your
47  *          structure to be added at monster creation time.  Initialize your
48  *          struct after a successful return from makemon().
49  *
50  *              src/makemon.c:  if (mmflags & MM_XX) newXX(mtmp);
51  *              your new code:  mon = makemon(&mons[mnum], x, y, MM_XX);
52  *
53  *       7. Adjust size_monst() in src/cmd.c appropriately.
54  *       8. Adjust dealloc_mextra() in src/mon.c to clean up
55  *          properly during monst deallocation.
56  *       9. Adjust copy_mextra() in src/mon.c to make duplicate
57  *          copies of your struct or data on another monst struct.
58  *      10. Adjust restmon() in src/restore.c to deal with your
59  *          struct or data during a restore.
60  *      11. Adjust savemon() in src/save.c to deal with your
61  *          struct or data during a save.
62  */
63 
64 /***
65  **     formerly vault.h -- vault guard extension
66  */
67 #define FCSIZ (ROWNO + COLNO)
68 #define GD_EATGOLD 0x01
69 #define GD_DESTROYGOLD 0x02
70 
71 struct fakecorridor {
72     xchar fx, fy, ftyp;
73 };
74 
75 struct egd {
76     int fcbeg, fcend;     /* fcend: first unused pos */
77     int vroom;            /* room number of the vault */
78     xchar gdx, gdy;       /* goal of guard's walk */
79     xchar ogx, ogy;       /* guard's last position */
80     d_level gdlevel;      /* level (& dungeon) guard was created in */
81     xchar warncnt;        /* number of warnings to follow */
82     Bitfield(gddone, 1);  /* true iff guard has released player */
83     Bitfield(witness, 2); /* the guard saw you do something */
84     Bitfield(unused, 5);
85     struct fakecorridor fakecorr[FCSIZ];
86 };
87 
88 /***
89  **     formerly epri.h -- temple priest extension
90  */
91 struct epri {
92     aligntyp shralign; /* alignment of priest's shrine */
93     schar shroom;      /* index in rooms */
94     coord shrpos;      /* position of shrine */
95     d_level shrlevel;  /* level (& dungeon) of shrine */
96     long intone_time,  /* used to limit verbosity  +*/
97         enter_time,    /*+ of temple entry messages */
98         hostile_time,  /* forbidding feeling */
99         peaceful_time; /* sense of peace */
100 };
101 /* note: roaming priests (no shrine) switch from ispriest to isminion
102    (and emin extension) */
103 
104 /***
105  **     formerly eshk.h -- shopkeeper extension
106  */
107 #define REPAIR_DELAY 5 /* minimum delay between shop damage & repair */
108 #define BILLSZ 200
109 
110 struct bill_x {
111     unsigned bo_id;
112     boolean useup;
113     long price; /* price per unit */
114     long bquan; /* amount used up */
115 };
116 
117 struct eshk {
118     long robbed;          /* amount stolen by most recent customer */
119     long credit;          /* amount credited to customer */
120     long debit;           /* amount of debt for using unpaid items */
121     long loan;            /* shop-gold picked (part of debit) */
122     int shoptype;         /* the value of g.rooms[shoproom].rtype */
123     schar shoproom;       /* index in g.rooms; set by inshop() */
124     schar unused;         /* to force alignment for stupid compilers */
125     boolean following;    /* following customer since he owes us sth */
126     boolean surcharge;    /* angry shk inflates prices */
127     boolean dismiss_kops; /* pacified shk sends kops away */
128     coord shk;            /* usual position shopkeeper */
129     coord shd;            /* position shop door */
130     d_level shoplevel;    /* level (& dungeon) of his shop */
131     int billct;           /* no. of entries of bill[] in use */
132     struct bill_x bill[BILLSZ];
133     struct bill_x *bill_p;
134     int visitct;            /* nr of visits by most recent customer */
135     char customer[PL_NSIZ]; /* most recent customer */
136     char shknam[PL_NSIZ];
137 };
138 
139 /***
140  **     formerly emin.h -- minion extension
141  */
142 struct emin {
143     aligntyp min_align; /* alignment of minion */
144     boolean renegade;   /* hostile co-aligned priest or Angel */
145 };
146 
147 /***
148  **     formerly edog.h -- pet extension
149  */
150 /*      various types of pet food, the lower the value, the better liked */
151 enum dogfood_types {
152     DOGFOOD = 0,
153     CADAVER = 1,
154     ACCFOOD = 2,
155     MANFOOD = 3,
156     APPORT  = 4,
157     POISON  = 5,
158     UNDEF   = 6,
159     TABU    = 7
160 };
161 
162 struct edog {
163     long droptime;            /* moment dog dropped object */
164     unsigned dropdist;        /* dist of dropped obj from @ */
165     int apport;               /* amount of training */
166     long whistletime;         /* last time he whistled */
167     long hungrytime;          /* will get hungry at this time */
168     coord ogoal;              /* previous goal location */
169     int abuse;                /* track abuses to this pet */
170     int revivals;             /* count pet deaths */
171     int mhpmax_penalty;       /* while starving, points reduced */
172     Bitfield(killed_by_u, 1); /* you attempted to kill him */
173 };
174 
175 /***
176  **     extension tracking a player's remnant monster (ghost, mummy etc.)
177  */
178 struct ebones {
179     uchar role;             /* index into roles[] */
180     uchar race;             /* index into races[] */
181     align oldalign;         /* character alignment */
182     Bitfield(female, 1);    /* was female */
183     uchar deathlevel;       /* level when dying (m_lev may differ) */
184     schar luck;             /* luck when dying */
185     Bitfield(demigod, 1);   /* had killed wiz or invoked */
186     Bitfield(crowned, 1);   /* had been crowned */
187 };
188 
189 /***
190  **     mextra.h -- collection of all monster extensions
191  */
192 struct mextra {
193     char *mgivenname;
194     struct egd *egd;
195     struct epri *epri;
196     struct eshk *eshk;
197     struct emin *emin;
198     struct edog *edog;
199     struct ebones *ebones;
200     int mcorpsenm; /* obj->corpsenm for mimic posing as statue or corpse,
201                     * obj->spe (fruit index) for one posing as a slime mold,
202                     * or an alignment mask for one posing as an altar */
203 };
204 
205 #define MGIVENNAME(mon) ((mon)->mextra->mgivenname)
206 #define EGD(mon) ((mon)->mextra->egd)
207 #define EPRI(mon) ((mon)->mextra->epri)
208 #define ESHK(mon) ((mon)->mextra->eshk)
209 #define EMIN(mon) ((mon)->mextra->emin)
210 #define EDOG(mon) ((mon)->mextra->edog)
211 #define EBONES(mon) ((mon)->mextra->ebones)
212 #define MCORPSENM(mon) ((mon)->mextra->mcorpsenm)
213 
214 #define has_mgivenname(mon) ((mon)->mextra && MGIVENNAME(mon))
215 #define has_egd(mon)   ((mon)->mextra && EGD(mon))
216 #define has_epri(mon)  ((mon)->mextra && EPRI(mon))
217 #define has_eshk(mon)  ((mon)->mextra && ESHK(mon))
218 #define has_emin(mon)  ((mon)->mextra && EMIN(mon))
219 #define has_edog(mon)  ((mon)->mextra && EDOG(mon))
220 #define has_ebones(mon) ((mon)->mextra && EBONES(mon))
221 #define has_mcorpsenm(mon) ((mon)->mextra && MCORPSENM(mon) != NON_PM)
222 
223 #endif /* MEXTRA_H */
224