| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "global.h" |
| 20 |
|
| 21 |
#include <math.h> |
| 22 |
#include <stdlib.h> |
| 23 |
#include <string.h> |
| 24 |
|
| 25 |
#include "ob_methods.h" |
| 26 |
#include "ob_types.h" |
| 27 |
#include "sounds.h" |
| 28 |
#include "sproto.h" |
| 29 |
|
| 30 |
static method_ret food_type_apply(ob_methods *context, object *food, object *applier, int aflags); |
| 31 |
static void eat_special_food(object *who, object *food); |
| 32 |
static int dragon_eat_flesh(object *op, object *meal); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
void init_type_food(void) { |
| 38 |
register_apply(FOOD, food_type_apply); |
| 39 |
register_apply(DRINK, food_type_apply); |
| 40 |
register_apply(FLESH, food_type_apply); |
| 41 |
} |
| 42 |
|
| 43 |
static void cursed_food_effects(object *who, object *food) { |
| 44 |
|
| 45 |
if (food->stats.hp != 0 && !is_wraith_pl(who)) { |
| 46 |
if (QUERY_FLAG(food, FLAG_CURSED)) { |
| 47 |
safe_strncpy(who->contr->killer, food->name, |
| 48 |
sizeof(who->contr->killer)); |
| 49 |
hit_player(who, food->stats.hp, food, AT_POISON, 1); |
| 50 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_CURSED, |
| 51 |
"Eck!...that was poisonous!"); |
| 52 |
} else { |
| 53 |
if (food->stats.hp > 0) |
| 54 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 55 |
"You begin to feel better."); |
| 56 |
else |
| 57 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_CURSED, |
| 58 |
"Eck!...that was poisonous!"); |
| 59 |
who->stats.hp += food->stats.hp; |
| 60 |
} |
| 61 |
} |
| 62 |
if (food->stats.sp != 0) { |
| 63 |
if (QUERY_FLAG(food, FLAG_CURSED)) { |
| 64 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_CURSED, |
| 65 |
"You are drained of mana!"); |
| 66 |
who->stats.sp -= food->stats.sp; |
| 67 |
if (who->stats.sp < 0) |
| 68 |
who->stats.sp = 0; |
| 69 |
} else { |
| 70 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 71 |
"You feel a rush of magical energy!"); |
| 72 |
who->stats.sp += food->stats.sp; |
| 73 |
|
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
static void eat_common(object* applier, object* food) { |
| 79 |
char buf[MAX_BUF]; |
| 80 |
int capacity_remaining = MAX_FOOD - applier->stats.food; |
| 81 |
applier->stats.food += food->stats.food; |
| 82 |
if (capacity_remaining < food->stats.food) |
| 83 |
applier->stats.hp += capacity_remaining / 50; |
| 84 |
else |
| 85 |
applier->stats.hp += food->stats.food / 50; |
| 86 |
if (applier->stats.hp > applier->stats.maxhp) |
| 87 |
applier->stats.hp = applier->stats.maxhp; |
| 88 |
if (applier->stats.food > MAX_FOOD) |
| 89 |
applier->stats.food = MAX_FOOD; |
| 90 |
const int wasted_food = food->stats.food - capacity_remaining; |
| 91 |
if (wasted_food > 0) { |
| 92 |
const int thresh = MAX_FOOD/4; |
| 93 |
int speed_penalty; |
| 94 |
if (wasted_food > thresh) { |
| 95 |
speed_penalty = 10; |
| 96 |
} else { |
| 97 |
speed_penalty = 5; |
| 98 |
} |
| 99 |
|
| 100 |
if (slow_living_by(applier, speed_penalty)) { |
| 101 |
snprintf(buf, sizeof(buf), |
| 102 |
"%s the %s makes you %s full. You feel yourself moving %s " |
| 103 |
"slower.", |
| 104 |
food->type == DRINK ? "Drinking" : "Eating", food->name, |
| 105 |
wasted_food > thresh ? "very" : "rather", |
| 106 |
wasted_food > thresh ? "much" : "somewhat"); |
| 107 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_ATTRIBUTE, |
| 108 |
MSG_TYPE_ATTRIBUTE_BAD_EFFECT_START, buf); |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
static method_ret food_type_apply(ob_methods *context, object *food, object *applier, int aflags) { |
| 123 |
if (QUERY_FLAG(food, FLAG_NO_PICK)) { |
| 124 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, |
| 125 |
MSG_TYPE_APPLY_FAILURE, "You can't %s that!", |
| 126 |
food->type == DRINK ? "drink" : "eat"); |
| 127 |
return METHOD_OK; |
| 128 |
} |
| 129 |
|
| 130 |
if (applier->type != PLAYER) { |
| 131 |
applier->stats.hp = applier->stats.maxhp; |
| 132 |
} else { |
| 133 |
char buf[MAX_BUF]; |
| 134 |
if (food->type == FLESH && is_dragon_pl(applier)) { |
| 135 |
|
| 136 |
if (!QUERY_FLAG(food, FLAG_CURSED)) { |
| 137 |
dragon_eat_flesh(applier, food); |
| 138 |
eat_common(applier, food); |
| 139 |
} else { |
| 140 |
cursed_food_effects(applier, food); |
| 141 |
} |
| 142 |
} else if (is_old_wraith_pl(applier)) { |
| 143 |
|
| 144 |
object *skill = give_skill_by_name(applier, "wraith feed"); |
| 145 |
if (skill) { |
| 146 |
SET_FLAG(skill, FLAG_CAN_USE_SKILL); |
| 147 |
link_player_skills(applier); |
| 148 |
|
| 149 |
snprintf(buf, sizeof(buf), "You have been dead for too long to taste %s, ", food->name); |
| 150 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 151 |
buf); |
| 152 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 153 |
"and seem to have obtained a taste for living flesh."); |
| 154 |
} else |
| 155 |
LOG(llevError, "wraith feed skill not found\n"); |
| 156 |
} else if (is_wraith_pl(applier)) { |
| 157 |
|
| 158 |
snprintf(buf, sizeof(buf), "You can no longer taste %s, and do not feel less hungry after %s it.", food->name, food->type == DRINK ? "drinking" : "eating"); |
| 159 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 160 |
buf); |
| 161 |
} else { |
| 162 |
|
| 163 |
if (!QUERY_FLAG(food, FLAG_CURSED)) { |
| 164 |
if (!is_dragon_pl(applier)) { |
| 165 |
|
| 166 |
if (food->type == DRINK) |
| 167 |
snprintf(buf, sizeof(buf), "Ahhh...that %s tasted good.", food->name); |
| 168 |
else |
| 169 |
snprintf(buf, sizeof(buf), "The %s tasted %s", food->name, food->type == FLESH ? "terrible!" : "good."); |
| 170 |
} else { |
| 171 |
|
| 172 |
snprintf(buf, sizeof(buf), "The %s tasted terrible!", food->name); |
| 173 |
} |
| 174 |
draw_ext_info(0, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, buf); |
| 175 |
eat_common(applier, food); |
| 176 |
} else { |
| 177 |
cursed_food_effects(applier, food); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
if (food->title) |
| 182 |
eat_special_food(applier, food); |
| 183 |
} |
| 184 |
} |
| 185 |
if (food->type == DRINK) { |
| 186 |
play_sound_map(SOUND_TYPE_ITEM, applier, 0, "drink"); |
| 187 |
} |
| 188 |
apply_handle_yield(food); |
| 189 |
object_decrease_nrof_by_one(food); |
| 190 |
return METHOD_OK; |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
static void eat_special_food(object *who, object *food) { |
| 206 |
object *force; |
| 207 |
int i, did_one = 0; |
| 208 |
int8_t k; |
| 209 |
|
| 210 |
force = create_archetype(FORCE_NAME); |
| 211 |
|
| 212 |
for (i = 0; i < NUM_STATS; i++) { |
| 213 |
k = get_attr_value(&food->stats, i); |
| 214 |
if (k) { |
| 215 |
set_attr_value(&force->stats, i, k); |
| 216 |
did_one = 1; |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
for (i = 0; i < NROFATTACKS; i++) { |
| 222 |
if (food->resist[i] > 0) { |
| 223 |
force->resist[i] = food->resist[i]/2; |
| 224 |
did_one = 1; |
| 225 |
} |
| 226 |
} |
| 227 |
if (did_one) { |
| 228 |
force->speed = MOVE_PER_SECOND; |
| 229 |
object_update_speed(force); |
| 230 |
|
| 231 |
force->duration = food->stats.food/4; |
| 232 |
SET_FLAG(force, FLAG_IS_USED_UP); |
| 233 |
SET_FLAG(force, FLAG_APPLIED); |
| 234 |
change_abil(who, force); |
| 235 |
object_insert_in_ob(force, who); |
| 236 |
} else { |
| 237 |
object_free_drop_inventory(force); |
| 238 |
} |
| 239 |
|
| 240 |
fix_object(who); |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
static int dragon_eat_flesh(object *op, object *meal) { |
| 257 |
object *skin = NULL; |
| 258 |
object *abil = NULL; |
| 259 |
|
| 260 |
char buf[MAX_BUF]; |
| 261 |
double chance; |
| 262 |
double totalchance = 1; |
| 263 |
double bonus = 0; |
| 264 |
double mbonus = 0; |
| 265 |
int atnr_winner[NROFATTACKS]; |
| 266 |
int winners = 0; |
| 267 |
int i; |
| 268 |
|
| 269 |
|
| 270 |
if (meal->type != FLESH || !is_dragon_pl(op)) |
| 271 |
return 0; |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
skin = object_find_by_type_and_arch_name(op, FORCE, "dragon_skin_force"); |
| 277 |
abil = object_find_by_type_and_arch_name(op, FORCE, "dragon_ability_force"); |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
if (skin == NULL || abil == NULL) |
| 283 |
return 0; |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
for (i = 0; i < NROFATTACKS; i++) { |
| 289 |
if (meal->resist[i] > 0 && atnr_is_dragon_enabled(i)) { |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
bonus = (settings.max_level-op->level)*30./((double)settings.max_level); |
| 294 |
if (i == abil->stats.exp) |
| 295 |
bonus += 5; |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
mbonus = op->level*20./((double)settings.max_level); |
| 301 |
|
| 302 |
chance = (((double)MIN(op->level+bonus, meal->level+bonus+mbonus))*100./((double)settings.max_level))-skin->resist[i]; |
| 303 |
|
| 304 |
if (chance >= 0.) |
| 305 |
chance += 1.; |
| 306 |
else |
| 307 |
chance = (chance < -12) ? 0. : 1./pow(2., -chance); |
| 308 |
|
| 309 |
|
| 310 |
chance *= ((double)(MIN(meal->resist[i], 50)))/50.; |
| 311 |
|
| 312 |
|
| 313 |
if (i == abil->stats.exp) |
| 314 |
chance = MIN(100., chance*2.); |
| 315 |
|
| 316 |
|
| 317 |
if (RANDOM()%10000 < (unsigned int)(chance*100)) { |
| 318 |
atnr_winner[winners] = i; |
| 319 |
winners++; |
| 320 |
} |
| 321 |
|
| 322 |
if (chance >= 0.01) |
| 323 |
totalchance *= 1-chance/100; |
| 324 |
|
| 325 |
|
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
totalchance = 100-totalchance*100; |
| 331 |
|
| 332 |
if (totalchance > 50.) |
| 333 |
snprintf(buf, sizeof(buf), "Hmm! The %s tasted delicious!", meal->name); |
| 334 |
else if (totalchance > 10.) |
| 335 |
snprintf(buf, sizeof(buf), "The %s tasted very good.", meal->name); |
| 336 |
else if (totalchance > 1.) |
| 337 |
snprintf(buf, sizeof(buf), "The %s tasted good.", meal->name); |
| 338 |
else if (totalchance > 0.1) |
| 339 |
snprintf(buf, sizeof(buf), "The %s tasted bland.", meal->name); |
| 340 |
else if (totalchance >= 0.01) |
| 341 |
snprintf(buf, sizeof(buf), "The %s had a boring taste.", meal->name); |
| 342 |
else if (meal->last_eat > 0 && atnr_is_dragon_enabled(meal->last_eat)) |
| 343 |
snprintf(buf, sizeof(buf), "The %s tasted strange.", meal->name); |
| 344 |
else |
| 345 |
snprintf(buf, sizeof(buf), "The %s had no taste.", meal->name); |
| 346 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 347 |
buf); |
| 348 |
|
| 349 |
|
| 350 |
i = -1; |
| 351 |
if (winners > 0) |
| 352 |
i = atnr_winner[RANDOM()%winners]; |
| 353 |
|
| 354 |
if (i >= 0 && i < NROFATTACKS && skin->resist[i] < 95) { |
| 355 |
|
| 356 |
skin->resist[i]++; |
| 357 |
fix_object(op); |
| 358 |
|
| 359 |
draw_ext_info_format(NDI_UNIQUE|NDI_RED, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_PROTECTION_GAIN, |
| 360 |
"Your skin is now more resistant to %s!", |
| 361 |
change_resist_msg[i]); |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
if (meal->last_eat > 0 |
| 368 |
&& atnr_is_dragon_enabled(meal->last_eat) |
| 369 |
&& meal->last_eat != abil->last_eat) { |
| 370 |
abil->last_eat = meal->last_eat; |
| 371 |
|
| 372 |
if (meal->last_eat != abil->stats.exp) { |
| 373 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_RACE, |
| 374 |
"Your metabolism prepares to focus on %s!", |
| 375 |
change_resist_msg[meal->last_eat]); |
| 376 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_RACE, |
| 377 |
"The change will happen at level %d", |
| 378 |
abil->level+1); |
| 379 |
} else { |
| 380 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_RACE, |
| 381 |
"Your metabolism will continue to focus on %s.", |
| 382 |
change_resist_msg[meal->last_eat]); |
| 383 |
abil->last_eat = 0; |
| 384 |
} |
| 385 |
} |
| 386 |
return 1; |
| 387 |
} |