1 /*
2  * combat.h
3  * Copyright (C) 2009-2018 Joachim de Groot <jdegroot@web.de>
4  *
5  * NLarn is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * NLarn is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __COMBAT_H_
20 #define __COMBAT_H_
21 
22 #include <glib.h>
23 
24 #include "enumFactory.h"
25 
26 #define SPEED_ENUM(SPEED) \
27     SPEED(XSLOW,  =  25) \
28     SPEED(VSLOW,  =  50) \
29     SPEED(SLOW,   =  75) \
30     SPEED(NORMAL, = 100) \
31     SPEED(FAST,   = 125) \
32     SPEED(VFAST,  = 150) \
33     SPEED(XFAST,  = 175) \
34     SPEED(DOUBLE, = 200) \
35 
36 DECLARE_ENUM(speed, SPEED_ENUM)
37 
38 #define SIZE_ENUM(SIZE) \
39     SIZE(TINY,       =  25) \
40     SIZE(SMALL,      =  75) \
41     SIZE(MEDIUM,     = 100) \
42     SIZE(LARGE,      = 125) \
43     SIZE(GIANT,      = 150) \
44     SIZE(GARGANTUAN, = 200) \
45 
46 DECLARE_ENUM(size, SIZE_ENUM)
47 
48 #define ATTACK_T_ENUM(ATT) \
49     ATT(ATT_NONE,) \
50     ATT(ATT_WEAPON,) \
51     ATT(ATT_MAGIC,)  /* e.g. psionics */ \
52     ATT(ATT_CLAW,)   /* some dragons */ \
53     ATT(ATT_BITE,)   /* bugbear, osquip, snake */ \
54     ATT(ATT_STING,)  /* ant, centipede */ \
55     ATT(ATT_SLAM,)   /* shambling mound */ \
56     ATT(ATT_KICK,)   /* centaur */ \
57     ATT(ATT_TOUCH,)  /* vampire, wraith */ \
58     ATT(ATT_BREATH,) /* dragons, hellhound */ \
59     ATT(ATT_GAZE,)   /* floating eye */ \
60 
61 DECLARE_ENUM(attack_t, ATTACK_T_ENUM)
62 
63 #define DAMAGE_T_ENUM(DAM) \
64     DAM(DAM_NONE,)           /* pass-through: just reduce HP */ \
65     DAM(DAM_PHYSICAL,)       /* e.g. magic missile */ \
66     DAM(DAM_MAGICAL,) \
67     /* elements */ \
68     DAM(DAM_FIRE,) \
69     DAM(DAM_COLD,) \
70     DAM(DAM_ACID,) \
71     DAM(DAM_WATER,) \
72     DAM(DAM_ELECTRICITY,) \
73     /* effects */ \
74     DAM(DAM_POISON,)         /* traps, snake */ \
75     DAM(DAM_BLINDNESS,)      /* lama nobe, green urchin */ \
76     DAM(DAM_CONFUSION,)      /* umber hulk */ \
77     DAM(DAM_PARALYSIS,)      /* floating eye */ \
78     DAM(DAM_DEC_CON,) \
79     DAM(DAM_DEC_DEX,)        /* quasit */ \
80     DAM(DAM_DEC_INT,) \
81     DAM(DAM_DEC_STR,)        /* ant, centipede */ \
82     DAM(DAM_DEC_WIS,) \
83     DAM(DAM_DEC_RND,)        /* ziller */ \
84     DAM(DAM_DRAIN_LIFE,)     /* vampire, wraith */ \
85     /* inventory manipulation */ \
86     /* these damage types are handled by the monster, not the player */ \
87     DAM(DAM_STEAL_GOLD,)     /* leprechaun */ \
88     DAM(DAM_STEAL_ITEM,)     /* nymph */ \
89     DAM(DAM_RUST,)           /* rust monster, gelatious cube */ \
90     DAM(DAM_REM_ENCH,)       /* remove enchantment from player's items */ \
91     DAM(DAM_MAX,) \
92     DAM(DAM_RANDOM,)         /* random damage: any of the types above */ \
93 
94 DECLARE_ENUM(damage_t, DAMAGE_T_ENUM)
95 
96 typedef struct _attack
97 {
98     attack_t type;
99     damage_t damage;
100     int base;
101     int rand;
102 } attack;
103 
104 #define DAMAGE_ORIGINATOR_T_ENUM(DAMO) \
105     DAMO(DAMO_NONE,) \
106     DAMO(DAMO_ITEM,) \
107     DAMO(DAMO_MAP,) \
108     DAMO(DAMO_MONSTER,) \
109     DAMO(DAMO_PLAYER,) \
110     DAMO(DAMO_SOBJECT,) \
111     DAMO(DAMO_SPHERE,) \
112     DAMO(DAMO_TRAP,) \
113     DAMO(DAMO_GOD,) \
114 
115 DECLARE_ENUM(damage_originator_t, DAMAGE_ORIGINATOR_T_ENUM)
116 
117 typedef struct _damage_originator
118 {
119     damage_originator_t ot;
120     gpointer originator;
121 } damage_originator;
122 
123 typedef struct _damage
124 {
125     damage_t type;
126     attack_t attack;
127     gint amount;
128     damage_originator dam_origin; /* the source of the damage */
129 } damage;
130 
131 typedef struct _damage_msg
132 {
133     char *msg_affected;
134     char *msg_unaffected;
135 } damage_msg;
136 
137 damage *damage_new(damage_t type, attack_t att_type, int amount,
138                    damage_originator_t damo, gpointer originator);
139 
140 damage *damage_copy(damage *dam);
141 
damage_free(damage * dam)142 static inline void damage_free(damage *dam) { g_free(dam); }
143 
144 char *damage_to_str(damage *dam);
145 
146 #endif
147