1 /* 2 * effects.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 __EFFECTS_H_ 20 #define __EFFECTS_H_ 21 22 #include <glib.h> 23 #include <time.h> 24 25 #include "cJSON.h" 26 27 typedef enum _effect_t 28 { 29 ET_NONE, /* no short-term effect */ 30 /* POSITIVE EFFECTS */ 31 /* base attribute modification */ 32 ET_INC_CON, /* enhanced constitution */ 33 ET_INC_DEX, /* enhanced dexterity */ 34 ET_INC_INT, /* enhanced intelligence */ 35 ET_INC_STR, /* enhanced strength */ 36 ET_INC_WIS, /* enhanced wisdom */ 37 ET_INC_RND, /* increase random ability */ 38 39 /* secondary attributes modification */ 40 ET_INC_DAMAGE, /* increased damage */ 41 ET_INC_HP_MAX, /* increased HP max */ 42 ET_INC_MP_MAX, /* increased MP max */ 43 ET_INC_HP_REGEN, /* increased hp regeneration */ 44 ET_INC_MP_REGEN, /* increased mp regeneration */ 45 ET_INC_LEVEL, /* gain level */ 46 ET_INC_EXP, /* gain experience */ 47 ET_RESIST_FIRE, /* resist fire */ 48 ET_RESIST_COLD, /* resist cold */ 49 ET_RESIST_MAGIC, /* resist magic */ 50 ET_PROTECTION, /* adds to AC */ 51 52 /* ability improvements */ 53 ET_STEALTH, /* stealth */ 54 ET_AWARENESS, /* expanded awareness */ 55 ET_SPEED, /* fast */ 56 ET_HEROISM, /* heroism: big bonus on all base attributes */ 57 ET_INVISIBILITY, /* invisible */ 58 ET_INVULNERABILITY, /* invulnerability */ 59 ET_INFRAVISION, /* see invisible monsters */ 60 ET_ENLIGHTENMENT, /* enlightenment */ 61 ET_REFLECTION, /* reflection */ 62 63 ET_DETECT_MONSTER, /* sense presence of monsters */ 64 ET_HOLD_MONSTER, /* monsters can't flee */ 65 ET_SCARED, /* monsters turn to flee */ 66 ET_CHARM_MONSTER, /* make monsters peaceful */ 67 68 /* healing */ 69 ET_INC_HP, /* heal */ 70 ET_MAX_HP, /* full healing */ 71 ET_INC_MP, /* restore mana */ 72 ET_MAX_MP, /* full mana restore */ 73 74 ET_CANCELLATION, /* cancels spheres */ 75 ET_UNDEAD_PROTECTION, /* protection against undead */ 76 ET_SPIRIT_PROTECTION, /* protection against spirits */ 77 ET_LIFE_PROTECTION, /* you only live twice */ 78 ET_NOTHEFT, /* protection from thievish monsters */ 79 ET_SUSTAINMENT, /* protection from stat drain attacks */ 80 ET_TIMESTOP, /* game time modification */ 81 ET_WALL_WALK, /* ability to walk through walls */ 82 ET_LEVITATION, /* affected person floats in the air */ 83 84 /* NEGATIVE EFFECTS */ 85 /* base attribute modification */ 86 ET_DEC_CON, /* reduced constitution */ 87 ET_DEC_DEX, /* reduced dexterity */ 88 ET_DEC_INT, /* reduced intelligence */ 89 ET_DEC_STR, /* reduced strength */ 90 ET_DEC_WIS, /* reduced wisdom */ 91 ET_DEC_RND, /* reduce random attribute */ 92 93 ET_AGGRAVATE_MONSTER, /* aggravate monsters */ 94 ET_SLEEP, /* no move for a certain amount of time */ 95 ET_DIZZINESS, /* decrease all primary attributes */ 96 ET_SICKNESS, /* decreased damage */ 97 ET_BLINDNESS, /* remove the ability to see */ 98 ET_CLUMSINESS, /* unable to wield weapon */ 99 ET_ITCHING, /* unable to wear armour */ 100 ET_CONFUSION, /* random movement */ 101 ET_PARALYSIS, /* loss of ability to move */ 102 ET_POISON, /* cause by potion or trap */ 103 ET_AMNESIA, /* potion of forgetfulness */ 104 ET_SLOWNESS, /* reduced speed */ 105 ET_BURDENED, /* overloaded */ 106 ET_OVERSTRAINED, /* extremely overloaded */ 107 ET_TRAPPED, /* trapped in a pit */ 108 109 ET_MAX /* last effect known */ 110 } effect_t; 111 112 typedef struct effect_data 113 { 114 effect_t id; 115 const char *name; /* name of the effect's constant */ 116 guint duration; /* duration of effect. 0 = permanent */ 117 int amount; /* if modifier: amount of attribute modification */ 118 const char *desc; /* description for status display and obituary */ 119 const char *msg_start; /* message displayed when effect starts */ 120 const char *msg_stop; /* message displayed when effect ends */ 121 const char *msg_start_monster; /* messages shown when the effect happens on a monster */ 122 const char *msg_stop_monster; 123 guint /* effect flags */ 124 var_duration: 1, /* the effect's duration is variable */ 125 var_amount: 1, /* the effect's amount is variable */ 126 inc_duration: 1, /* reset the duration of unique effects */ 127 inc_amount: 1; /* extend the amount of unique effects */ 128 } effect_data; 129 130 typedef struct effect 131 { 132 gpointer oid; /* effect's game object id */ 133 effect_t type; /* type of effect */ 134 guint32 start; /* game time the effect began */ 135 guint32 turns; /* number of turns this effect remains */ 136 gint32 amount; /* power of effect, if applicable */ 137 gpointer item; /* oid of item which causes the effect (if caused by item) */ 138 } effect; 139 140 struct game; 141 142 /* function declarations */ 143 144 effect *effect_new(effect_t type); 145 effect *effect_copy(effect *e); 146 void effect_destroy(effect *e); 147 148 void effect_serialize(gpointer oid, effect *e, cJSON *root); 149 effect *effect_deserialize(cJSON *eser, struct game *g); 150 cJSON *effects_serialize(GPtrArray *effs); 151 GPtrArray *effects_deserialize(cJSON *eser); 152 153 const char *effect_type_name(effect_t type); 154 guint effect_type_duration(effect_t type); 155 int effect_type_amount(effect_t type); 156 gboolean effect_type_inc_duration(effect_t type); 157 gboolean effect_type_inc_amount(effect_t type); 158 const char *effect_get_desc(effect *e); 159 const char *effect_get_msg_start(effect *e); 160 const char *effect_get_msg_stop(effect *e); 161 const char *effect_get_msg_m_start(effect *e); 162 const char *effect_get_msg_m_stop(effect *e); 163 164 int effect_get_amount(effect *e); 165 166 effect *effect_add(GPtrArray *ea, effect *e); 167 int effect_del(GPtrArray *ea, effect *e); 168 effect *effect_get(GPtrArray *ea, effect_t type); 169 170 /* check if an effect is set */ 171 int effect_query(GPtrArray *ea, effect_t type); 172 173 /** 174 * Count down the number of turns remaining for an effect. 175 * 176 * @param an effect 177 * @return turns remaining. Expired effects return -1, permantent effects 0 178 */ 179 int effect_expire(effect *e); 180 181 #endif 182