ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/apply.C
(Generate patch)

Comparing deliantra/server/server/apply.C (file contents):
Revision 1.118 by root, Thu Jul 26 00:27:08 2007 UTC vs.
Revision 1.229 by root, Fri Mar 26 20:17:48 2010 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <cmath> 25#include <cmath>
25 26
26#include <global.h> 27#include <global.h>
53 * subtype 5: arch or race 54 * subtype 5: arch or race
54 * subtype 7: all three 55 * subtype 7: all three
55 */ 56 */
56 if (op->subtype) 57 if (op->subtype)
57 { 58 {
58 arch_flag = (op->subtype & 1); 59 arch_flag = op->subtype & 1;
59 name_flag = (op->subtype & 2); 60 name_flag = op->subtype & 2;
60 race_flag = (op->subtype & 4); 61 race_flag = op->subtype & 4;
61 } 62 }
62 else 63 else
63 { 64 {
64 arch_flag = 1; 65 arch_flag = 1;
65 name_flag = 1; 66 name_flag = 1;
92 * Return value: 1 if money was destroyed, 0 if not. 93 * Return value: 1 if money was destroyed, 0 if not.
93 */ 94 */
94static int 95static int
95apply_id_altar (object *money, object *altar, object *pl) 96apply_id_altar (object *money, object *altar, object *pl)
96{ 97{
97 object *id, *marked; 98 dynbuf_text &buf = msg_dynbuf; buf.clear ();
98 int success = 0;
99 99
100 if (pl == NULL || pl->type != PLAYER) 100 if (!pl || pl->type != PLAYER)
101 return 0; 101 return 0;
102 102
103 /* Check for MONEY type is a special hack - it prevents 'nothing needs 103 /* Check for MONEY type is a special hack - it prevents 'nothing needs
104 * identifying' from being printed out more than it needs to be. 104 * identifying' from being printed out more than it needs to be.
105 */ 105 */
106 if (!check_altar_sacrifice (altar, money) || money->type != MONEY) 106 if (!check_altar_sacrifice (altar, money, pl) || money->type != MONEY)
107 return 0; 107 return 0;
108 108
109 marked = find_marked_object (pl);
110 /* if the player has a marked item, identify that if it needs to be 109 /* if the player has a marked item, identify that if it needs to be
111 * identified. IF it doesn't, then go through the player inventory. 110 * identified. If it doesn't, then go through the player inventory.
112 */ 111 */
112 if (object *marked = find_marked_object (pl))
113 if (marked && !QUERY_FLAG (marked, FLAG_IDENTIFIED) && need_identify (marked)) 113 if (!QUERY_FLAG (marked, FLAG_IDENTIFIED) && need_identify (marked))
114 { 114 {
115 if (operate_altar (altar, &money)) 115 if (operate_altar (altar, &money, pl))
116 { 116 {
117 identify (marked); 117 identify (marked);
118 new_draw_info_format (NDI_UNIQUE, 0, pl, "You have %s.", long_desc (marked, pl)); 118
119 buf.printf ("You have %s.\r", long_desc (marked, pl));
119 if (marked->msg) 120 if (marked->msg)
120 { 121 buf << "The item has a story:\r" << marked->msg << "\n\n";
121 new_draw_info (NDI_UNIQUE, 0, pl, "The item has a story:"); 122
122 new_draw_info (NDI_UNIQUE, 0, pl, marked->msg); 123 return !money;
123 } 124 }
124 return money == NULL;
125 } 125 }
126 }
127 126
128 for (id = pl->inv; id; id = id->below) 127 for (object *id = pl->inv; id; id = id->below)
129 { 128 {
130 if (!QUERY_FLAG (id, FLAG_IDENTIFIED) && !id->invisible && need_identify (id)) 129 if (!QUERY_FLAG (id, FLAG_IDENTIFIED) && !id->invisible && need_identify (id))
131 { 130 {
132 if (operate_altar (altar, &money)) 131 if (operate_altar (altar, &money, pl))
133 { 132 {
134 identify (id); 133 identify (id);
135 new_draw_info_format (NDI_UNIQUE, 0, pl, "You have %s.", long_desc (id, pl)); 134
135 buf.printf ("You have %s.\r", long_desc (id, pl));
136 if (id->msg) 136 if (id->msg)
137 { 137 buf << "The item has a story:\r" << id->msg << "\n\n";
138 new_draw_info (NDI_UNIQUE, 0, pl, "The item has a story:"); 138
139 new_draw_info (NDI_UNIQUE, 0, pl, id->msg);
140 }
141 success = 1;
142 /* If no more money, might as well quit now */ 139 /* If no more money, might as well quit now */
143 if (money == NULL || !check_altar_sacrifice (altar, money)) 140 if (!money || !check_altar_sacrifice (altar, money))
144 break; 141 break;
145 } 142 }
146 else 143 else
147 { 144 {
148 LOG (llevError, "check_id_altar: Couldn't do sacrifice when we should have been able to\n"); 145 LOG (llevError, "check_id_altar: Couldn't do sacrifice when we should have been able to\n");
149 break; 146 break;
150 } 147 }
151 } 148 }
152 } 149 }
153 if (!success) 150
154 new_draw_info (NDI_UNIQUE, 0, pl, "You have nothing that needs identifying"); 151 if (buf.empty ())
152 pl->failmsg ("You have nothing that needs identifying");
153 else
154 pl->contr->infobox (MSG_CHANNEL ("identify"), buf);
155
155 return money == NULL; 156 return !money;
156} 157}
157 158
158/** 159/**
159 * This checks whether the object has a "on_use_yield" field, and if so generated and drops 160 * This checks whether the object has a "on_use_yield" field, and if so generated and drops
160 * matching item. 161 * matching item.
161 **/ 162 **/
162void 163void
163handle_apply_yield (object *tmp) 164handle_apply_yield (object *tmp)
164{ 165{
165 const char *yield; 166 if (shstr_tmp yield = tmp->kv (shstr_on_use_yield))
166 167 archetype::get (yield)->insert_at (tmp, tmp, INS_BELOW_ORIGINATOR);
167 yield = get_ob_key_value (tmp, "on_use_yield");
168 if (yield != NULL)
169 {
170 object *drop = get_archetype (yield);
171
172 if (tmp->env)
173 {
174 drop = insert_ob_in_ob (drop, tmp->env);
175 if (tmp->env->type == PLAYER)
176 esrv_send_item (tmp->env, drop);
177 }
178 else
179 {
180 drop->x = tmp->x;
181 drop->y = tmp->y;
182 insert_ob_in_map (drop, tmp->map, tmp, INS_BELOW_ORIGINATOR);
183 }
184 }
185} 168}
186 169
187/** 170/**
188 * Handles applying a potion. 171 * Handles applying a potion.
189 */ 172 */
190int 173int
191apply_potion (object *op, object *tmp) 174apply_potion (object *op, object *tmp)
192{ 175{
193 int got_one = 0, i; 176 int got_one = 0, i;
194 object *force = 0, *floor = 0; 177 object *force = 0;
195 178
196 floor = GET_MAP_OB (op->map, op->x, op->y); 179 object *floor = GET_MAP_OB (op->map, op->x, op->y);
197 180
198 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) 181 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE)
199 { 182 {
200 if (op->type == PLAYER)
201 new_draw_info (NDI_UNIQUE, 0, op, "Gods prevent you from using this here, it's sacred ground!"); 183 op->failmsg ("Gods prevent you from using this here, it's sacred ground!");
184
202 CLEAR_FLAG (tmp, FLAG_APPLIED); 185 CLEAR_FLAG (tmp, FLAG_APPLIED);
203 return 0; 186 return 0;
204 } 187 }
205 188
206 if (op->type == PLAYER) 189 if (op->type == PLAYER)
217 200
218 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 201 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
219 { 202 {
220 op->drain_stat (); 203 op->drain_stat ();
221 op->update_stats (); 204 op->update_stats ();
222 decrease_ob (tmp); 205 tmp->decrease ();
223 return 1; 206 return 1;
224 } 207 }
225 208
226 if (!(at = archetype::find (ARCH_DEPLETION))) 209 if (!(at = archetype::find (shstr_depletion)))
227 { 210 {
228 LOG (llevError, "Could not find archetype depletion\n"); 211 LOG (llevError, "Could not find archetype depletion\n");
229 return 0; 212 return 0;
230 } 213 }
214
231 depl = present_arch_in_ob (at, op); 215 depl = present_arch_in_ob (at, op);
232 216
233 if (depl) 217 if (depl)
234 { 218 {
235 for (i = 0; i < NUM_STATS; i++) 219 for (i = 0; i < NUM_STATS; i++)
236 if (depl->stats.stat (i)) 220 if (depl->stats.stat (i))
237 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]); 221 op->statusmsg (restore_msg[i]);
238 222
239 depl->destroy (); 223 depl->destroy ();
240 op->update_stats (); 224 op->update_stats ();
241 } 225 }
242 else 226 else
243 new_draw_info (NDI_UNIQUE, 0, op, "You potion had no effect."); 227 op->statusmsg ("Your potion had no effect.");
244 228
245 decrease_ob (tmp); 229 tmp->decrease ();
246 return 1; 230 return 1;
247 } 231 }
248 232
249 /* improvement potion - only for players */ 233 /* improvement potion - only for players */
250 if (op->type == PLAYER && tmp->attacktype & AT_GODPOWER) 234 if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER))
251 { 235 {
252 for (i = 1; i < MIN (11, op->level); i++) 236 for (i = 1; i < min (11, op->level); i++)
253 { 237 {
254 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 238 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
255 { 239 {
256 if (op->contr->levhp[i] != 1) 240 if (op->contr->levhp[i] != 1)
257 { 241 {
258 op->contr->levhp[i] = 1; 242 op->contr->levhp[i] = 1;
259 break; 243 break;
260 } 244 }
245
261 if (op->contr->levsp[i] != 1) 246 if (op->contr->levsp[i] != 1)
262 { 247 {
263 op->contr->levsp[i] = 1; 248 op->contr->levsp[i] = 1;
264 break; 249 break;
265 } 250 }
251
266 if (op->contr->levgrace[i] != 1) 252 if (op->contr->levgrace[i] != 1)
267 { 253 {
268 op->contr->levgrace[i] = 1; 254 op->contr->levgrace[i] = 1;
269 break; 255 break;
270 } 256 }
274 if (op->contr->levhp[i] < 9) 260 if (op->contr->levhp[i] < 9)
275 { 261 {
276 op->contr->levhp[i] = 9; 262 op->contr->levhp[i] = 9;
277 break; 263 break;
278 } 264 }
265
279 if (op->contr->levsp[i] < 6) 266 if (op->contr->levsp[i] < 6)
280 { 267 {
281 op->contr->levsp[i] = 6; 268 op->contr->levsp[i] = 6;
282 break; 269 break;
283 } 270 }
271
284 if (op->contr->levgrace[i] < 3) 272 if (op->contr->levgrace[i] < 3)
285 { 273 {
286 op->contr->levgrace[i] = 3; 274 op->contr->levgrace[i] = 3;
287 break; 275 break;
288 } 276 }
289 } 277 }
290 } 278 }
291 279
292 /* Just makes checking easier */ 280 /* Just makes checking easier */
293 if (i < MIN (11, op->level)) 281 if (i < min (11, op->level))
294 got_one = 1; 282 got_one = 1;
295 283
296 if (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED)) 284 if (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))
297 { 285 {
298 if (got_one) 286 if (got_one)
299 { 287 {
300 op->update_stats (); 288 op->update_stats ();
301 new_draw_info (NDI_UNIQUE, 0, op, "The Gods smile upon you and remake you"); 289 op->statusmsg ("The Gods smile upon you and remake you "
302 new_draw_info (NDI_UNIQUE, 0, op, "a little more in their image."); 290 "a little more in their image. "
303 new_draw_info (NDI_UNIQUE, 0, op, "You feel a little more perfect."); 291 "You feel a little more perfect.", NDI_GREEN);
304 } 292 }
305 else 293 else
306 new_draw_info (NDI_UNIQUE, 0, op, "The potion had no effect - you are already perfect"); 294 op->statusmsg ("The potion had no effect - you are already perfect.");
307 } 295 }
308 else 296 else
309 { /* cursed potion */ 297 { /* cursed potion */
310 if (got_one) 298 if (got_one)
311 { 299 {
312 op->update_stats (); 300 op->update_stats ();
313 new_draw_info (NDI_UNIQUE, 0, op, "The Gods are angry and punish you."); 301 op->failmsg ("The Gods are angry and punish you.");
314 } 302 }
315 else 303 else
316 new_draw_info (NDI_UNIQUE, 0, op, "You are fortunate that you are so pathetic."); 304 op->statusmsg ("You are fortunate that you are so pathetic.", NDI_DK_ORANGE);
317 } 305 }
318 306
319 decrease_ob (tmp); 307 tmp->decrease ();
320 return 1; 308 return 1;
321 } 309 }
322 310
323 311
324 /* A potion that casts a spell. Healing, restore spellpoint (power potion) 312 /* A potion that casts a spell. Healing, restore spellpoint (power potion)
328 */ 316 */
329 if (tmp->inv) 317 if (tmp->inv)
330 { 318 {
331 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 319 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
332 { 320 {
333 object *fball; 321 op->failmsg ("Yech! Your lungs are on fire!");
334 322 create_exploding_ball_at (op, op->level);
335 new_draw_info (NDI_UNIQUE, 0, op, "Yech! Your lungs are on fire!");
336 /* Explodes a fireball centered at player */
337 fball = get_archetype (EXPLODING_FIREBALL);
338 fball->dam_modifier = random_roll (1, op->level, op, PREFER_LOW) / 5 + 1;
339 fball->stats.maxhp = random_roll (1, op->level, op, PREFER_LOW) / 10 + 2;
340 fball->x = op->x;
341 fball->y = op->y;
342 insert_ob_in_map (fball, op->map, NULL, 0);
343 } 323 }
344 else 324 else
345 cast_spell (op, tmp, op->facing, tmp->inv, NULL); 325 cast_spell (op, tmp, op->facing, tmp->inv, NULL);
346 326
347 decrease_ob (tmp); 327 tmp->decrease ();
328
348 /* if youre dead, no point in doing this... */ 329 /* if youre dead, no point in doing this... */
349 if (!QUERY_FLAG (op, FLAG_REMOVED)) 330 if (!QUERY_FLAG (op, FLAG_REMOVED))
350 op->update_stats (); 331 op->update_stats ();
332
351 return 1; 333 return 1;
352 } 334 }
353 335
354 /* Deal with protection potions */ 336 /* Deal with protection potions */
355 force = NULL; 337 force = NULL;
357 { 339 {
358 if (tmp->resist[i]) 340 if (tmp->resist[i])
359 { 341 {
360 if (!force) 342 if (!force)
361 force = get_archetype (FORCE_NAME); 343 force = get_archetype (FORCE_NAME);
344
362 memcpy (force->resist, tmp->resist, sizeof (tmp->resist)); 345 memcpy (force->resist, tmp->resist, sizeof (tmp->resist));
363 force->type = POTION_EFFECT; 346 force->type = POTION_EFFECT;
364 break; /* Only need to find one protection since we copy entire batch */ 347 break; /* Only need to find one protection since we copy entire batch */
365 } 348 }
366 } 349 }
350
367 /* This is a protection potion */ 351 /* This is a protection potion */
368 if (force) 352 if (force)
369 { 353 {
370 /* cursed items last longer */ 354 /* cursed items last longer */
371 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 355 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
379 force->speed_left = -1; 363 force->speed_left = -1;
380 force = insert_ob_in_ob (force, op); 364 force = insert_ob_in_ob (force, op);
381 CLEAR_FLAG (tmp, FLAG_APPLIED); 365 CLEAR_FLAG (tmp, FLAG_APPLIED);
382 SET_FLAG (force, FLAG_APPLIED); 366 SET_FLAG (force, FLAG_APPLIED);
383 change_abil (op, force); 367 change_abil (op, force);
384 decrease_ob (tmp); 368 tmp->decrease ();
385 return 1; 369 return 1;
386 } 370 }
387 371
388 /* Only thing left are the stat potions */ 372 /* Only thing left are the stat potions */
389 if (op->type == PLAYER) 373 if (op->type == PLAYER)
390 { /* only for players */ 374 { /* only for players */
391 if ((QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) && tmp->value != 0) 375 if ((QUERY_FLAG (tmp, FLAG_CURSED)
376 || QUERY_FLAG (tmp, FLAG_DAMNED))
377 && tmp->value != 0)
392 CLEAR_FLAG (tmp, FLAG_APPLIED); 378 CLEAR_FLAG (tmp, FLAG_APPLIED);
393 else 379 else
394 SET_FLAG (tmp, FLAG_APPLIED); 380 SET_FLAG (tmp, FLAG_APPLIED);
381
395 if (!change_abil (op, tmp)) 382 if (!change_abil (op, tmp))
396 new_draw_info (NDI_UNIQUE, 0, op, "Nothing happened."); 383 op->statusmsg ("Nothing happened.");
397 } 384 }
398 385
399 /* CLEAR_FLAG is so that if the character has other potions 386 /* CLEAR_FLAG is so that if the character has other potions
400 * that were grouped with the one consumed, his 387 * that were grouped with the one consumed, his
401 * stat will not be raised by them. fix_player just clears 388 * stat will not be raised by them. fix_player just clears
402 * up all the stats. 389 * up all the stats.
403 */ 390 */
404 CLEAR_FLAG (tmp, FLAG_APPLIED); 391 CLEAR_FLAG (tmp, FLAG_APPLIED);
405 op->update_stats (); 392 op->update_stats ();
406 decrease_ob (tmp); 393 tmp->decrease ();
407 return 1; 394 return 1;
408} 395}
409 396
410/**************************************************************************** 397/****************************************************************************
411 * Weapon improvement code follows 398 * Weapon improvement code follows
412 ****************************************************************************/ 399 ****************************************************************************/
413 400
414/** 401/**
402 * This function just checks whether who can handle equipping an item
403 * with item_power.
404 */
405static bool
406check_item_power (object *who, int item_power)
407{
408 if (who->type == PLAYER
409 && item_power
410 && item_power + who->contr->item_power > settings.item_power_factor * who->level)
411 return false;
412 else
413 return true;
414}
415
416/**
415 * This returns the sum of nrof of item (arch name). 417 * This returns the sum of nrof of item (arch name).
416 */ 418 */
417static int 419static int
418check_item (object *op, const char *item) 420check_item (object *op, shstr_cmp item)
419{ 421{
420 int count = 0; 422 int count = 0;
421 423
422 424 if (!item)
423 if (item == NULL)
424 return 0; 425 return 0;
425 426
426 op = op->below; 427 for (op = op->below; op; op = op->below)
427 while (op != NULL)
428 {
429 if (strcmp (op->arch->archname, item) == 0) 428 if (op->arch->archname == item)
430 {
431 if (!QUERY_FLAG (op, FLAG_CURSED) && !QUERY_FLAG (op, FLAG_DAMNED) 429 if (!QUERY_FLAG (op, FLAG_CURSED) && !QUERY_FLAG (op, FLAG_DAMNED)
432 /* Loophole bug? -FD- */ && !QUERY_FLAG (op, FLAG_UNPAID)) 430 && /* Loophole bug? -FD- */ !QUERY_FLAG (op, FLAG_UNPAID))
433 {
434 if (op->nrof == 0) /* this is necessary for artifact sacrifices --FD-- */
435 count++;
436 else
437 count += op->nrof; 431 count += op->number_of ();
438 }
439 }
440
441 op = op->below;
442 }
443 432
444 return count; 433 return count;
445} 434}
446 435
447/** 436/**
449 * op is typically the player, which is only 438 * op is typically the player, which is only
450 * really used to determine what space to look at. 439 * really used to determine what space to look at.
451 * Modified to only eat 'nrof' of objects. 440 * Modified to only eat 'nrof' of objects.
452 */ 441 */
453static void 442static void
454eat_item (object *op, const char *item, uint32 nrof) 443eat_item (object *op, shstr_cmp item, uint32 nrof)
455{ 444{
456 object *prev; 445 object *prev;
457 446
458 prev = op; 447 prev = op;
459 op = op->below; 448 op = op->below;
460 449
461 while (op != NULL) 450 while (op)
462 { 451 {
463 if (strcmp (op->arch->archname, item) == 0) 452 if (op->arch->archname == item)
464 { 453 {
465 if (op->nrof >= nrof) 454 if (op->nrof >= nrof)
466 { 455 {
467 decrease_ob_nr (op, nrof); 456 op->decrease (nrof);
468 return; 457 return;
469 } 458 }
470 else 459 else
471 { 460 {
472 decrease_ob_nr (op, op->nrof); 461 op->decrease (nrof);
473 nrof -= op->nrof; 462 nrof -= op->nrof;
474 } 463 }
464
475 op = prev; 465 op = prev;
476 } 466 }
467
477 prev = op; 468 prev = op;
478 op = op->below; 469 op = op->below;
479 } 470 }
480} 471}
481 472
482/** 473/**
483 * This checks to see of the player (who) is sufficient level to use a weapon
484 * with improvs improvements (typically last_eat). We take an int here
485 * instead of the object so that the improvement code can pass along the
486 * increased value to see if the object is usuable.
487 * we return 1 (true) if the player can use the weapon.
488 */
489static int
490check_weapon_power (const object *who, int improvs)
491{
492
493/* Old code is below (commented out). Basically, since weapons are the only
494 * object players really have any control to improve, it's a bit harsh to
495 * require high level in some combat skill, so we just use overall level.
496 */
497#if 1
498 if (((who->level / 5) + 5) >= improvs)
499 return 1;
500 else
501 return 0;
502
503#else
504 int level = 0;
505
506 /* The skill system hands out wc and dam bonuses to fighters
507 * more generously than the old system (see fix_player). Thus
508 * we need to curtail the power of player enchanted weapons.
509 * I changed this to 1 improvement per "fighter" level/5 -b.t.
510 * Note: Nothing should break by allowing this ratio to be different or
511 * using normal level - it is just a matter of play balance.
512 */
513 if (who->type == PLAYER)
514 {
515 object *wc_obj = NULL;
516
517 for (wc_obj = who->inv; wc_obj; wc_obj = wc_obj->below)
518 if (wc_obj->type == SKILL && IS_COMBAT_SKILL (wc_obj->subtype) && wc_obj->level > level)
519 level = wc_obj->level;
520
521 if (!level)
522 {
523 LOG (llevError, "Error: Player: %s lacks wc experience object\n", who->name);
524 level = who->level;
525 }
526 }
527 else
528 level = who->level;
529
530 return (improvs <= ((level / 5) + 5));
531#endif
532}
533
534/**
535 * Returns how many items of type improver->slaying there are under op. 474 * Returns how many items of type improver->slaying there are under op.
536 * Will display a message if none found, and 1 if improver->slaying is NULL. 475 * Will display a message if none found, and 1 if improver->slaying is NULL.
537 */ 476 */
538static int 477static int
539check_sacrifice (object *op, const object *improver) 478check_sacrifice (object *op, const object *improver)
540{ 479{
541 int count = 0; 480 int count = 0;
542 481
543 if (improver->slaying != NULL) 482 if (improver->slaying)
544 { 483 {
545 count = check_item (op, improver->slaying); 484 count = check_item (op, improver->slaying);
546 if (count < 1) 485 if (count < 1)
547 { 486 {
548 char buf[200];
549
550 sprintf (buf, "The gods want more %ss", &improver->slaying); 487 op->failmsg (format ("The gods want more %ss", &improver->slaying));
551 new_draw_info (NDI_UNIQUE, 0, op, buf);
552 return 0; 488 return 0;
553 } 489 }
554 } 490 }
555 else 491 else
556 count = 1; 492 count = 1;
559} 495}
560 496
561/** 497/**
562 * Actually improves the weapon, and tells user. 498 * Actually improves the weapon, and tells user.
563 */ 499 */
564int 500static int
565improve_weapon_stat (object *op, object *improver, object *weapon, signed char *stat, int sacrifice_count, const char *statname) 501improve_weapon_stat (object *op, object *improver, object *weapon, sint8 &stat, int sacrifice_count, const char *statname)
566{ 502{
567
568 new_draw_info (NDI_UNIQUE, 0, op, "Your sacrifice was accepted.");
569 *stat += sacrifice_count; 503 stat += sacrifice_count;
570 weapon->last_eat++; 504 weapon->last_eat++;
571 new_draw_info_format (NDI_UNIQUE, 0, op, "Weapon's bonus to %s improved by %d", statname, sacrifice_count); 505 improver->decrease ();
572 decrease_ob (improver);
573 506
574 /* So it updates the players stats and the window */ 507 /* So it updates the players stats and the window */
575 op->update_stats (); 508 op->update_stats ();
509
510 op->statusmsg (format (
511 "Your sacrifice was accepted.\n"
512 "Weapon's bonus to %s improved by %d.",
513 statname, sacrifice_count
514 ));
515
576 return 1; 516 return 1;
577} 517}
578 518
579/* Types of improvements, hidden in the sp field. */ 519/* Types of improvements, hidden in the sp field. */
580#define IMPROVE_PREPARE 1 520#define IMPROVE_PREPARE 1
591 531
592/** 532/**
593 * This does the prepare weapon scroll. 533 * This does the prepare weapon scroll.
594 * Checks for sacrifice, and so on. 534 * Checks for sacrifice, and so on.
595 */ 535 */
596int 536static int
597prepare_weapon (object *op, object *improver, object *weapon) 537prepare_weapon (object *op, object *improver, object *weapon)
598{ 538{
599 int sacrifice_count, i; 539 int sacrifice_count, i;
600 char buf[MAX_BUF]; 540 char buf[MAX_BUF];
601 541
602 if (weapon->level != 0) 542 if (weapon->level != 0)
603 { 543 {
604 new_draw_info (NDI_UNIQUE, 0, op, "Weapon already prepared."); 544 op->failmsg ("Weapon is already prepared!");
605 return 0; 545 return 0;
606 } 546 }
607 547
608 for (i = 0; i < NROFATTACKS; i++) 548 for (i = 0; i < NROFATTACKS; i++)
609 if (weapon->resist[i]) 549 if (weapon->resist[i])
615 if (i < NROFATTACKS || weapon->stats.hp || /* regeneration */ 555 if (i < NROFATTACKS || weapon->stats.hp || /* regeneration */
616 (weapon->stats.sp && weapon->type == WEAPON) || /* sp regeneration */ 556 (weapon->stats.sp && weapon->type == WEAPON) || /* sp regeneration */
617 weapon->stats.exp || /* speed */ 557 weapon->stats.exp || /* speed */
618 weapon->stats.ac) /* AC - only taifu's I think */ 558 weapon->stats.ac) /* AC - only taifu's I think */
619 { 559 {
620 new_draw_info (NDI_UNIQUE, 0, op, "Cannot prepare magic weapons."); 560 op->failmsg ("You cannot prepare magic weapons. "
561 "H<A weapon is considered magical if it changes regeneration, "
562 "speed or ac, or has other protections.>");
621 return 0; 563 return 0;
622 } 564 }
623 565
624 sacrifice_count = check_sacrifice (op, improver); 566 sacrifice_count = check_sacrifice (op, improver);
625 if (sacrifice_count <= 0) 567 if (sacrifice_count <= 0)
626 return 0; 568 return 0;
627 569
628 weapon->level = isqrt (sacrifice_count); 570 weapon->level = isqrt (sacrifice_count);
629 new_draw_info (NDI_UNIQUE, 0, op, "Your sacrifice was accepted.");
630 eat_item (op, improver->slaying, sacrifice_count); 571 eat_item (op, improver->slaying, sacrifice_count);
631 572
632 new_draw_info_format (NDI_UNIQUE, 0, op, "Your *%s may be improved %d times.", &weapon->name, weapon->level); 573 op->statusmsg (format (
574 "Your sacrifice was accepted."
575 "Your *%s may be improved %d times.",
576 &weapon->name, weapon->level
577 ));
633 578
634 sprintf (buf, "%s's %s", &op->name, &weapon->name); 579 sprintf (buf, "%s's %s", &op->name, &weapon->name);
635 weapon->name = weapon->name_pl = buf; 580 weapon->name = weapon->name_pl = buf;
636 weapon->nrof = 0; /* prevents preparing n weapons in the same 581 weapon->nrof = 0; /* prevents preparing n weapons in the same
637 slot at once! */ 582 slot at once! */
638 decrease_ob (improver); 583 improver->decrease ();
639 weapon->last_eat = 0; 584 weapon->last_eat = 0;
640 return 1; 585 return 1;
641} 586}
642
643 587
644/** 588/**
645 * Does the dirty job for 'improve weapon' scroll, prepare or add something. 589 * Does the dirty job for 'improve weapon' scroll, prepare or add something.
646 * This is the new improve weapon code. 590 * This is the new improve weapon code.
647 * Returns 0 if it was not able to work for some reason. 591 * Returns 0 if it was not able to work for some reason.
650 * 594 *
651 * We are hiding extra information about the weapon in the level and 595 * We are hiding extra information about the weapon in the level and
652 * last_eat numbers for an object. Hopefully this won't break anything ?? 596 * last_eat numbers for an object. Hopefully this won't break anything ??
653 * level == max improve last_eat == current improve 597 * level == max improve last_eat == current improve
654 */ 598 */
655int 599static int
656improve_weapon (object *op, object *improver, object *weapon) 600improve_weapon (object *op, object *improver, object *weapon)
657{ 601{
658 int sacrifice_count, sacrifice_needed = 0; 602 int sacrifice_count, sacrifice_needed = 0;
659 603
660 if (improver->stats.sp == IMPROVE_PREPARE) 604 if (improver->stats.sp == IMPROVE_PREPARE)
661 {
662 return prepare_weapon (op, improver, weapon); 605 return prepare_weapon (op, improver, weapon);
663 } 606
664 if (weapon->level == 0) 607 if (weapon->level == 0)
665 { 608 {
666 new_draw_info (NDI_UNIQUE, 0, op, "This weapon has not been prepared."); 609 op->failmsg (
610 "This weapon has not been prepared."
611 " H<You first have to prepare a weapon with a prepare weapon scroll.>");
667 return 0; 612 return 0;
668 } 613 }
669 if (weapon->level == weapon->last_eat && weapon->item_power >= 100) 614
615 if (weapon->last_eat >= weapon->level // improvements used up
616 || weapon->item_power >= 100) // or item_power >= arbitrary limit of 100
670 { 617 {
671 new_draw_info (NDI_UNIQUE, 0, op, "This weapon cannot be improved any more."); 618 op->failmsg ("This weapon cannot be improved any more.");
672 return 0; 619 return 0;
673 } 620 }
674 if (QUERY_FLAG (weapon, FLAG_APPLIED) && !check_weapon_power (op, weapon->last_eat + 1)) 621
622 if (QUERY_FLAG (weapon, FLAG_APPLIED)
623 && !check_item_power (op, weapon->item_power + 1))
675 { 624 {
676 new_draw_info (NDI_UNIQUE, 0, op, "Improving the weapon will make it too"); 625 op->failmsg ("Improving the weapon will make it too "
677 new_draw_info (NDI_UNIQUE, 0, op, "powerful for you to use. Unready it if you"); 626 "powerful for you to use. Unready it if you "
678 new_draw_info (NDI_UNIQUE, 0, op, "really want to improve it."); 627 "really want to improve it.");
679 return 0; 628 return 0;
680 } 629 }
630
681 /* This just increases damage by 5 points, no matter what. No sacrifice 631 /* This just increases damage by 5 points, no matter what. No sacrifice
682 * is needed. Since stats.dam is now a 16 bit value and not 8 bit, 632 * is needed. Since stats.dam is now a 16 bit value and not 8 bit,
683 * don't put any maximum value on damage - the limit is how much the 633 * don't put any maximum value on damage - the limit is how much the
684 * weapon can be improved. 634 * weapon can be improved.
685 */ 635 */
686 if (improver->stats.sp == IMPROVE_DAMAGE) 636 if (improver->stats.sp == IMPROVE_DAMAGE)
687 { 637 {
688 weapon->stats.dam += 5; 638 weapon->stats.dam += 5;
689 weapon->weight += 5000; /* 5 KG's */ 639 weapon->weight += 5000; /* 5 KG's */
690 new_draw_info_format (NDI_UNIQUE, 0, op, "Damage has been increased by 5 to %d", weapon->stats.dam); 640 op->statusmsg (format ("Damage has been increased by 5 to %d.", weapon->stats.dam));
691 weapon->last_eat++; 641 weapon->last_eat++;
692 642
693 weapon->item_power++; 643 weapon->item_power++;
694 decrease_ob (improver); 644 improver->decrease ();
695 return 1; 645 return 1;
696 } 646 }
647
697 if (improver->stats.sp == IMPROVE_WEIGHT) 648 if (improver->stats.sp == IMPROVE_WEIGHT)
698 { 649 {
699 /* Reduce weight by 20% */ 650 /* Reduce weight by 20% */
700 weapon->weight = (weapon->weight * 8) / 10; 651 weapon->weight = (weapon->weight * 8) / 10;
701 if (weapon->weight < 1) 652 if (weapon->weight < 1)
702 weapon->weight = 1; 653 weapon->weight = 1;
654
703 new_draw_info_format (NDI_UNIQUE, 0, op, "Weapon weight reduced to %6.1f kg", (float) weapon->weight / 1000.0); 655 op->statusmsg (format ("Weapon weight reduced to %6.1fkg.", (float) weapon->weight / 1000.0));
704 weapon->last_eat++; 656 weapon->last_eat++;
705 weapon->item_power++; 657 weapon->item_power++;
706 decrease_ob (improver); 658 improver->decrease ();
707 return 1; 659 return 1;
708 } 660 }
661
709 if (improver->stats.sp == IMPROVE_ENCHANT) 662 if (improver->stats.sp == IMPROVE_ENCHANT)
710 { 663 {
711 weapon->magic++; 664 weapon->magic++;
712 weapon->last_eat++; 665 weapon->last_eat++;
713 new_draw_info_format (NDI_UNIQUE, 0, op, "Weapon magic increased to %d", weapon->magic); 666 op->statusmsg (format ("Weapon magic increased to %d.", weapon->magic));
714 decrease_ob (improver); 667 improver->decrease ();
715 weapon->item_power++; 668 weapon->item_power++;
716 return 1; 669 return 1;
717 } 670 }
718 671
719 sacrifice_needed = weapon->stats.Str + weapon->stats.Int + weapon->stats.Dex + 672 sacrifice_needed = weapon->stats.Str + weapon->stats.Int + weapon->stats.Dex +
724 sacrifice_needed *= 2; 677 sacrifice_needed *= 2;
725 678
726 sacrifice_count = check_sacrifice (op, improver); 679 sacrifice_count = check_sacrifice (op, improver);
727 if (sacrifice_count < sacrifice_needed) 680 if (sacrifice_count < sacrifice_needed)
728 { 681 {
729 new_draw_info_format (NDI_UNIQUE, 0, op, "You need at least %d %s", sacrifice_needed, &improver->slaying); 682 op->failmsg (format ("You need at least %d %s.", sacrifice_needed, &improver->slaying));
730 return 0; 683 return 0;
731 } 684 }
685
732 eat_item (op, improver->slaying, sacrifice_needed); 686 eat_item (op, improver->slaying, sacrifice_needed);
733 weapon->item_power++; 687 weapon->item_power++;
734 688
735 switch (improver->stats.sp) 689 switch (improver->stats.sp)
736 { 690 {
737 case IMPROVE_STR:
738 return improve_weapon_stat (op, improver, weapon, (signed char *) &(weapon->stats.Str), 1, "strength"); 691 case IMPROVE_STR: return improve_weapon_stat (op, improver, weapon, weapon->stats.Str, 1, "strength");
739 case IMPROVE_DEX:
740 return improve_weapon_stat (op, improver, weapon, (signed char *) &(weapon->stats.Dex), 1, "dexterity"); 692 case IMPROVE_DEX: return improve_weapon_stat (op, improver, weapon, weapon->stats.Dex, 1, "dexterity");
741 case IMPROVE_CON:
742 return improve_weapon_stat (op, improver, weapon, (signed char *) &(weapon->stats.Con), 1, "constitution"); 693 case IMPROVE_CON: return improve_weapon_stat (op, improver, weapon, weapon->stats.Con, 1, "constitution");
743 case IMPROVE_WIS:
744 return improve_weapon_stat (op, improver, weapon, (signed char *) &(weapon->stats.Wis), 1, "wisdom"); 694 case IMPROVE_WIS: return improve_weapon_stat (op, improver, weapon, weapon->stats.Wis, 1, "wisdom");
745 case IMPROVE_CHA:
746 return improve_weapon_stat (op, improver, weapon, (signed char *) &(weapon->stats.Cha), 1, "charisma"); 695 case IMPROVE_CHA: return improve_weapon_stat (op, improver, weapon, weapon->stats.Cha, 1, "charisma");
747 case IMPROVE_INT:
748 return improve_weapon_stat (op, improver, weapon, (signed char *) &(weapon->stats.Int), 1, "intelligence"); 696 case IMPROVE_INT: return improve_weapon_stat (op, improver, weapon, weapon->stats.Int, 1, "intelligence");
749 case IMPROVE_POW:
750 return improve_weapon_stat (op, improver, weapon, (signed char *) &(weapon->stats.Pow), 1, "power"); 697 case IMPROVE_POW: return improve_weapon_stat (op, improver, weapon, weapon->stats.Pow, 1, "power");
751 default: 698 default:
752 new_draw_info (NDI_UNIQUE, 0, op, "Unknown improvement type."); 699 op->failmsg ("Unknown improvement type.");
753 } 700 }
701
754 LOG (llevError, "improve_weapon: Got to end of function\n"); 702 LOG (llevError, "improve_weapon: Got to end of function\n");
755 return 0; 703 return 0;
756} 704}
757 705
758/** 706/**
759 * Handles the applying of improve/prepare/enchant weapon scroll. 707 * Handles the applying of improve/prepare/enchant weapon scroll.
760 * Checks a few things (not on a non-magic square, marked weapon, ...), 708 * Checks a few things (not on a non-magic square, marked weapon, ...),
761 * then calls improve_weapon to do the dirty work. 709 * then calls improve_weapon to do the dirty work.
762 */ 710 */
763int 711static int
764check_improve_weapon (object *op, object *tmp) 712check_improve_weapon (object *op, object *tmp)
765{ 713{
766 object *otmp; 714 object *otmp;
767 715
768 if (op->type != PLAYER) 716 if (op->type != PLAYER)
769 return 0; 717 return 0;
770 718
771 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)) 719 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC))
772 { 720 {
773 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll."); 721 op->failmsg ("Something blocks the magic of the scroll!");
774 return 0; 722 return 0;
775 } 723 }
776 724
777 otmp = find_marked_object (op); 725 otmp = find_marked_object (op);
726
778 if (!otmp) 727 if (!otmp)
779 { 728 {
780 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark a weapon object."); 729 op->failmsg ("You need to mark a weapon object. H<Use the mark command or the mark option from the item popup menu.>");
781 return 0; 730 return 0;
782 } 731 }
783 732
784 if (otmp->type != WEAPON && otmp->type != BOW) 733 if (otmp->type != WEAPON && otmp->type != BOW)
785 { 734 {
786 new_draw_info (NDI_UNIQUE, 0, op, "Marked item is not a weapon or bow"); 735 op->failmsg ("Marked item is not a weapon or bow!");
787 return 0; 736 return 0;
788 } 737 }
789 738
790 new_draw_info (NDI_UNIQUE, 0, op, "Applied weapon builder."); 739 op->statusmsg ("Applied weapon builder.");
740
791 improve_weapon (op, tmp, otmp); 741 improve_weapon (op, tmp, otmp);
792 esrv_send_item (op, otmp); 742 esrv_send_item (op, otmp);
793 return 1; 743 return 1;
794} 744}
795 745
813 * the armour value of the piece of equipment exceed either 763 * the armour value of the piece of equipment exceed either
814 * the users level or 90) 764 * the users level or 90)
815 * Modified by MSW for partial resistance. Only support 765 * Modified by MSW for partial resistance. Only support
816 * changing of physical area right now. 766 * changing of physical area right now.
817 */ 767 */
818int 768static int
819improve_armour (object *op, object *improver, object *armour) 769improve_armour (object *op, object *improver, object *armour)
820{ 770{
821 object *tmp; 771 object *tmp;
822 772
823 if (armour->magic >= settings.armor_max_enchant) 773 if (armour->magic >= settings.armor_max_enchant)
824 { 774 {
825 new_draw_info (NDI_UNIQUE, 0, op, "This armour can not be enchanted any further."); 775 op->failmsg ("This armour can not be enchanted any further!");
826 return 0; 776 return 0;
827 } 777 }
778
828 /* Dealing with random artifact armor is a lot trickier (in terms of value, weight, 779 /* Dealing with random artifact armor is a lot trickier (in terms of value, weight,
829 * etc), so take the easy way out and don't worry about it. 780 * etc), so take the easy way out and don't worry about it.
830 * Note - maybe add scrolls which make the random artifact versions (eg, armour 781 * Note - maybe add scrolls which make the random artifact versions (eg, armour
831 * of gnarg and what not?) 782 * of gnarg and what not?)
832 */ 783 */
833 if (armour->title) 784 if (armour->title)
834 { 785 {
835 new_draw_info (NDI_UNIQUE, 0, op, "This armour will not accept further enchantment."); 786 op->failmsg ("This armour will not accept further enchantment.");
836 return 0; 787 return 0;
837 } 788 }
838 789
839 /* Split objects if needed. Can't insert tmp until the 790 /* Split objects if needed. Can't insert tmp until the
840 * end of this function - otherwise it will just re-merge. 791 * end of this function - otherwise it will just re-merge.
841 */ 792 */
842 if (armour->nrof > 1) 793 tmp = armour->nrof > 1 ? armour->split (armour->nrof - 1) : 0;
843 tmp = get_split_ob (armour, armour->nrof - 1);
844 else
845 tmp = NULL;
846 794
847 armour->magic++; 795 armour->magic++;
848 796
849 if (!settings.armor_speed_linear) 797 if (!settings.armor_speed_linear)
850 { 798 {
887 armour->item_power = get_power_from_ench (armour->arch->item_power + armour->magic); 835 armour->item_power = get_power_from_ench (armour->arch->item_power + armour->magic);
888 836
889 if (op->type == PLAYER) 837 if (op->type == PLAYER)
890 { 838 {
891 esrv_send_item (op, armour); 839 esrv_send_item (op, armour);
840
892 if (QUERY_FLAG (armour, FLAG_APPLIED)) 841 if (QUERY_FLAG (armour, FLAG_APPLIED))
893 op->update_stats (); 842 op->update_stats ();
894 } 843 }
895 decrease_ob (improver); 844
845 improver->decrease ();
846
896 if (tmp) 847 if (tmp)
897 { 848 op->insert (tmp);
898 insert_ob_in_ob (tmp, op); 849
899 esrv_send_item (op, tmp);
900 }
901 return 1; 850 return 1;
902} 851}
903
904 852
905/* 853/*
906 * convert_item() returns 1 if anything was converted, 0 if the item was not 854 * convert_item() returns 1 if anything was converted, 0 if the item was not
907 * what the converter wants, -1 if the converter is broken. 855 * what the converter wants, -1 if the converter is broken.
908 */ 856 *
909#define CONV_FROM(xyz) xyz->slaying
910#define CONV_TO(xyz) xyz->other_arch
911#define CONV_NR(xyz) xyz->stats.sp
912#define CONV_NEED(xyz) xyz->stats.food
913
914/* Takes one items and makes another. 857 * Takes one type of items and makes another.
915 * converter is the object that is doing the conversion. 858 * converter is the object that is doing the conversion.
916 * item is the object that triggered the converter - if it is not 859 * item is the object that triggered the converter - if it is not
917 * what the converter wants, this will not do anything. 860 * what the converter wants, this will not do anything.
918 */ 861 */
919int 862int
920convert_item (object *item, object *converter) 863convert_item (object *item, object *converter)
921{ 864{
922 int nr = 0; 865 sint64 nr = 0, price_in;
923 uint32 price_in; 866
867 if (item->flag [FLAG_UNPAID])
868 return 0;
869
870 shstr conv_from = converter->slaying;
871 archetype *conv_to = converter->other_arch;
872 sint64 need = converter->stats.food;
873 sint64 give = converter->stats.sp;
924 874
925 /* We make some assumptions - we assume if it takes money as it type, 875 /* We make some assumptions - we assume if it takes money as it type,
926 * it wants some amount. We don't make change (ie, if something costs 876 * it wants some amount. We don't make change (ie, if something costs
927 * 3 gp and player drops a platinum, tough luck) 877 * 3 gp and player drops a platinum, tough luck)
928 */ 878 */
929 if (!strcmp (CONV_FROM (converter), "money")) 879 if (conv_from == shstr_money)
930 { 880 {
931 int cost;
932
933 if (item->type != MONEY) 881 if (item->type != MONEY)
934 return 0; 882 return 0;
935 883
936 nr = (item->nrof * item->value) / CONV_NEED (converter); 884 nr = sint64 (item->nrof) * item->value / need;
937 if (!nr) 885 if (!nr)
938 return 0; 886 return 0;
939 cost = nr * CONV_NEED (converter) / item->value; 887
940 /* take into account rounding errors */ 888 converter->play_sound (sound_find ("shop_buy"));
941 if (nr * CONV_NEED (converter) % item->value) 889
942 cost++; 890 sint64 cost = (nr * need + item->value - 1) / item->value;
943 decrease_ob_nr (item, cost); 891
892 item->decrease (cost);
944 893
945 price_in = cost * item->value; 894 price_in = cost * item->value;
946 } 895 }
947 else 896 else
948 { 897 {
949 if (item->type == PLAYER || CONV_FROM (converter) != item->arch->archname || 898 if (item->type == PLAYER
950 (CONV_NEED (converter) && CONV_NEED (converter) > (uint16) item->nrof)) 899 || conv_from != item->arch->archname
900 || (need && need > (uint16) item->nrof))
951 return 0; 901 return 0;
952 902
953 if (CONV_NEED (converter)) 903 converter->play_sound (sound_find ("convert_item"));
904
905 if (need)
954 { 906 {
955 nr = item->nrof / CONV_NEED (converter); 907 nr = sint64 (item->nrof) / need;
956 decrease_ob_nr (item, nr * CONV_NEED (converter)); 908 item->decrease (nr * need);
957 price_in = nr * CONV_NEED (converter) * item->value; 909 price_in = nr * need * item->value;
958 } 910 }
959 else 911 else
960 { 912 {
961 price_in = item->value; 913 price_in = item->value;
962 item->destroy (); 914 item->destroy ();
963 } 915 }
964 } 916 }
965 917
966 if (converter->inv != NULL) 918 if (converter->inv)
967 { 919 {
968 object *ob; 920 object *ob;
969 int i; 921 int i;
970 object *ob_to_copy; 922 object *ob_to_copy;
971 923
972 /* select random object from inventory to copy */ 924 /* select random object from inventory to copy */
973 ob_to_copy = converter->inv; 925 ob_to_copy = converter->inv;
974 for (ob = converter->inv->below, i = 1; ob != NULL; ob = ob->below, i++) 926 for (ob = converter->inv->below, i = 1; ob; ob = ob->below, i++)
975 {
976 if (rndm (0, i) == 0) 927 if (rndm (0, i) == 0)
977 {
978 ob_to_copy = ob; 928 ob_to_copy = ob;
979 } 929
980 } 930 item = ob_to_copy->deep_clone ();
981 item = object_create_clone (ob_to_copy);
982 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE); 931 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE);
983 unflag_inv (item, FLAG_IS_A_TEMPLATE); 932 unflag_inv (item, FLAG_IS_A_TEMPLATE);
984 } 933 }
985 else 934 else
986 { 935 {
987 if (converter->other_arch == NULL) 936 if (!conv_to)
988 { 937 {
989 LOG (llevError, "move_creator: Converter doesn't have other arch set: %s (%s, %d, %d)\n", 938 LOG (llevError, "move_creator: Converter doesn't have other arch set: %s (%s, %d, %d)\n",
990 &converter->name, &converter->map->path, converter->x, converter->y); 939 &converter->name, &converter->map->path, converter->x, converter->y);
991 return -1; 940 return -1;
992 } 941 }
993 942
994 item = object_create_arch (converter->other_arch); 943 item = object_create_arch (conv_to);
995 fix_generated_item (item, converter, 0, 0, GT_MINIMAL); 944 fix_generated_item (item, converter, 0, 0, GT_MINIMAL);
996 } 945 }
997 946
998 if (CONV_NR (converter)) 947 if (give)
999 item->nrof = CONV_NR (converter); 948 item->nrof = give;
949
1000 if (nr) 950 if (nr)
1001 item->nrof *= nr; 951 item->nrof *= nr;
1002 if (is_in_shop (converter)) 952
953 if (converter->flag [FLAG_PRECIOUS])
1003 SET_FLAG (item, FLAG_UNPAID); 954 SET_FLAG (item, FLAG_UNPAID);
955
956 if (is_in_shop (converter))
957 {
958 // converters on shop floors don't work anymore, bug lets check for it
959 // and report in case someone still does it.
960 LOG (llevDebug, "ITEMBUG: broken converter, converters on shop floor don't work: %s\n",
961 converter->debug_desc ());
962 SET_FLAG (item, FLAG_UNPAID);
963 }
1004 else if (price_in < item->nrof * item->value) 964 else if (price_in < sint64 (item->nrof) * item->value)
1005 { 965 {
1006 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", 966 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n",
1007 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name); 967 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name);
1008
1009 /** 968 /**
1010 * elmex: we are going to let the game continue, as the mapcreator 969 * elmex: we are going to let the game continue, as the mapcreator
1011 * probably had something in mind when doing this 970 * hopefully had something in mind when doing this.
1012 */ 971 */
1013 } 972 }
973
974 // elmex: only identify if we need to, for example so that generated money doesn't
975 // get an 'identified' flag so easily.
976 if (need_identify (item))
977 identify (item);
978
1014 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y); 979 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y);
1015 return 1; 980 return 1;
1016} 981}
1017 982
1018/** 983/**
1019 * Handle apply on containers. 984 * Handle apply on containers.
1020 * By Eneq(@csd.uu.se). 985 * By Eneq(@csd.uu.se).
1021 * Moved to own function and added many features [Tero.Haatanen@lut.fi] 986 * Moved to own function and added many features [Tero.Haatanen@lut.fi]
1022 * added the alchemical cauldron to the code -b.t. 987 * added the alchemical cauldron to the code -b.t.
1023 */ 988 */
1024int 989static int
1025apply_container (object *op, object *sack) 990apply_container (object *op, object *sack)
1026{ 991{
1027 if (op->type != PLAYER || !op->contr->ns) 992 if (op->type != PLAYER || !op->contr->ns)
1028 return 0; /* This might change */ 993 return 0; /* This might change */
1029 994
1035 1000
1036 op->contr->last_used = 0; 1001 op->contr->last_used = 0;
1037 1002
1038 if (sack->env && sack->env != op) 1003 if (sack->env && sack->env != op)
1039 { 1004 {
1040 new_draw_info (NDI_UNIQUE, 0, op, "You must put it onto the floor or into your inventory first."); 1005 op->failmsg ("You must put it onto the floor or into your inventory first.");
1041 return 1; 1006 return 1;
1042 } 1007 }
1043 1008
1044 // already applied == open on ground, or open in inv, or active in inv 1009 // already applied == open on ground, or open in inv, or active in inv
1045 if (sack->flag [FLAG_APPLIED]) 1010 if (sack->flag [FLAG_APPLIED])
1046 { 1011 {
1047 if (op->container == sack) 1012 if (op->container_ () == sack)
1048 { 1013 {
1049 // open on ground or inv, so close 1014 // open on ground or inv, so close
1050 op->close_container (); 1015 op->close_container ();
1051 return 1; 1016 return 1;
1052 } 1017 }
1053 else if (!sack->env) 1018 else if (!sack->env)
1054 { 1019 {
1055 // active, but not ours: some other player has opened it 1020 // active, but not ours: some other player has opened it
1056 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already occupied.", query_name (sack)); 1021 op->failmsg (format ("Somebody else is using the %s already.", query_name (sack)));
1057 return 1; 1022 return 1;
1058 } 1023 }
1059 1024
1060 // fall through to opening it (active in inv) 1025 // fall through to opening it (active in inv)
1061 } 1026 }
1063 { 1028 {
1064 // it is in our env, so activate it, do not open yet 1029 // it is in our env, so activate it, do not open yet
1065 op->close_container (); 1030 op->close_container ();
1066 sack->flag [FLAG_APPLIED] = 1; 1031 sack->flag [FLAG_APPLIED] = 1;
1067 esrv_update_item (UPD_FLAGS, op, sack); 1032 esrv_update_item (UPD_FLAGS, op, sack);
1068 new_draw_info_format (NDI_UNIQUE, 0, op, "You ready %s.", query_name (sack)); 1033 op->statusmsg (format ("You ready %s.", query_name (sack)));
1069 return 1; 1034 return 1;
1070 } 1035 }
1071 1036
1072 // it's locked? 1037 // it's locked?
1073 if (sack->slaying) 1038 if (sack->slaying)
1074 { 1039 {
1075 if (object *tmp = find_key (op, op, sack)) 1040 if (object *tmp = find_key (op, op, sack))
1076 new_draw_info_format (NDI_UNIQUE, 0, op, "You unlock %s with %s.", query_name (sack), query_name (tmp)); 1041 op->statusmsg (format ("You unlock %s with %s.", query_name (sack), query_name (tmp)));
1077 else 1042 else
1078 { 1043 {
1079 new_draw_info_format (NDI_UNIQUE, 0, op, "You don't have the key to unlock %s.", query_name (sack)); 1044 op->statusmsg (format ("You don't have the key to unlock %s.", query_name (sack)));
1080 return 1; 1045 return 1;
1081 } 1046 }
1082 } 1047 }
1083 1048
1084 op->open_container (sack); 1049 op->open_container (sack);
1095{ 1060{
1096 /* Only players can make sacrifices on spell casting altars. */ 1061 /* Only players can make sacrifices on spell casting altars. */
1097 if (altar->inv && (!originator || originator->type != PLAYER)) 1062 if (altar->inv && (!originator || originator->type != PLAYER))
1098 return 0; 1063 return 0;
1099 1064
1100 if (operate_altar (altar, &sacrifice)) 1065 if (operate_altar (altar, &sacrifice, originator))
1101 { 1066 {
1102 /* Simple check. Unfortunately, it means you can't cast magic bullet 1067 /* Simple check. Unfortunately, it means you can't cast magic bullet
1103 * with an altar. We call it a Potion - altars are stationary - it 1068 * with an altar. We call it a Potion - altars are stationary - it
1104 * is up to map designers to use them properly. 1069 * is up to map designers to use them properly.
1105 */ 1070 */
1106 if (altar->inv && altar->inv->type == SPELL) 1071 if (altar->inv && altar->inv->type == SPELL)
1107 { 1072 {
1108 new_draw_info_format (NDI_BLACK, 0, originator, "The altar casts %s.", &altar->inv->name); 1073 originator->statusmsg (format ("The altar casts %s.", &altar->inv->name));
1109 cast_spell (originator, altar, 0, altar->inv, NULL); 1074 cast_spell (originator, altar, 0, altar->inv, NULL);
1110 /* If it is connected, push the button. Fixes some problems with 1075 /* If it is connected, push the button. Fixes some problems with
1111 * old maps. 1076 * old maps.
1112 */ 1077 */
1113 1078
1114/* push_button (altar);*/ 1079/* push_button (altar);*/
1115 } 1080 }
1116 else 1081 else
1117 { 1082 {
1118 altar->value = 1; /* works only once */ 1083 altar->value = 1; /* works only once */
1119 push_button (altar); 1084 push_button (altar, originator);
1120 } 1085 }
1121 1086
1122 return !sacrifice; 1087 return !sacrifice;
1123 } 1088 }
1124 else 1089 else
1139 double opinion; 1104 double opinion;
1140 object *tmp, *next; 1105 object *tmp, *next;
1141 1106
1142 SET_FLAG (op, FLAG_NO_APPLY); /* prevent loops */ 1107 SET_FLAG (op, FLAG_NO_APPLY); /* prevent loops */
1143 1108
1144 if (op->type != PLAYER) 1109 bool has_unpaid = false;
1110
1111 // quite inefficient to do this here twice, but the api doesn't lend itself to
1112 // a quick and small change :(
1113 for (object::depth_iterator item = op->begin (); item != op->end (); ++item)
1114 if (item->flag [FLAG_UNPAID])
1115 {
1116 has_unpaid = true;
1117 break;
1118 }
1119
1120 if (!op->is_player ())
1145 { 1121 {
1146 /* Remove all the unpaid objects that may be carried here. 1122 /* Remove all the unpaid objects that may be carried here.
1147 * This could be pets or monsters that are somehow in 1123 * This could be pets or monsters that are somehow in
1148 * the shop. 1124 * the shop.
1149 */ 1125 */
1153 1129
1154 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 1130 if (QUERY_FLAG (tmp, FLAG_UNPAID))
1155 { 1131 {
1156 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); 1132 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9);
1157 1133
1134 if (i >= 0)
1158 tmp->remove (); 1135 tmp->move (i);
1159
1160 if (i == -1)
1161 i = 0;
1162
1163 tmp->map = op->map;
1164 tmp->x = op->x + freearr_x[i];
1165 tmp->y = op->y + freearr_y[i];
1166 insert_ob_in_map (tmp, op->map, op, 0);
1167 } 1136 }
1168 } 1137 }
1169 1138
1170 /* Don't teleport things like spell effects */ 1139 /* Don't teleport things like spell effects */
1171 if (QUERY_FLAG (op, FLAG_NO_PICK)) 1140 if (QUERY_FLAG (op, FLAG_NO_PICK))
1174 /* unpaid objects, or non living objects, can't transfer by 1143 /* unpaid objects, or non living objects, can't transfer by
1175 * shop mats. Instead, put it on a nearby space. 1144 * shop mats. Instead, put it on a nearby space.
1176 */ 1145 */
1177 if (QUERY_FLAG (op, FLAG_UNPAID) || !QUERY_FLAG (op, FLAG_ALIVE)) 1146 if (QUERY_FLAG (op, FLAG_UNPAID) || !QUERY_FLAG (op, FLAG_ALIVE))
1178 { 1147 {
1179
1180 /* Somebody dropped an unpaid item, just move to an adjacent place. */ 1148 /* Somebody dropped an unpaid item, just move to an adjacent place. */
1181 int i = find_free_spot (op, op->map, op->x, op->y, 1, 9); 1149 int i = find_free_spot (op, op->map, op->x, op->y, 1, 9);
1182 1150
1183 if (i != -1) 1151 if (i != -1)
1184 rv = transfer_ob (op, op->x + freearr_x[i], op->y + freearr_y[i], 0, shop_mat); 1152 rv = transfer_ob (op, op->x + freearr_x[i], op->y + freearr_y[i], 0, shop_mat);
1185 1153
1186 return 0; 1154 return 0;
1187 } 1155 }
1156
1188 /* Removed code that checked for multipart objects - it appears that 1157 /* Removed code that checked for multipart objects - it appears that
1189 * the teleport function should be able to handle this just fine. 1158 * the teleport function should be able to handle this just fine.
1190 */ 1159 */
1191 rv = teleport (shop_mat, SHOP_MAT, op); 1160 rv = teleport (shop_mat, SHOP_MAT, op);
1192 } 1161 }
1193 else if (can_pay (op) && get_payment (op)) 1162 else if (can_pay (op) && get_payment (op))
1194 { 1163 {
1195 /* this is only used for players */ 1164 /* this is only used for players */
1196 rv = teleport (shop_mat, SHOP_MAT, op); 1165 rv = teleport (shop_mat, SHOP_MAT, op);
1197 1166
1167 if (has_unpaid)
1168 op->contr->play_sound (sound_find ("shop_buy"));
1169 else if (is_in_shop (op))
1170 op->contr->play_sound (sound_find ("shop_enter"));
1171 else
1172 op->contr->play_sound (sound_find ("shop_leave"));
1173
1198 if (shop_mat->msg) 1174 if (shop_mat->msg)
1199 new_draw_info (NDI_UNIQUE, 0, op, shop_mat->msg); 1175 op->statusmsg (shop_mat->msg);
1200 /* This check below is a bit simplistic - generally it should be correct, 1176 /* This check below is a bit simplistic - generally it should be correct,
1201 * but there is never a guarantee that the bottom space on the map is 1177 * but there is never a guarantee that the bottom space on the map is
1202 * actually the shop floor. 1178 * actually the shop floor.
1203 */ 1179 */
1204 else if (!rv && !is_in_shop (op)) 1180 else if (!rv && !is_in_shop (op))
1205 { 1181 {
1206 opinion = shopkeeper_approval (op->map, op); 1182 opinion = shopkeeper_approval (op->map, op);
1207 1183
1208 if (opinion > 0.9) 1184 op->statusmsg (
1209 new_draw_info (NDI_UNIQUE, 0, op, "The shopkeeper gives you a friendly wave."); 1185 opinion >= 0.90 ? "The shopkeeper gives you a friendly wave."
1210 else if (opinion > 0.75) 1186 : opinion >= 0.75 ? "The shopkeeper waves to you."
1211 new_draw_info (NDI_UNIQUE, 0, op, "The shopkeeper waves to you."); 1187 : opinion >= 0.50 ? "The shopkeeper ignores you."
1212 else if (opinion > 0.5) 1188 : "The shopkeeper glares at you with contempt."
1213 new_draw_info (NDI_UNIQUE, 0, op, "The shopkeeper ignores you.");
1214 else 1189 );
1215 new_draw_info (NDI_UNIQUE, 0, op, "The shopkeeper glares at you with contempt.");
1216 } 1190 }
1217 } 1191 }
1218 else 1192 else
1219 { 1193 {
1220 /* if we get here, a player tried to leave a shop but was not able 1194 /* if we get here, a player tried to leave a shop but was not able
1221 * to afford the items he has. We try to move the player so that 1195 * to afford the items he has. We try to move the player so that
1222 * they are not on the mat anymore 1196 * they are not on the mat anymore
1223 */ 1197 */
1224 int i = find_free_spot (op, op->map, op->x, op->y, 1, 9); 1198 int i = find_free_spot (op, op->map, op->x, op->y, 1, 9);
1225 1199
1226 if (i == -1) 1200 if (i == -1)
1227 {
1228 LOG (llevError, "Internal shop-mat problem.\n"); 1201 LOG (llevError, "Internal shop-mat problem.\n");
1229 }
1230 else 1202 else
1231 { 1203 {
1232 op->remove (); 1204 op->remove ();
1233 op->x += freearr_x[i]; 1205 op->x += freearr_x[i];
1234 op->y += freearr_y[i]; 1206 op->y += freearr_y[i];
1244 * Handles applying a sign. 1216 * Handles applying a sign.
1245 */ 1217 */
1246static void 1218static void
1247apply_sign (object *op, object *sign, int autoapply) 1219apply_sign (object *op, object *sign, int autoapply)
1248{ 1220{
1249 readable_message_type *msgType; 1221 if (!op->is_player())
1222 return;
1250 1223
1251 if (sign->msg == NULL) 1224 if (sign->has_dialogue ())
1252 { 1225 {
1253 new_draw_info (NDI_UNIQUE, 0, op, "Nothing is written on it."); 1226 op->statusmsg (format ("Maybe you should I<talk> to the %s instead?", &sign->name));
1254 return; 1227 return;
1255 } 1228 }
1256 1229
1230 if (!sign->msg)
1231 {
1232 op->contr->infobox (MSG_CHANNEL ("examine"),
1233 format ("T<%s>\n\n Nothing %sis written on it.",
1234 &sign->name,
1235 sign->name == sign->arch->name ? "" : "else "));
1236 return;
1237 }
1238
1257 if (sign->stats.food) 1239 if (sign->stats.food)
1258 { 1240 {
1259 if (sign->last_eat >= sign->stats.food) 1241 if (sign->last_eat >= sign->stats.food)
1260 { 1242 {
1261 if (!sign->move_on) 1243 if (!sign->move_on)
1262 new_draw_info (NDI_UNIQUE, 0, op, "You cannot read it anymore."); 1244 op->failmsg ("You cannot read it anymore.");
1245
1263 return; 1246 return;
1264 } 1247 }
1265 1248
1266 if (!QUERY_FLAG (op, FLAG_WIZPASS)) 1249 if (!QUERY_FLAG (op, FLAG_WIZPASS))
1267 sign->last_eat++; 1250 sign->last_eat++;
1272 * move_on is zero, it needs to be manually applied (doesn't talk 1255 * move_on is zero, it needs to be manually applied (doesn't talk
1273 * to us). 1256 * to us).
1274 */ 1257 */
1275 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ) && !sign->move_on) 1258 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ) && !sign->move_on)
1276 { 1259 {
1277 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind."); 1260 op->failmsg ("You are unable to read while blind!");
1278 return; 1261 return;
1279 } 1262 }
1280 1263
1281 if (op->contr) 1264 if (op->contr)
1282 if (client *ns = op->contr->ns) 1265 if (client *ns = op->contr->ns)
1283 { 1266 {
1284 msgType = get_readable_message_type (sign); 1267 if (sign->sound)
1268 ns->play_sound (sign->sound);
1269 else if (autoapply)
1270 ns->play_sound (sound_find ("msg_voice"));
1285 1271
1286 if (ns->can_msg) 1272 op->contr->infobox (MSG_CHANNEL ("examine"), format ("T<%s>\n\n%s", &sign->name, &sign->msg));
1287 ns->send_msg (NDI_NAVY, msgType->msgtype, &sign->msg);
1288 else
1289 {
1290 char newbuf[HUGE_BUF];
1291 snprintf (newbuf, sizeof (newbuf), "%u %s", autoapply ? 1 : 0, &sign->msg);
1292 draw_ext_info (NDI_UNIQUE | NDI_NAVY, 0, op, msgType->message_type, msgType->message_subtype, newbuf, &sign->msg);
1293 }
1294 } 1273 }
1274}
1275
1276static void
1277move_apply_hole (object *trap, object *victim)
1278{
1279 /* Hole not open? */
1280 if (trap->stats.wc > 0)
1281 return;
1282
1283 /* Is this a multipart monster and not the head? If so, return.
1284 * Processing will happen if the head runs into the pit
1285 */
1286 if (victim->head)
1287 return;
1288
1289 // now find all possible locations and randomly pick one
1290 int dir = find_free_spot (victim, trap->map, EXIT_X (trap), EXIT_Y (trap), 0,
1291 trap->range >= 3 ? SIZEOFFREE3 + 1
1292 : trap->range >= 2 ? SIZEOFFREE2 + 1
1293 : trap->range >= 1 ? SIZEOFFREE1 + 1
1294 : SIZEOFFREE0 + 1);
1295
1296 if (dir < 0)
1297 return;
1298
1299 victim->play_sound (trap->sound ? trap->sound : sound_find ("fall_hole"));
1300 victim->statusmsg ("You fall through the hole!", NDI_RED);
1301
1302 transfer_ob (victim,
1303 EXIT_X (trap) + freearr_x[dir],
1304 EXIT_Y (trap) + freearr_y[dir],
1305 0, victim);
1295} 1306}
1296 1307
1297/** 1308/**
1298 * 'victim' moves onto 'trap' 1309 * 'victim' moves onto 'trap'
1299 * 'victim' leaves 'trap' 1310 * 'victim' leaves 'trap'
1313 return; 1324 return;
1314 1325
1315 /* move_apply() is the most likely candidate for causing unwanted and 1326 /* move_apply() is the most likely candidate for causing unwanted and
1316 * possibly unlimited recursion. 1327 * possibly unlimited recursion.
1317 */ 1328 */
1318 /* The following was changed because it was causing perfeclty correct 1329 /* The following was changed because it was causing perfectly correct
1319 * maps to fail. 1) it's not an error to recurse: 1330 * maps to fail. 1) it's not an error to recurse:
1320 * rune detonates, summoning monster. monster lands on nearby rune. 1331 * rune detonates, summoning monster. monster lands on nearby rune.
1321 * nearby rune detonates. This sort of recursion is expected and 1332 * nearby rune detonates. This sort of recursion is expected and
1322 * proper. This code was causing needless crashes. 1333 * proper. This code was causing needless crashes.
1323 */ 1334 */
1330 1341
1331 recursion_depth++; 1342 recursion_depth++;
1332 if (trap->head) 1343 if (trap->head)
1333 trap = trap->head; 1344 trap = trap->head;
1334 1345
1335 if (INVOKE_OBJECT (MOVE_TRIGGER, trap, ARG_OBJECT (victim), ARG_OBJECT (originator))) 1346 if (!INVOKE_OBJECT (MOVE_TRIGGER, trap, ARG_OBJECT (victim), ARG_OBJECT (originator)))
1336 goto leave;
1337
1338 switch (trap->type) 1347 switch (trap->type)
1339 { 1348 {
1340 case PLAYERMOVER: 1349 case PLAYERMOVER:
1341 if (trap->attacktype && (trap->level || victim->type != PLAYER) && !should_director_abort (trap, victim)) 1350 if (trap->attacktype && (trap->level || victim->type != PLAYER) && !should_director_abort (trap, victim))
1351 {
1352 if (!trap->stats.maxsp)
1353 trap->stats.maxsp = 2;
1354
1355 /* Is this correct? From the docs, it doesn't look like it
1356 * should be divided by trap->speed
1357 */
1358 victim->speed_left = -trap->stats.maxsp * victim->speed / trap->speed;
1359
1360 /* Just put in some sanity check. I think there is a bug in the
1361 * above with some objects have zero speed, and thus the player
1362 * getting permanently paralyzed.
1363 */
1364 if (victim->speed_left < -50.f)
1365 victim->speed_left = -50.f;
1366 /* LOG(llevDebug, "apply, playermove, player speed_left=%f\n", victim->speed_left); */
1367 }
1368 break;
1369
1370 case SPINNER:
1371 if (victim->direction)
1372 {
1373 victim->direction = absdir (victim->direction - trap->stats.sp);
1374 update_turn_face (victim);
1375 }
1376 break;
1377
1378 case DIRECTOR:
1379 if (victim->direction && !should_director_abort (trap, victim))
1380 {
1381 victim->direction = trap->stats.sp;
1382 update_turn_face (victim);
1383 }
1384 break;
1385
1386 case BUTTON:
1387 case PEDESTAL:
1388 case T_MATCH:
1389 update_button (trap, originator);
1390 break;
1391
1392 case ALTAR:
1393 /* sacrifice victim on trap */
1394 apply_altar (trap, victim, originator);
1395 break;
1396
1397 case THROWN_OBJ:
1398 if (trap->inv == NULL)
1399 break;
1400 /* fallthrough */
1401
1402 case ARROW:
1403 /* bad bug: monster throw a object, make a step forwards, step on object ,
1404 * trigger this here and get hit by own missile - and will be own enemy.
1405 * Victim then is his own enemy and will start to kill herself (this is
1406 * removed) but we have not synced victim and his missile. To avoid senseless
1407 * action, we avoid hits here
1408 */
1409 if ((QUERY_FLAG (victim, FLAG_ALIVE) && trap->has_active_speed ())
1410 && trap->owner != victim)
1411 hit_with_arrow (trap, victim);
1412 break;
1413
1414 case SPELL_EFFECT:
1415 apply_spell_effect (trap, victim);
1416 break;
1417
1418 case TRAPDOOR:
1342 { 1419 {
1420 int max, sound_was_played;
1421 object *ab, *ab_next;
1422
1343 if (!trap->stats.maxsp) 1423 if (!trap->value)
1344 trap->stats.maxsp = 2; 1424 {
1425 int tot;
1345 1426
1346 /* Is this correct? From the docs, it doesn't look like it 1427 for (ab = trap->above, tot = 0; ab; ab = ab->above)
1347 * should be divided by trap->speed 1428 if ((ab->move_type && trap->move_on) || ab->move_type == 0)
1429 tot += ab->head_ ()->total_weight ();
1430
1431 if (!(trap->value = (tot > trap->weight) ? 1 : 0))
1432 break;
1433
1434 SET_ANIMATION (trap, trap->value);
1435 update_object (trap, UP_OBJ_FACE);
1436 }
1437
1438 for (ab = trap->above, max = 100, sound_was_played = 0; --max && ab; ab = ab_next)
1439 {
1440 /* need to set this up, since if we do transfer the object,
1441 * ab->above would be bogus
1348 */ 1442 */
1349 victim->speed_left = -FABS (trap->stats.maxsp * victim->speed / trap->speed); 1443 ab_next = ab->above;
1350 1444
1351 /* Just put in some sanity check. I think there is a bug in the 1445 if ((ab->move_type && trap->move_on) || ab->move_type == 0)
1352 * above with some objects have zero speed, and thus the player 1446 {
1353 * getting permanently paralyzed. 1447 if (!sound_was_played)
1448 {
1449 trap->play_sound (trap->sound ? trap->sound : sound_find ("fall_hole"));
1450 sound_was_played = 1;
1451 }
1452
1453 ab->statusmsg ("You fall into a trapdoor!", NDI_RED);
1454 transfer_ob (ab, EXIT_X (trap), EXIT_Y (trap), 0, ab);
1455 }
1354 */ 1456 }
1355 if (victim->speed_left < -50.f) 1457 break;
1356 victim->speed_left = -50.f;
1357 /* LOG(llevDebug, "apply, playermove, player speed_left=%f\n", victim->speed_left); */
1358 } 1458 }
1359 goto leave;
1360 1459
1361 case SPINNER: 1460 case CONVERTER:
1362 if (victim->direction) 1461 if (convert_item (victim, trap) < 0)
1363 {
1364 victim->direction = absdir (victim->direction - trap->stats.sp);
1365 update_turn_face (victim);
1366 }
1367 goto leave;
1368
1369 case DIRECTOR:
1370 if (victim->direction && !should_director_abort (trap, victim))
1371 {
1372 victim->direction = trap->stats.sp;
1373 update_turn_face (victim);
1374 }
1375 goto leave;
1376
1377 case BUTTON:
1378 case PEDESTAL:
1379 update_button (trap);
1380 goto leave;
1381
1382 case ALTAR:
1383 /* sacrifice victim on trap */
1384 apply_altar (trap, victim, originator);
1385 goto leave;
1386
1387 case THROWN_OBJ:
1388 if (trap->inv == NULL)
1389 goto leave;
1390 /* fallthrough */
1391
1392 case ARROW:
1393 /* bad bug: monster throw a object, make a step forwards, step on object ,
1394 * trigger this here and get hit by own missile - and will be own enemy.
1395 * Victim then is his own enemy and will start to kill herself (this is
1396 * removed) but we have not synced victim and his missile. To avoid senseless
1397 * action, we avoid hits here
1398 */
1399 if ((QUERY_FLAG (victim, FLAG_ALIVE) && trap->speed) && trap->owner != victim)
1400 hit_with_arrow (trap, victim);
1401 goto leave;
1402
1403 case SPELL_EFFECT:
1404 apply_spell_effect (trap, victim);
1405 goto leave;
1406
1407 case TRAPDOOR:
1408 {
1409 int max, sound_was_played;
1410 object *ab, *ab_next;
1411
1412 if (!trap->value)
1413 { 1462 {
1414 int tot; 1463 originator->failmsg (format ("The %s seems to be broken!", query_name (trap)));
1415 1464 archetype::get (shstr_burnout)->insert_at (trap, trap);
1416 for (ab = trap->above, tot = 0; ab != NULL; ab = ab->above)
1417 if ((ab->move_type && trap->move_on) || ab->move_type == 0)
1418 tot += (ab->nrof ? ab->nrof : 1) * ab->weight + ab->carrying;
1419
1420 if (!(trap->value = (tot > trap->weight) ? 1 : 0))
1421 goto leave;
1422
1423 SET_ANIMATION (trap, trap->value);
1424 update_object (trap, UP_OBJ_FACE);
1425 } 1465 }
1426 1466
1427 for (ab = trap->above, max = 100, sound_was_played = 0; --max && ab; ab = ab_next) 1467 break;
1468
1469 case TRIGGER_BUTTON:
1470 case TRIGGER_PEDESTAL:
1471 case TRIGGER_ALTAR:
1472 check_trigger (trap, victim, originator);
1473 break;
1474
1475 case DEEP_SWAMP:
1476 walk_on_deep_swamp (trap, victim);
1477 break;
1478
1479 case CHECK_INV:
1480 check_inv (victim, trap);
1481 break;
1482
1483 case HOLE:
1484 move_apply_hole (trap, victim);
1485 break;
1486
1487 case EXIT:
1488 if (victim->type == PLAYER && EXIT_PATH (trap))
1428 { 1489 {
1429 /* need to set this up, since if we do transfer the object, 1490 /* Basically, don't show exits leading to random maps the
1430 * ab->above would be bogus 1491 * players output.
1431 */ 1492 */
1432 ab_next = ab->above; 1493 if (trap->msg && EXIT_PATH (trap) != shstr_random_map_exit)
1494 victim->statusmsg (trap->msg, NDI_NAVY);
1433 1495
1434 if ((ab->move_type && trap->move_on) || ab->move_type == 0) 1496 trap->play_sound (trap->sound);
1435 { 1497 victim->enter_exit (trap);
1436 if (!sound_was_played)
1437 {
1438 trap->play_sound (sound_find ("fall_hole"));
1439 sound_was_played = 1;
1440 }
1441
1442 new_draw_info (NDI_UNIQUE, 0, ab, "You fall into a trapdoor!");
1443 transfer_ob (ab, (int) EXIT_X (trap), (int) EXIT_Y (trap), 0, ab);
1444 }
1445 } 1498 }
1446 goto leave; 1499 break;
1447 }
1448 1500
1449
1450 case CONVERTER:
1451 if (convert_item (victim, trap) < 0)
1452 {
1453 new_draw_info_format (NDI_UNIQUE, 0, originator, "The %s seems to be broken!", query_name (trap));
1454 get_archetype ("burnout")->insert_at (trap, trap);
1455 }
1456
1457 goto leave;
1458
1459 case TRIGGER_BUTTON:
1460 case TRIGGER_PEDESTAL:
1461 case TRIGGER_ALTAR:
1462 check_trigger (trap, victim);
1463 goto leave;
1464
1465 case DEEP_SWAMP:
1466 walk_on_deep_swamp (trap, victim);
1467 goto leave;
1468
1469 case CHECK_INV:
1470 check_inv (victim, trap);
1471 goto leave;
1472
1473 case HOLE:
1474 /* Hole not open? */
1475 if (trap->stats.wc > 0)
1476 goto leave;
1477
1478 /* Is this a multipart monster and not the head? If so, return.
1479 * Processing will happen if the head runs into the pit
1480 */
1481 if (victim->head)
1482 goto leave;
1483
1484 victim->play_sound (sound_find ("fall_hole"));
1485 new_draw_info (NDI_UNIQUE, 0, victim, "You fall through the hole!\n");
1486 transfer_ob (victim, EXIT_X (trap), EXIT_Y (trap), 1, victim);
1487 goto leave;
1488
1489 case EXIT:
1490 if (victim->type == PLAYER && EXIT_PATH (trap))
1491 {
1492 /* Basically, don't show exits leading to random maps the
1493 * players output.
1494 */
1495 if (trap->msg && strncmp (EXIT_PATH (trap), "/!", 2))
1496 new_draw_info (NDI_NAVY, 0, victim, trap->msg);
1497
1498 victim->enter_exit (trap);
1499 }
1500 goto leave;
1501
1502 case ENCOUNTER: 1501 case ENCOUNTER:
1503 /* may be some leftovers on this */ 1502 /* may be some leftovers on this */
1504 goto leave; 1503 break;
1505 1504
1506 case SHOP_MAT: 1505 case SHOP_MAT:
1507 apply_shop_mat (trap, victim); 1506 apply_shop_mat (trap, victim);
1508 goto leave; 1507 break;
1509 1508
1510 /* Drop a certain amount of gold, and have one item identified */ 1509 /* Drop a certain amount of gold, and have one item identified */
1511 case IDENTIFY_ALTAR: 1510 case IDENTIFY_ALTAR:
1512 apply_id_altar (victim, trap, originator); 1511 apply_id_altar (victim, trap, originator);
1513 goto leave; 1512 break;
1514 1513
1515 case SIGN: 1514 case SIGN:
1516 if (victim->type != PLAYER && trap->stats.food > 0) 1515 if (victim->type != PLAYER && trap->stats.food > 0)
1517 goto leave; /* monsters musn't apply magic_mouths with counters */ 1516 break; /* monsters musn't apply magic_mouths with counters */
1518 1517
1519 apply_sign (victim, trap, 1); 1518 apply_sign (victim, trap, 1);
1520 goto leave; 1519 break;
1521 1520
1522 case CONTAINER: 1521 case CONTAINER:
1523 apply_container (victim, trap); 1522 apply_container (victim, trap);
1524 goto leave; 1523 break;
1525 1524
1526 case RUNE: 1525 case RUNE:
1527 case TRAP: 1526 case TRAP:
1528 if (trap->level && QUERY_FLAG (victim, FLAG_ALIVE)) 1527 if (trap->level && QUERY_FLAG (victim, FLAG_ALIVE))
1529 {
1530 spring_trap (trap, victim); 1528 spring_trap (trap, victim);
1531 } 1529 break;
1532 goto leave;
1533 1530
1534 default: 1531 default:
1535 LOG (llevDebug, "name %s, arch %s, type %d with fly/walk on/off not " 1532 LOG (llevDebug, "name %s, arch %s, type %d with fly/walk on/off not "
1536 "handled in move_apply()\n", &trap->name, &trap->arch->archname, trap->type); 1533 "handled in move_apply()\n", &trap->name, &trap->arch->archname, trap->type);
1537 goto leave; 1534 break;
1538 } 1535 }
1539 1536
1540leave:
1541 recursion_depth--; 1537 recursion_depth--;
1542} 1538}
1543 1539
1544/** 1540/**
1545 * Handles reading a regular (ie not containing a spell) book. 1541 * Handles reading a regular (ie not containing a spell) book.
1550 int lev_diff; 1546 int lev_diff;
1551 object *skill_ob; 1547 object *skill_ob;
1552 1548
1553 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ)) 1549 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ))
1554 { 1550 {
1555 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind."); 1551 op->failmsg ("You are unable to read while blind!");
1556 return; 1552 return;
1557 } 1553 }
1558 1554
1559 if (!tmp->msg) 1555 if (!tmp->msg)
1560 { 1556 {
1561 new_draw_info_format (NDI_UNIQUE, 0, op, "You open the %s and find it empty.", &tmp->name); 1557 op->failmsg (format ("The %s contains nothing but meaningless gibberish. H<There is nothing interesting to read here.>", &tmp->name));
1562 return; 1558 return;
1563 } 1559 }
1564 1560
1565 /* need a literacy skill to read stuff! */ 1561 /* need a literacy skill to read stuff! */
1566 skill_ob = find_skill_by_name (op, tmp->skill); 1562 skill_ob = find_skill_by_name (op, tmp->skill);
1567 if (!skill_ob) 1563 if (!skill_ob)
1568 { 1564 {
1569 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. H<You lack the skill to read this>"); 1565 op->failmsg (format ("You are unable to decipher the strange symbols. H<You lack the %s skill to read this.>", &tmp->skill));
1570 return; 1566 return;
1571 } 1567 }
1572 1568
1573 lev_diff = tmp->level - (skill_ob->level + 5); 1569 lev_diff = tmp->level - (skill_ob->level + 5);
1574 if (!QUERY_FLAG (op, FLAG_WIZ) && lev_diff > 0) 1570 if (!QUERY_FLAG (op, FLAG_WIZ) && lev_diff > 0)
1575 { 1571 {
1576 if (lev_diff < 2) 1572 op->failmsg (lev_diff < 2 ? "This book is just barely beyond your comprehension."
1577 new_draw_info (NDI_UNIQUE, 0, op, "This book is just barely beyond your comprehension."); 1573 : lev_diff < 3 ? "This book is slightly beyond your comprehension."
1578 else if (lev_diff < 3) 1574 : lev_diff < 5 ? "This book is beyond your comprehension."
1579 new_draw_info (NDI_UNIQUE, 0, op, "This book is slightly beyond your comprehension."); 1575 : lev_diff < 8 ? "This book is quite a bit beyond your comprehension."
1580 else if (lev_diff < 5) 1576 : lev_diff < 15 ? "This book is way beyond your comprehension."
1581 new_draw_info (NDI_UNIQUE, 0, op, "This book is beyond your comprehension."); 1577 : "This book is totally beyond your comprehension.");
1582 else if (lev_diff < 8)
1583 new_draw_info (NDI_UNIQUE, 0, op, "This book is quite a bit beyond your comprehension.");
1584 else if (lev_diff < 15)
1585 new_draw_info (NDI_UNIQUE, 0, op, "This book is way beyond your comprehension.");
1586 else
1587 new_draw_info (NDI_UNIQUE, 0, op, "This book is totally beyond your comprehension.");
1588 return; 1578 return;
1589 } 1579 }
1590 1580
1581 // we currently don't use the message types for anything.
1591 readable_message_type *msgType = get_readable_message_type (tmp); 1582 // readable_message_type *msgType = get_readable_message_type (tmp);
1583
1584 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("apply_book"));
1592 1585
1593 if (player *pl = op->contr) 1586 if (player *pl = op->contr)
1594 if (client *ns = pl->ns) 1587 if (client *ns = pl->ns)
1595 if (ns->can_msg) 1588 pl->infobox (MSG_CHANNEL ("book"), format ("T<%s>\n\n%s", (char *)long_desc (tmp, op), &tmp->msg));
1596 {
1597 dynbuf_text buf;
1598 buf << long_desc (tmp, op)
1599 << "\n\n"
1600 << tmp->msg
1601 << '\0';
1602 ns->send_msg (NDI_NAVY, msgType->msgtype, buf.linearise ());
1603 }
1604 else
1605 draw_ext_info_format (NDI_UNIQUE | NDI_NAVY, 0, op,
1606 msgType->message_type, msgType->message_subtype,
1607 "You open the %s and start reading.\n%s", (char *)"%s\n%s",
1608 long_desc (tmp, op), &tmp->msg);
1609 1589
1610 /* gain xp from reading */ 1590 /* gain xp from reading */
1611 if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT)) 1591 if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT))
1612 { /* only if not read before */ 1592 { /* only if not read before */
1613 int exp_gain = calc_skill_exp (op, tmp, skill_ob); 1593 int exp_gain = calc_skill_exp (op, tmp, skill_ob);
1615 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1595 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1616 { 1596 {
1617 /*exp_gain *= 2; because they just identified it too */ 1597 /*exp_gain *= 2; because they just identified it too */
1618 SET_FLAG (tmp, FLAG_IDENTIFIED); 1598 SET_FLAG (tmp, FLAG_IDENTIFIED);
1619 1599
1620 /* If in a container, update how it looks */ 1600 if (object *pl = tmp->visible_to ())
1621 if (tmp->env)
1622 esrv_update_item (UPD_FLAGS | UPD_NAME, op, tmp); 1601 esrv_update_item (UPD_FLAGS | UPD_NAME, pl, tmp);
1623 else
1624 op->contr->ns->floorbox_update ();
1625 } 1602 }
1626 1603
1627 change_exp (op, exp_gain, skill_ob->skill, 0); 1604 change_exp (op, exp_gain, skill_ob->skill, 0);
1628 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */ 1605 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */
1629 } 1606 }
1630} 1607}
1631 1608
1632/** 1609/**
1610 * op made some mistake with a scroll, this takes care of punishment.
1611 * scroll_failure()- hacked directly from spell_failure
1612 */
1613static void
1614scroll_failure (object *op, int failure, int power)
1615{
1616 if (abs (failure / 4) > power)
1617 power = abs (failure / 4); /* set minimum effect */
1618
1619 if (failure <= -1 && failure > -15)
1620 { /* wonder */
1621 object *tmp;
1622
1623 op->failmsg ("Your spell warps!");
1624 tmp = get_archetype (SPELL_WONDER);
1625 cast_wonder (op, op, 0, tmp);
1626 tmp->destroy ();
1627 }
1628 else if (failure <= -15 && failure > -35)
1629 { /* drain mana */
1630 op->failmsg ("Your mana is drained!");
1631 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW);
1632 if (op->stats.sp < 0)
1633 op->stats.sp = 0;
1634 }
1635 else if (settings.spell_failure_effects == TRUE)
1636 {
1637 if (failure <= -35 && failure > -60)
1638 { /* confusion */
1639 op->failmsg ("The magic recoils on you!");
1640 confuse_player (op, op, power);
1641 }
1642 else if (failure <= -60 && failure > -70)
1643 { /* paralysis */
1644 op->failmsg ("The magic recoils and paralyzes you!");
1645 paralyze_player (op, op, power);
1646 }
1647 else if (failure <= -70 && failure > -80)
1648 { /* blind */
1649 op->failmsg ("The magic recoils on you!");
1650 blind_player (op, op, power);
1651 }
1652 else if (failure <= -80)
1653 { /* blast the immediate area */
1654 object *tmp = get_archetype (LOOSE_MANA);
1655 cast_magic_storm (op, tmp, power);
1656 op->failmsg ("You unleash uncontrolled mana!");
1657 tmp->destroy ();
1658 }
1659 }
1660}
1661
1662/**
1633 * Handles the applying of a skill scroll, calling learn_skill straight. 1663 * Handles the applying of a skill scroll, calling learn_skill straight.
1634 * op is the person learning the skill, tmp is the skill scroll object 1664 * op is the person learning the skill, tmp is the skill scroll object
1635 */ 1665 */
1636static void 1666static void
1637apply_skillscroll (object *op, object *tmp) 1667apply_skillscroll (object *op, object *tmp)
1638{ 1668{
1639 switch ((int) learn_skill (op, tmp)) 1669 switch (learn_skill (op, tmp))
1640 { 1670 {
1641 case 0: 1671 case 0:
1642 new_draw_info (NDI_UNIQUE, 0, op, "You already possess the knowledge "); 1672 op->play_sound (sound_find ("generic_fail"));
1643 new_draw_info_format (NDI_UNIQUE, 0, op, "held within the %s.\n", query_name (tmp)); 1673 op->failmsg (format ("You already possess the knowledge held within the %s.", query_name (tmp)));
1644 return; 1674 break;
1645 1675
1646 case 1: 1676 case 1:
1647 new_draw_info_format (NDI_UNIQUE, 0, op, "You succeed in learning %s", &tmp->skill);
1648 decrease_ob (tmp); 1677 tmp->decrease ();
1678 op->play_sound (sound_find ("skill_learn"));
1679 op->statusmsg (format ("You succeed in learning %s", &tmp->skill));
1649 return; 1680 break;
1650 1681
1651 default: 1682 default:
1683 tmp->decrease ();
1684 op->play_sound (sound_find ("generic_fail"));
1652 new_draw_info_format (NDI_UNIQUE, 0, op, "You fail to learn the knowledge of the %s.\n", query_name (tmp)); 1685 op->failmsg (format ("You fail to learn the knowledge of the %s.\n", query_name (tmp)));
1653 decrease_ob (tmp);
1654 return; 1686 break;
1655 } 1687 }
1656} 1688}
1657 1689
1658/** 1690/**
1659 * Actually makes op learn spell. 1691 * Actually makes op learn spell.
1709 { 1741 {
1710 LOG (llevError, "BUG: do_forget_spell(): spell not known\n"); 1742 LOG (llevError, "BUG: do_forget_spell(): spell not known\n");
1711 return; 1743 return;
1712 } 1744 }
1713 1745
1714 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", spell); 1746 op->failmsg (format ("You lose knowledge of %s.", spell));
1715 player_unready_range_ob (op->contr, spob); 1747 player_unready_range_ob (op->contr, spob);
1716 esrv_remove_spell (op->contr, spob); 1748 esrv_remove_spell (op->contr, spob);
1717 spob->destroy (); 1749 spob->destroy ();
1718} 1750}
1719 1751
1727{ 1759{
1728 object *skop, *spell, *spell_skill; 1760 object *skop, *spell, *spell_skill;
1729 1761
1730 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ)) 1762 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ))
1731 { 1763 {
1732 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind."); 1764 op->failmsg ("You are unable to read while blind.");
1733 return; 1765 return;
1734 } 1766 }
1735 1767
1736 /* artifact_spellbooks have 'slaying' field point to a spell name, 1768 /* artifact_spellbooks have 'slaying' field point to a spell name,
1737 * instead of having their spell stored in stats.sp. These are 1769 * instead of having their spell stored in stats.sp. These are
1738 * legacy spellbooks 1770 * legacy spellbooks
1739 */ 1771 */
1740 if (tmp->slaying) 1772 if (tmp->slaying)
1741 { 1773 {
1742 spell = arch_to_object (find_archetype_by_object_name (tmp->slaying)); 1774 spell = find_archetype_by_object_name (tmp->slaying)->instance ();
1775
1743 if (!spell) 1776 if (!spell)
1744 { 1777 {
1745 new_draw_info_format (NDI_UNIQUE, 0, op, "The book's formula for %s is incomplete", &tmp->slaying); 1778 op->failmsg (format ("The book's formula for %s is incomplete.", &tmp->slaying));
1746 return; 1779 return;
1747 } 1780 }
1748 else 1781 else
1749 insert_ob_in_ob (spell, tmp); 1782 insert_ob_in_ob (spell, tmp);
1750 1783
1755 1788
1756 /* need a literacy skill to learn spells. Also, having a literacy level 1789 /* need a literacy skill to learn spells. Also, having a literacy level
1757 * lower than the spell will make learning the spell more difficult */ 1790 * lower than the spell will make learning the spell more difficult */
1758 if (!skop) 1791 if (!skop)
1759 { 1792 {
1760 new_draw_info (NDI_UNIQUE, 0, op, "You can't read! Your attempt fails. H<You lack the literacy skill.>"); 1793 op->failmsg (format ("You can't read! Your attempt fails. H<You lack the %s skill.>", &tmp->skill));
1761 return; 1794 return;
1762 } 1795 }
1763 1796
1764 spell = tmp->inv; 1797 spell = tmp->inv;
1765 1798
1766 if (!spell) 1799 if (!spell)
1767 { 1800 {
1768 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name); 1801 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name);
1769 new_draw_info (NDI_UNIQUE, 0, op, "The spellbook symbols make no sense. This is a bug, please report!"); 1802 op->failmsg ("The spellbook symbols make no sense. This is a bug, please report!");
1770 return; 1803 return;
1771 } 1804 }
1772 1805
1773 if (skop->level < int (sqrtf (spell->level) * 1.5f)) 1806 int learn_level = sqrtf (spell->level) * 1.5f;
1807 if (skop->level < learn_level)
1774 { 1808 {
1775 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. H<Your literacy level is too low.>"); 1809 op->failmsg (format ("You are unable to decipher the strange symbols. H<Your %s level is too low, it must be at least %d.>",
1810 &tmp->skill, learn_level));
1776 return; 1811 return;
1777 } 1812 }
1778 1813
1779 new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name); 1814 op->statusmsg (format ("The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name));
1780 1815
1781 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1816 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1782 {
1783 identify (tmp); 1817 identify (tmp);
1784
1785 if (tmp->env)
1786 esrv_update_item (UPD_FLAGS | UPD_NAME, op, tmp);
1787 else
1788 op->contr->ns->floorbox_update ();
1789 }
1790 1818
1791 /* I removed the check for special_prayer_mark here - it didn't make 1819 /* I removed the check for special_prayer_mark here - it didn't make
1792 * a lot of sense - special prayers are not found in spellbooks, and 1820 * a lot of sense - special prayers are not found in spellbooks, and
1793 * if the player doesn't know the spell, doesn't make a lot of sense that 1821 * if the player doesn't know the spell, doesn't make a lot of sense that
1794 * they would have a special prayer mark. 1822 * they would have a special prayer mark.
1795 */ 1823 */
1796 if (check_spell_known (op, spell->name)) 1824 if (check_spell_known (op, spell->name))
1797 { 1825 {
1798 new_draw_info (NDI_UNIQUE, 0, op, "You already know that spell. H<It makes no sense to learn spells twice, and would only waste the spellbook.>\n"); 1826 op->statusmsg ("You already know that spell. H<It makes no sense to learn spells twice, and would only waste the spellbook.>\n");
1799 return; 1827 return;
1800 } 1828 }
1801 1829
1802 if (spell->skill) 1830 if (spell->skill)
1803 { 1831 {
1804 spell_skill = find_skill_by_name (op, spell->skill); 1832 spell_skill = find_skill_by_name (op, spell->skill);
1805 1833
1806 if (!spell_skill) 1834 if (!spell_skill)
1807 { 1835 {
1808 new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the skill %s to use this spell.", &spell->skill); 1836 op->failmsg (format ("You lack the skill %s to use this spell.", &spell->skill));
1809 return; 1837 return;
1810 } 1838 }
1811 1839
1812 if (spell_skill->level < spell->level) 1840 if (spell_skill->level < spell->level)
1813 { 1841 {
1814 new_draw_info_format (NDI_UNIQUE, 0, op, "You need to be level %d in %s to learn this spell.", spell->level, &spell->skill); 1842 op->failmsg (format ("You need to be level %d in %s to learn this spell.", spell->level, &spell->skill));
1815 return; 1843 return;
1816 } 1844 }
1817 } 1845 }
1818 1846
1819 /* Logic as follows 1847 /* Logic as follows
1828 * Overall, chances are the same but a player will find having a high 1856 * Overall, chances are the same but a player will find having a high
1829 * literacy rate very useful! -b.t. 1857 * literacy rate very useful! -b.t.
1830 */ 1858 */
1831 if (QUERY_FLAG (op, FLAG_CONFUSED)) 1859 if (QUERY_FLAG (op, FLAG_CONFUSED))
1832 { 1860 {
1833 new_draw_info (NDI_UNIQUE, 0, op, "In your confused state you flub the wording of the text!"); 1861 op->failmsg ("In your confused state you flub the wording of the text!");
1834 scroll_failure (op, 0 - random_roll (0, spell->level, op, PREFER_LOW), MAX (spell->stats.sp, spell->stats.grace)); 1862 scroll_failure (op, 0 - random_roll (0, spell->level, op, PREFER_LOW), max (spell->stats.sp, spell->stats.grace));
1835 } 1863 }
1836 else if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || 1864 else if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) ||
1837 (random_roll (0, 100, op, PREFER_LOW) - (5 * skop->level)) < learn_spell[spell->stats.grace ? op->stats.Wis : op->stats.Int]) 1865 (random_roll (0, 100, op, PREFER_LOW) - (5 * skop->level)) < learn_spell[spell->stats.grace ? op->stats.Wis : op->stats.Int])
1838 { 1866 {
1839 1867 op->statusmsg ("You succeed in learning the spell!", NDI_GREEN);
1840 new_draw_info (NDI_UNIQUE, 0, op, "You succeed in learning the spell!");
1841 do_learn_spell (op, spell, 0); 1868 do_learn_spell (op, spell, 0);
1842 1869
1843 /* xp gain to literacy for spell learning */ 1870 /* xp gain to literacy for spell learning */
1844 if (!QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 1871 if (!QUERY_FLAG (tmp, FLAG_STARTEQUIP))
1845 change_exp (op, calc_skill_exp (op, tmp, skop), skop->skill, 0); 1872 change_exp (op, calc_skill_exp (op, tmp, skop), skop->skill, 0);
1846 } 1873 }
1847 else 1874 else
1848 { 1875 {
1849 op->contr->play_sound (sound_find ("fumble_spell")); 1876 op->contr->play_sound (sound_find ("fumble_spell"));
1850 new_draw_info (NDI_UNIQUE, 0, op, "You fail to learn the spell. H<Wis (priests) or Int (wizards) governs the chance of learning a prayer or spell.>\n"); 1877 op->failmsg ("You fail to learn the spell. H<Wis (priests) or Int (wizards) governs the chance of learning a prayer or spell.>\n");
1851 } 1878 }
1852 1879
1853 decrease_ob (tmp); 1880 tmp->decrease ();
1854} 1881}
1855 1882
1856/** 1883/**
1857 * Handles applying a spell scroll. 1884 * Handles applying a spell scroll.
1858 */ 1885 */
1861{ 1888{
1862 object *skop; 1889 object *skop;
1863 1890
1864 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ)) 1891 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ))
1865 { 1892 {
1866 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind."); 1893 op->failmsg ("You are unable to read while blind.");
1867 return; 1894 return;
1868 } 1895 }
1869 1896
1870 if (!tmp->inv || tmp->inv->type != SPELL) 1897 if (!tmp->inv || tmp->inv->type != SPELL)
1871 { 1898 {
1872 new_draw_info (NDI_UNIQUE, 0, op, "The scroll just doesn't make sense! H<...and never will make sense.>"); 1899 op->failmsg ("The scroll just doesn't make sense! H<...and never will make sense.>");
1873 return; 1900 return;
1874 } 1901 }
1875 1902
1876 if (op->type == PLAYER) 1903 if (op->type == PLAYER)
1877 { 1904 {
1883 */ 1910 */
1884 skop = find_skill_by_name (op, skill_names[SK_LITERACY]); 1911 skop = find_skill_by_name (op, skill_names[SK_LITERACY]);
1885 1912
1886 if (!skop) 1913 if (!skop)
1887 { 1914 {
1888 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. H<You lack the literacy skill.>"); 1915 op->failmsg (format ("You are unable to decipher the strange symbols. H<You lack the %s skill.>", &skill_names[SK_LITERACY]));
1889 return; 1916 return;
1890 } 1917 }
1891 1918
1892 if ((exp_gain = calc_skill_exp (op, tmp, skop))) 1919 if ((exp_gain = calc_skill_exp (op, tmp, skop)))
1893 change_exp (op, exp_gain, skop->skill, 0); 1920 change_exp (op, exp_gain, skop->skill, 0);
1894 } 1921 }
1895 1922
1896 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1923 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1897 identify (tmp); 1924 identify (tmp);
1898 1925
1899 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name); 1926 op->statusmsg (format ("The scroll of %s turns to dust.", &tmp->inv->name));
1900 1927
1901 cast_spell (op, tmp, dir, tmp->inv, NULL); 1928 cast_spell (op, tmp, dir, tmp->inv, NULL);
1902 decrease_ob (tmp); 1929 tmp->decrease ();
1903} 1930}
1904 1931
1905/** 1932/**
1906 * Applies a treasure object - by default, chest. op 1933 * Applies a treasure object - by default, chest. op
1907 * is the person doing the applying, tmp is the treasure 1934 * is the person doing the applying, tmp is the treasure
1908 * chest. 1935 * chest.
1909 */ 1936 */
1910static void 1937static void
1911apply_treasure (object *op, object *tmp) 1938apply_treasure (object *op, object *tmp)
1912{ 1939{
1913 /* Nice side effect of new treasure creation method is that the treasure 1940 /* Nice side effect of this treasure creation method is that the treasure
1914 * for the chest is done when the chest is created, and put into the chest 1941 * for the chest is done when the chest is created, and put into the chest
1915 * inventory. So that when the chest burns up, the items still exist. Also 1942 * inventory. So that when the chest burns up, the items still exist. Also
1916 * prevents people fromt moving chests to more difficult maps to get better 1943 * prevents people from moving chests to more difficult maps to get better
1917 * treasure 1944 * treasure
1918 */ 1945 */
1919 object *treas = tmp->inv; 1946 object *treas = tmp->inv;
1920 1947
1921 if (!treas) 1948 if (!treas)
1922 { 1949 {
1923 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty."); 1950 op->statusmsg ("The chest was empty.");
1924 decrease_ob (tmp); 1951 tmp->decrease ();
1925 return; 1952 return;
1926 } 1953 }
1927 1954
1928 while (tmp->inv) 1955 while (tmp->inv)
1929 { 1956 {
1930 treas = tmp->inv; 1957 treas = tmp->inv;
1931
1932 treas->remove (); 1958 treas->remove ();
1933 new_draw_info_format (NDI_UNIQUE, 0, op, "You find %s in the chest.", query_name (treas));
1934 1959
1935 treas->x = op->x; 1960 treas->x = op->x;
1936 treas->y = op->y; 1961 treas->y = op->y;
1937 treas = insert_ob_in_map (treas, op->map, op, INS_BELOW_ORIGINATOR); 1962 treas = insert_ob_in_map (treas, op->map, op, INS_BELOW_ORIGINATOR);
1938 1963
1939 if (treas && (treas->type == RUNE || treas->type == TRAP) && treas->level && QUERY_FLAG (op, FLAG_ALIVE)) 1964 if (treas && (treas->type == RUNE || treas->type == TRAP) && treas->level && QUERY_FLAG (op, FLAG_ALIVE))
1940 spring_trap (treas, op); 1965 spring_trap (treas, op);
1941 1966
1942 /* If either player or container was destroyed, no need to do 1967 /* If either player or container was destroyed, no need to do
1943 * further processing. I think this should be enclused with 1968 * further processing. I think this should be enclused with
1944 * spring trap above, as I don't think there is otherwise 1969 * spring trap above, as I don't think there is otherwise
1945 * any way for the treasure chest or player to get killed 1970 * any way for the treasure chest or player to get killed.
1946 */ 1971 */
1947 if (op->destroyed () || tmp->destroyed ()) 1972 if (op->destroyed () || tmp->destroyed ())
1948 break; 1973 break;
1949 } 1974 }
1950 1975
1951 if (!tmp->destroyed () && tmp->inv == NULL) 1976 if (!tmp->destroyed () && !tmp->inv)
1952 decrease_ob (tmp); 1977 tmp->decrease (true);
1953
1954}
1955
1956/**
1957 * op eats food.
1958 * If player, takes care of messages and dragon special food.
1959 */
1960static void
1961apply_food (object *op, object *tmp)
1962{
1963 int capacity_remaining;
1964
1965 if (op->type != PLAYER)
1966 op->stats.hp = op->stats.maxhp;
1967 else
1968 {
1969 /* check if this is a dragon (player), eating some flesh */
1970 if (tmp->type == FLESH && is_dragon_pl (op) && dragon_eat_flesh (op, tmp))
1971 ;
1972 else
1973 {
1974 /* usual case - no dragon meal: */
1975 if (op->stats.food + tmp->stats.food > 999)
1976 {
1977 if (tmp->type == FOOD || tmp->type == FLESH)
1978 new_draw_info (NDI_UNIQUE, 0, op, "You feel full, but what a waste of food!");
1979 else
1980 new_draw_info (NDI_UNIQUE, 0, op, "Most of the drink goes down your face not your throat!");
1981 }
1982
1983 if (!QUERY_FLAG (tmp, FLAG_CURSED))
1984 {
1985 char buf[MAX_BUF];
1986
1987 if (!is_dragon_pl (op))
1988 {
1989 /* eating message for normal players */
1990 if (tmp->type == DRINK)
1991 sprintf (buf, "Ahhh...that %s tasted good.", &tmp->name);
1992 else
1993 sprintf (buf, "The %s tasted %s", &tmp->name, tmp->type == FLESH ? "terrible!" : "good.");
1994 }
1995 else
1996 {
1997 /* eating message for dragon players */
1998 sprintf (buf, "The %s tasted terrible!", &tmp->name);
1999 }
2000
2001 new_draw_info (NDI_UNIQUE, 0, op, buf);
2002 capacity_remaining = 999 - op->stats.food;
2003 op->stats.food += tmp->stats.food;
2004 if (capacity_remaining < tmp->stats.food)
2005 op->stats.hp += capacity_remaining / 50;
2006 else
2007 op->stats.hp += tmp->stats.food / 50;
2008 if (op->stats.hp > op->stats.maxhp)
2009 op->stats.hp = op->stats.maxhp;
2010 if (op->stats.food > 999)
2011 op->stats.food = 999;
2012 }
2013
2014 /* special food hack -b.t. */
2015 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED))
2016 eat_special_food (op, tmp);
2017 }
2018 }
2019
2020 handle_apply_yield (tmp);
2021 decrease_ob (tmp);
2022} 1978}
2023 1979
2024/** 1980/**
2025 * A dragon is eating some flesh. If the flesh contains resistances, 1981 * A dragon is eating some flesh. If the flesh contains resistances,
2026 * there is a chance for the dragon's skin to get improved. 1982 * there is a chance for the dragon's skin to get improved.
2029 * object *op the object (dragon player) eating the flesh 1985 * object *op the object (dragon player) eating the flesh
2030 * object *meal the flesh item, getting chewed in dragon's mouth 1986 * object *meal the flesh item, getting chewed in dragon's mouth
2031 * return: 1987 * return:
2032 * int 1 if eating successful, 0 if it doesn't work 1988 * int 1 if eating successful, 0 if it doesn't work
2033 */ 1989 */
2034int 1990static int
2035dragon_eat_flesh (object *op, object *meal) 1991dragon_eat_flesh (object *op, object *meal)
2036{ 1992{
2037 object *skin = NULL; /* pointer to dragon skin force */ 1993 object *skin = NULL; /* pointer to dragon skin force */
2038 object *abil = NULL; /* pointer to dragon ability force */ 1994 object *abil = NULL; /* pointer to dragon ability force */
2039 object *tmp = NULL; /* tmp. object */ 1995 object *tmp = NULL; /* tmp. object */
2040 1996
2041 char buf[MAX_BUF]; /* tmp. string buffer */
2042 double chance; /* improvement-chance of one resistance type */ 1997 double chance; /* improvement-chance of one resistance type */
2043 double totalchance = 1; /* total chance of gaining one resistance */ 1998 double totalchance = 1; /* total chance of gaining one resistance */
2044 double bonus = 0; /* level bonus (improvement is easier at lowlevel) */ 1999 double bonus = 0; /* level bonus (improvement is easier at lowlevel) */
2045 double mbonus = 0; /* monster bonus */ 2000 double mbonus = 0; /* monster bonus */
2046 int atnr_winner[NROFATTACKS]; /* winning candidates for resistance improvement */ 2001 int atnr_winner[NROFATTACKS]; /* winning candidates for resistance improvement */
2047 int winners = 0; /* number of winners */ 2002 int winners = 0; /* number of winners */
2048 int i; /* index */ 2003 int i; /* index */
2049 2004
2050 /* let's make sure and doublecheck the parameters */ 2005 /* let's make sure and doublecheck the parameters */
2051 if (meal->type != FLESH || !is_dragon_pl (op)) 2006 if (meal->type != FLESH || !op->is_dragon ())
2052 return 0; 2007 return 0;
2053 2008
2054 /* now grab the 'dragon_skin'- and 'dragon_ability'-forces 2009 /* now grab the 'dragon_skin'- and 'dragon_ability'-forces
2055 from the player's inventory */ 2010 from the player's inventory */
2056 for (tmp = op->inv; tmp; tmp = tmp->below) 2011 for (tmp = op->inv; tmp; tmp = tmp->below)
2068 /* now start by filling stomache and health, according to food-value */ 2023 /* now start by filling stomache and health, according to food-value */
2069 if ((999 - op->stats.food) < meal->stats.food) 2024 if ((999 - op->stats.food) < meal->stats.food)
2070 op->stats.hp += (999 - op->stats.food) / 50; 2025 op->stats.hp += (999 - op->stats.food) / 50;
2071 else 2026 else
2072 op->stats.hp += meal->stats.food / 50; 2027 op->stats.hp += meal->stats.food / 50;
2028
2073 if (op->stats.hp > op->stats.maxhp) 2029 if (op->stats.hp > op->stats.maxhp)
2074 op->stats.hp = op->stats.maxhp; 2030 op->stats.hp = op->stats.maxhp;
2075 2031
2076 op->stats.food = MIN (999, op->stats.food + meal->stats.food); 2032 op->stats.food = min (999, op->stats.food + meal->stats.food);
2077 2033
2078 /*LOG(llevDebug, "-> player: %d, flesh: %d\n", op->level, meal->level); */ 2034 /*LOG(llevDebug, "-> player: %d, flesh: %d\n", op->level, meal->level); */
2079 2035
2080 /* on to the interesting part: chances for adding resistance */ 2036 /* on to the interesting part: chances for adding resistance */
2081 for (i = 0; i < NROFATTACKS; i++) 2037 for (i = 0; i < NROFATTACKS; i++)
2091 2047
2092 /* monster bonus increases with level, because high-level 2048 /* monster bonus increases with level, because high-level
2093 flesh is too rare */ 2049 flesh is too rare */
2094 mbonus = op->level * 20. / ((double) settings.max_level); 2050 mbonus = op->level * 20. / ((double) settings.max_level);
2095 2051
2096 chance = (((double) MIN (op->level + bonus, meal->level + bonus + mbonus)) * 100. / 2052 chance = (((double)min (op->level + bonus, meal->level + bonus + mbonus)) * 100. /
2097 ((double) settings.max_level)) - skin->resist[i]; 2053 ((double)settings.max_level)) - skin->resist[i];
2098 2054
2099 if (chance >= 0.) 2055 if (chance >= 0.)
2100 chance += 1.; 2056 chance += 1.;
2101 else 2057 else
2102 chance = (chance < -12) ? 0. : 1. / pow (2., -chance); 2058 chance = (chance < -12) ? 0. : 1. / pow (2., -chance);
2103 2059
2104 /* chance is proportional to amount of resistance (max. 50) */ 2060 /* chance is proportional to amount of resistance (max. 50) */
2105 chance *= ((double) (MIN (meal->resist[i], 50))) / 50.; 2061 chance *= ((double)(min (meal->resist[i], 50))) / 50.;
2106 2062
2107 /* doubled chance for resistance of ability-focus */ 2063 /* doubled chance for resistance of ability-focus */
2108 if (i == abil->stats.exp) 2064 if (i == abil->stats.exp)
2109 chance = MIN (100., chance * 2.); 2065 chance = min (100., chance * 2.);
2110 2066
2111 /* now make the throw and save all winners (Don't insert luck bonus here!) */ 2067 /* now make the throw and save all winners (Don't insert luck bonus here!) */
2112 if (rndm (10000) < (unsigned int) (chance * 100)) 2068 if (rndm (10000) < (unsigned int)(chance * 100))
2113 { 2069 {
2114 atnr_winner[winners] = i; 2070 atnr_winner[winners] = i;
2115 winners++; 2071 winners++;
2116 } 2072 }
2117 2073
2122 } 2078 }
2123 } 2079 }
2124 2080
2125 /* inverse totalchance as until now we have the failure-chance */ 2081 /* inverse totalchance as until now we have the failure-chance */
2126 totalchance = 100 - totalchance * 100; 2082 totalchance = 100 - totalchance * 100;
2083
2127 /* print message according to totalchance */ 2084 /* print message according to totalchance */
2085 const char *buf;
2128 if (totalchance > 50.) 2086 if (totalchance > 50.)
2129 sprintf (buf, "Hmm! The %s tasted delicious!", &meal->name); 2087 buf = format ("Hmm! The %s tasted delicious!", &meal->name);
2130 else if (totalchance > 10.) 2088 else if (totalchance > 10.)
2131 sprintf (buf, "The %s tasted very good.", &meal->name); 2089 buf = format ("The %s tasted very good.", &meal->name);
2132 else if (totalchance > 1.) 2090 else if (totalchance > 1.)
2133 sprintf (buf, "The %s tasted good.", &meal->name); 2091 buf = format ("The %s tasted good.", &meal->name);
2134 else if (totalchance > 0.1) 2092 else if (totalchance > 0.1)
2135 sprintf (buf, "The %s tasted bland.", &meal->name); 2093 buf = format ("The %s tasted bland.", &meal->name);
2136 else if (totalchance >= 0.01) 2094 else if (totalchance >= 0.01)
2137 sprintf (buf, "The %s had a boring taste.", &meal->name); 2095 buf = format ("The %s had a boring taste.", &meal->name);
2138 else if (meal->last_eat > 0 && atnr_is_dragon_enabled (meal->last_eat)) 2096 else if (meal->last_eat > 0 && atnr_is_dragon_enabled (meal->last_eat))
2139 sprintf (buf, "The %s tasted strange.", &meal->name); 2097 buf = format ("The %s tasted strange.", &meal->name);
2140 else 2098 else
2141 sprintf (buf, "The %s had no taste.", &meal->name); 2099 buf = format ("The %s had no taste.", &meal->name);
2142 new_draw_info (NDI_UNIQUE, 0, op, buf); 2100
2101 op->statusmsg (buf);
2143 2102
2144 /* now choose a winner if we have any */ 2103 /* now choose a winner if we have any */
2145 i = -1; 2104 i = -1;
2146 if (winners > 0) 2105 if (winners > 0)
2147 i = atnr_winner[RANDOM () % winners]; 2106 i = atnr_winner [rndm (winners)];
2148 2107
2149 if (i >= 0 && i < NROFATTACKS && skin->resist[i] < 95) 2108 if (i >= 0 && i < NROFATTACKS && skin->resist[i] < 95)
2150 { 2109 {
2151 /* resistance increased! */ 2110 /* resistance increased! */
2152 skin->resist[i]++; 2111 skin->resist[i]++;
2153 op->update_stats (); 2112 op->update_stats ();
2154 2113
2155 sprintf (buf, "Your skin is now more resistant to %s!", change_resist_msg[i]); 2114 op->statusmsg (format ("Your skin is now more resistant to %s!", change_resist_msg[i]));
2156 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, buf);
2157 } 2115 }
2158 2116
2159 /* if this flesh contains a new ability focus, we mark it 2117 /* if this flesh contains a new ability focus, we mark it
2160 into the ability_force and it will take effect on next level */ 2118 into the ability_force and it will take effect on next level */
2161 if (meal->last_eat > 0 && atnr_is_dragon_enabled (meal->last_eat) && meal->last_eat != abil->last_eat) 2119 if (meal->last_eat > 0 && atnr_is_dragon_enabled (meal->last_eat) && meal->last_eat != abil->last_eat)
2162 { 2120 {
2163 abil->last_eat = meal->last_eat; /* write: last_eat <new attnr focus> */ 2121 abil->last_eat = meal->last_eat; /* write: last_eat <new attnr focus> */
2164 2122
2165 if (meal->last_eat != abil->stats.exp) 2123 if (meal->last_eat != abil->stats.exp)
2124 op->statusmsg (format (
2125 "Your metabolism prepares to focus on %s!\n"
2126 "The change will happen at level %d.",
2127 change_resist_msg[meal->last_eat],
2128 abil->level + 1
2166 { 2129 ));
2167 sprintf (buf, "Your metabolism prepares to focus on %s!", change_resist_msg[meal->last_eat]);
2168 new_draw_info (NDI_UNIQUE, 0, op, buf);
2169 sprintf (buf, "The change will happen at level %d", abil->level + 1);
2170 new_draw_info (NDI_UNIQUE, 0, op, buf);
2171 }
2172 else 2130 else
2173 { 2131 {
2174 sprintf (buf, "Your metabolism will continue to focus on %s.", change_resist_msg[meal->last_eat]); 2132 op->statusmsg (format ("Your metabolism will continue to focus on %s.", change_resist_msg[meal->last_eat]));
2175 new_draw_info (NDI_UNIQUE, 0, op, buf);
2176 abil->last_eat = 0; 2133 abil->last_eat = 0;
2177 } 2134 }
2178 } 2135 }
2136
2179 return 1; 2137 return 1;
2138}
2139
2140/**
2141 * op eats food.
2142 * If player, takes care of messages and dragon special food.
2143 */
2144static void
2145apply_food (object *op, object *tmp)
2146{
2147 int capacity_remaining;
2148
2149 if (op->type != PLAYER)
2150 op->stats.hp = op->stats.maxhp;
2151 else
2152 {
2153 /* check if this is a dragon (player), eating some flesh */
2154 if (tmp->type == FLESH && op->is_dragon () && dragon_eat_flesh (op, tmp))
2155 ;
2156 else
2157 {
2158 /* usual case - no dragon meal: */
2159 if (op->stats.food + tmp->stats.food > 999)
2160 {
2161 if (tmp->type == FOOD || tmp->type == FLESH)
2162 op->failmsg ("You feel full, but what a waste of food!");
2163 else
2164 op->statusmsg ("Most of the drink goes down your face not your throat!");
2165 }
2166
2167 tmp->play_sound (
2168 tmp->sound
2169 ? tmp->sound
2170 : tmp->type == DRINK
2171 ? sound_find ("eat_drink")
2172 : sound_find ("eat_food")
2173 );
2174
2175 if (!QUERY_FLAG (tmp, FLAG_CURSED))
2176 {
2177 const char *buf;
2178
2179 if (!op->is_dragon ())
2180 {
2181 /* eating message for normal players */
2182 if (tmp->type == DRINK)
2183 buf = format ("Ahhh...that %s tasted good.", &tmp->name);
2184 else
2185 buf = format ("The %s tasted %s", &tmp->name, tmp->type == FLESH ? "terrible!" : "good.");
2186 }
2187 else
2188 /* eating message for dragon players */
2189 buf = format ("The %s tasted terrible!", &tmp->name);
2190
2191 op->statusmsg (buf);
2192
2193 capacity_remaining = 999 - op->stats.food;
2194 op->stats.food += tmp->stats.food;
2195 if (capacity_remaining < tmp->stats.food)
2196 op->stats.hp += capacity_remaining / 50;
2197 else
2198 op->stats.hp += tmp->stats.food / 50;
2199
2200 if (op->stats.hp > op->stats.maxhp)
2201 op->stats.hp = op->stats.maxhp;
2202 if (op->stats.food > 999)
2203 op->stats.food = 999;
2204 }
2205
2206 /* special food hack -b.t. */
2207 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED))
2208 eat_special_food (op, tmp);
2209 }
2210 }
2211
2212 handle_apply_yield (tmp);
2213 tmp->decrease ();
2180} 2214}
2181 2215
2182/** 2216/**
2183 * Handles applying an improve armor scroll. 2217 * Handles applying an improve armor scroll.
2184 * Does some sanity checks, then calls improve_armour. 2218 * Does some sanity checks, then calls improve_armour.
2188{ 2222{
2189 object *armor; 2223 object *armor;
2190 2224
2191 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, 0, op->x, op->y, 0, 0) & P_NO_MAGIC)) 2225 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, 0, op->x, op->y, 0, 0) & P_NO_MAGIC))
2192 { 2226 {
2193 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll. H<The area prevents magic effects.>"); 2227 op->failmsg ("Something blocks the magic of the scroll. H<This area prevents magic effects.>");
2194 return; 2228 return;
2195 } 2229 }
2196 2230
2197 armor = find_marked_object (op); 2231 armor = find_marked_object (op);
2198 2232
2199 if (!armor) 2233 if (!armor)
2200 { 2234 {
2201 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark an armor object. Use the right mouse button popup or the mark command to do this."); 2235 op->failmsg ("You need to mark an armor object. Use the right mouse button popup or the mark command to do this.");
2202 return; 2236 return;
2203 } 2237 }
2204 2238
2205 if (armor->type != ARMOUR 2239 if (armor->type != ARMOUR
2206 && armor->type != CLOAK 2240 && armor->type != CLOAK
2207 && armor->type != BOOTS && armor->type != GLOVES && armor->type != BRACERS && armor->type != SHIELD && armor->type != HELMET) 2241 && armor->type != BOOTS && armor->type != GLOVES && armor->type != BRACERS && armor->type != SHIELD && armor->type != HELMET)
2208 { 2242 {
2209 new_draw_info (NDI_UNIQUE, 0, op, "Your marked item is not armour!\n"); 2243 op->failmsg ("Your marked item is not armour!\n");
2210 return; 2244 return;
2211 } 2245 }
2212 2246
2213 new_draw_info (NDI_UNIQUE, 0, op, "Applying armour enchantment."); 2247 op->statusmsg ("Applying armour enchantment.");
2214 improve_armour (op, tmp, armor); 2248 improve_armour (op, tmp, armor);
2215} 2249}
2216 2250
2217extern void 2251void
2218apply_poison (object *op, object *tmp) 2252apply_poison (object *op, object *tmp)
2219{ 2253{
2254 // need to do it now when it is still on the map
2255 handle_apply_yield (tmp);
2256
2257 object *poison = tmp->split (1);
2258
2220 if (op->type == PLAYER) 2259 if (op->type == PLAYER)
2221 { 2260 {
2222 op->contr->play_sound (sound_find ("drink_poison")); 2261 op->contr->play_sound (sound_find ("drink_poison"));
2223 new_draw_info (NDI_UNIQUE, 0, op, "Yech! That tasted poisonous!"); 2262 op->failmsg ("Yech! That tasted poisonous!");
2224 strcpy (op->contr->killer, "poisonous booze"); 2263 op->contr->killer = poison;
2225 } 2264 }
2226 2265
2227 if (tmp->stats.hp > 0) 2266 if (poison->stats.hp > 0)
2228 { 2267 {
2229 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", tmp->stats.hp); 2268 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", poison->stats.hp);
2230 hit_player (op, tmp->stats.hp, tmp, AT_POISON, 1); 2269 hit_player (op, poison->stats.hp, tmp, AT_POISON, 1);
2231 } 2270 }
2232 2271
2233 op->stats.food -= op->stats.food / 4; 2272 op->stats.food -= op->stats.food / 4;
2234 handle_apply_yield (tmp); 2273 poison->destroy ();
2235 decrease_ob (tmp);
2236} 2274}
2237 2275
2238/** 2276/**
2239 * This function return true if the exit is not a 2 ways one or it is 2 ways, valid exit. 2277 * This function will try to apply a lighter and in case no lighter
2240 * A valid 2 way exit means: 2278 * is specified it will try to find a lighter in the players inventory,
2241 * -You can come back (there is another exit at the other side) 2279 * and inform him about this requirement.
2242 * -You are
2243 * ° the owner of the exit
2244 * ° or in the same party as the owner
2245 * 2280 *
2246 * Note: a owner in a 2 way exit is saved as the owner's name 2281 * who - the player
2247 * in the field exit->name cause the field exit->owner doesn't 2282 * op - the item we want to light
2248 * survive in the swapping (in fact the whole exit doesn't survive). 2283 * lighter - the lighter or 0 if a lighter has yet to be found
2249 */ 2284 */
2250int 2285static object *
2251is_legal_2ways_exit (object *op, object *exit) 2286auto_apply_lighter (object *who, object *op, object *lighter)
2252{ 2287{
2253 if (exit->stats.exp != 1) 2288 if (lighter == 0)
2254 return 1; /*This is not a 2 way, so it is legal */
2255
2256#if 0 //TODO
2257 if (!has_been_loaded (EXIT_PATH (exit)) && exit->race)
2258 return 0; /* This is a reset town portal */
2259#endif
2260
2261 maptile *exitmap = maptile::find_sync (EXIT_PATH (exit), exit->map);
2262
2263 if (exitmap)
2264 { 2289 {
2265 exitmap->load_sync (); 2290 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2266
2267 object *tmp = exitmap->at (EXIT_X (exit), EXIT_Y (exit)).bot;
2268
2269 if (!tmp)
2270 return 0;
2271
2272 for (; tmp; tmp = tmp->above)
2273 { 2291 {
2274 if (tmp->type != EXIT) 2292 if (tmp->type == LIGHTER)
2275 continue; /*Not an exit */
2276
2277 if (!EXIT_PATH (tmp))
2278 continue; /*Not a valid exit */
2279
2280 if ((EXIT_X (tmp) != exit->x) || (EXIT_Y (tmp) != exit->y))
2281 continue; /*Not in the same place */
2282
2283 if (exit->map->path != EXIT_PATH (tmp))
2284 continue; /*Not in the same map */
2285
2286 /* From here we have found the exit is valid. However we do
2287 * here the check of the exit owner. It is important for the
2288 * town portals to prevent strangers from visiting your appartments
2289 */
2290 if (!exit->race)
2291 return 1; /*No owner, free for all! */
2292
2293 object *exit_owner = 0;
2294
2295 for_all_players (pp)
2296 { 2293 {
2297 if (!pp->ob) 2294 lighter = tmp;
2298 continue;
2299
2300 if (pp->ob->name != exit->race)
2301 continue;
2302
2303 exit_owner = pp->ob; /*We found a player which correspond to the player name */
2304 break; 2295 break;
2305 } 2296 }
2297 }
2306 2298
2307 if (!exit_owner) 2299 if (!lighter)
2308 return 0; /* No more owner */ 2300 {
2309 2301 who->failmsg (format (
2310 if (exit_owner->contr == op->contr) 2302 "You can't light up the %s with your bare hands! "
2311 return 1; /*It is your exit */ 2303 "H<You need a lighter in your inventory, for example a flint and steel.>",
2312 2304 &op->name));
2313 if (exit_owner && /*There is a owner */
2314 (op->contr) && /*A player tries to pass */
2315 ((exit_owner->contr->party == NULL) || /*No pass if controller has no party */
2316 (exit_owner->contr->party != op->contr->party))) /* Or not the same as op */
2317 return 0; 2305 return 0;
2306 }
2307 }
2318 2308
2309 // last_eat == 0 means the lighter is not being used up!
2310 if (lighter->last_eat && lighter->stats.food)
2311 {
2312 /* lighter gets used up */
2313 lighter = lighter->split ();
2314 lighter->stats.food--;
2315 who->insert (lighter);
2316 }
2317 else if (lighter->last_eat)
2318 {
2319 /* no charges left in lighter */
2320 who->failmsg (format (
2321 "You attempt to light the %s with a used up %s.",
2322 &op->name, &lighter->name));
2323 return 0;
2324 }
2325
2326 return lighter;
2327}
2328
2329/**
2330 * Designed primarily to light torches/lanterns/etc.
2331 * Also burns up burnable material too. First object in the inventory is
2332 * the selected object to "burn". -b.t.
2333 */
2334static void
2335apply_lighter (object *who, object *lighter)
2336{
2337 object *item;
2338 int is_player_env = 0;
2339
2340 item = find_marked_object (who);
2341 if (item)
2342 {
2343 if (!auto_apply_lighter (who, item, lighter))
2344 return;
2345
2346 /* Perhaps we should split what we are trying to light on fire?
2347 * I can't see many times when you would want to light multiple
2348 * objects at once.
2349 */
2350
2351 save_throw_object (item, AT_FIRE, who);
2352
2353 if (item->destroyed ()
2354 || ((item->type == LAMP || item->type == TORCH)
2355 && item->glow_radius > 0))
2356 who->statusmsg (format (
2357 "You light the %s with the %s.",
2358 &item->name, &lighter->name));
2359 else
2360 who->failmsg (format (
2361 "You attempt to light the %s with the %s and fail.",
2362 &item->name, &lighter->name));
2363 }
2364 else
2365 who->failmsg ("You need to mark a lightable object.");
2366}
2367
2368/**
2369 * This function generates a cursed effect for cursed lamps and torches.
2370 */
2371static void
2372player_apply_lamp_cursed_effect (object *who, object *op)
2373{
2374 if (op->level)
2375 {
2376 who->failmsg (format (
2377 "The %s was cursed, it explodes in a big fireball!",
2378 &op->name));
2379 create_exploding_ball_at (who, op->level);
2380 }
2381 else
2382 {
2383 who->failmsg (format (
2384 "The %s was cursed, it crumbles to dust, at least it didn't explode.!",
2385 &op->name));
2386 }
2387
2388 op->destroy ();
2389}
2390
2391/**
2392 * Apply for players and lamps
2393 *
2394 * who - the player
2395 * op - the lamp
2396 */
2397static void
2398player_apply_lamp (object *who, object *op)
2399{
2400 bool switch_on = op->glow_radius ? false : true;
2401
2402 if (switch_on)
2403 {
2404 object *lighter = 0;
2405
2406 if (op->flag [FLAG_IS_LIGHTABLE]
2407 && !(lighter = auto_apply_lighter (who, op, 0)))
2408 return;
2409
2410 if (op->stats.food < 1)
2411 {
2412 if (op->type == LAMP)
2413 who->failmsg (format (
2414 "The %s is out of fuel! "
2415 "H<Lamps and similar items need fuel. They cannot be refilled.>",
2416 &op->name));
2417 else
2418 who->failmsg (format (
2419 "The %s is burnt out! "
2420 "H<Torches and similar items burn out and become worthless.>",
2421 &op->name));
2319 return 1; 2422 return;
2423 }
2424
2425 if (op->flag [FLAG_CURSED])
2320 } 2426 {
2427 player_apply_lamp_cursed_effect (who, op);
2428 return;
2429 }
2430
2431 if (lighter)
2432 who->statusmsg (format (
2433 "You light up the %s with the %s.", &op->name, &lighter->name));
2434 else
2435 who->statusmsg (format ("You light up the %s.", &op->name));
2436 }
2437 else
2321 } 2438 {
2439 if (op->flag [FLAG_CURSED])
2440 {
2441 player_apply_lamp_cursed_effect (who, op);
2442 return;
2443 }
2322 2444
2445 if (op->type == TORCH)
2446 {
2447 if (!op->flag [FLAG_IS_LIGHTABLE])
2448 {
2449 who->statusmsg (format (
2450 "You put out the %s. "
2451 "H<The %s can't be used anymore, as it can't be lighted up again.>",
2452 &op->name, &op->name));
2453 }
2454 else
2455 who->statusmsg (format (
2456 "You put out the %s."
2457 "H<Torches wear out if you put them out.>",
2458 &op->name));
2459 }
2460 else
2461 who->statusmsg (format ("You turn off the %s.", &op->name));
2462 }
2463
2464 apply_lamp (op, switch_on);
2465}
2466
2467void get_animation_from_arch (object *op, arch_ptr a)
2468{
2469 op->animation_id = a->animation_id;
2470 op->flag [FLAG_IS_TURNABLE] = a->flag [FLAG_IS_TURNABLE];
2471 op->flag [FLAG_ANIMATE] = a->flag [FLAG_ANIMATE];
2472 op->anim_speed = a->anim_speed;
2473 op->last_anim = 0;
2474 op->state = 0;
2475 op->face = a->face;
2476
2477 if (NUM_ANIMATIONS(op) > 1)
2478 {
2479 SET_ANIMATION(op, 0);
2480 animate_object (op, op->direction);
2481 }
2482 else
2483 update_object (op, UP_OBJ_FACE);
2484}
2485
2486/**
2487 * Apply for LAMPs and TORCHes.
2488 *
2489 * op - the lamp
2490 * switch_on - a flag which says whether the lamp should be switched on or off
2491 */
2492void apply_lamp (object *op, bool switch_on)
2493{
2494 op->set_glow_radius (switch_on ? op->range : 0);
2495 op->set_speed (switch_on ? op->arch->speed : 0);
2496
2497 // torches wear out if you put them out
2498 if (op->type == TORCH && !switch_on)
2499 {
2500 if (op->flag [FLAG_IS_LIGHTABLE])
2501 {
2502 op->stats.food -= (double) op->arch->stats.food / 15;
2503 if (op->stats.food < 0)
2504 op->stats.food = 0;
2505 }
2506 else
2507 op->stats.food = 0;
2508 }
2509
2510 // lamps and torched get worthless when used up
2511 if (op->stats.food <= 0)
2512 op->value = 0;
2513
2514 // FIXME: This is a hack to make the more sane torches and lamps
2515 // still animated ;-/
2516 if (op->other_arch)
2517 get_animation_from_arch (op, switch_on ? op->other_arch : op->arch);
2518
2519 if (object *pl = op->visible_to ())
2520 esrv_update_item (UPD_ANIM | UPD_FACE | UPD_NAME, pl, op);
2521}
2522
2523/**
2524 * This handles items of type 'transformer'.
2525 * Basically those items, used with a marked item, transform both items into something
2526 * else.
2527 * "Transformer" item has food decreased by 1, removed if 0 (0 at start means illimited)..
2528 * Change information is contained in the 'slaying' field of the marked item.
2529 * The format is as follow: transformer:[number ]yield[;transformer:...].
2530 * This way an item can be transformed in many things, and/or many objects.
2531 * The 'slaying' field for transformer is used as verb for the action.
2532 */
2533static void
2534apply_item_transformer (object *pl, object *transformer)
2535{
2536 object *marked;
2537 object *new_item;
2538 const char *find;
2539 char *separator;
2540 int yield;
2541 char got[MAX_BUF];
2542 int len;
2543
2544 if (!pl || !transformer)
2323 return 0; 2545 return;
2546
2547 marked = find_marked_object (pl);
2548
2549 if (!marked)
2550 {
2551 pl->failmsg (format ("Use the %s with what item?", query_name (transformer)));
2552 return;
2553 }
2554
2555 if (!marked->slaying)
2556 {
2557 pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked)));
2558 return;
2559 }
2560
2561 /* check whether they are compatible or not */
2562 find = strstr (&marked->slaying, transformer->arch->archname);
2563 if (!find || (*(find + strlen (transformer->arch->archname)) != ':'))
2564 {
2565 pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked)));
2566 return;
2567 }
2568
2569 find += strlen (transformer->arch->archname) + 1;
2570 /* Item can be used, now find how many and what it yields */
2571 if (isdigit (*(find)))
2572 {
2573 yield = atoi (find);
2574 if (yield < 1)
2575 {
2576 LOG (llevDebug, "apply_item_transformer: item %s has slaying-yield %d.", query_base_name (marked, 0), yield);
2577 yield = 1;
2578 }
2579 }
2580 else
2581 yield = 1;
2582
2583 while (isdigit (*find))
2584 find++;
2585
2586 while (*find == ' ')
2587 find++;
2588
2589 memset (got, 0, MAX_BUF);
2590
2591 if ((separator = (char *) strchr (find, ';')))
2592 len = separator - find;
2593 else
2594 len = strlen (find);
2595
2596 min_it (len, MAX_BUF - 1);
2597
2598 strcpy (got, find);
2599 got[len] = '\0';
2600
2601 /* Now create new item, remove used ones when required. */
2602 new_item = get_archetype (got);
2603 if (!new_item)
2604 {
2605 pl->failmsg (format ("This %s is strange, better to not use it.", query_base_name (marked, 0)));
2606 return;
2607 }
2608
2609 new_item->nrof = yield;
2610
2611 pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0)));
2612
2613 pl->insert (new_item);
2614 /* Eat up one item */
2615 marked->decrease ();
2616
2617 /* Eat one transformer if needed */
2618 if (transformer->stats.food)
2619 if (--transformer->stats.food == 0)
2620 transformer->decrease ();
2324} 2621}
2325 2622
2326/** 2623/**
2327 * Main apply handler. 2624 * Main apply handler.
2328 * 2625 *
2331 * Return value: 2628 * Return value:
2332 * 0: player or monster can't apply objects of that type 2629 * 0: player or monster can't apply objects of that type
2333 * 1: has been applied, or there was an error applying the object 2630 * 1: has been applied, or there was an error applying the object
2334 * 2: objects of that type can't be applied if not in inventory 2631 * 2: objects of that type can't be applied if not in inventory
2335 * 2632 *
2336 * op is the object that is causing object to be applied, tmp is the object 2633 * who is the object that is causing object to be applied, op is the object
2337 * being applied. 2634 * being applied.
2338 * 2635 *
2339 * aflag is special (always apply/unapply) flags. Nothing is done with 2636 * aflag is special (always apply/unapply) flags. Nothing is done with
2340 * them in this function - they are passed to apply_special 2637 * them in this function - they are passed to apply_special
2341 */ 2638 */
2342int 2639int
2343manual_apply (object *op, object *tmp, int aflag) 2640manual_apply (object *who, object *op, int aflag)
2344{ 2641{
2345 if (tmp->head) 2642 op = op->head_ ();
2346 tmp = tmp->head;
2347 2643
2348 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED)) 2644 if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED))
2349 { 2645 {
2350 if (op->type == PLAYER) 2646 if (who->type == PLAYER)
2351 { 2647 {
2648 examine (who, op);
2352 new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first. H<You cannot use items marked as unpaid.>"); 2649 //who->failmsg ("You should pay for it first! H<You cannot use items marked as unpaid.>");//TODO remove
2353 return 1; 2650 return 1;
2354 } 2651 }
2355 else 2652 else
2356 return 0; /* monsters just skip unpaid items */ 2653 return 0; /* monsters just skip unpaid items */
2357 } 2654 }
2358 2655
2359 if (INVOKE_OBJECT (APPLY, tmp, ARG_OBJECT (op))) 2656 if (INVOKE_OBJECT (APPLY, op, ARG_OBJECT (who)))
2360 return RESULT_INT (0); 2657 return RESULT_INT (0);
2361 2658
2362 switch (tmp->type) 2659 switch (op->type)
2363 { 2660 {
2364 case CF_HANDLE: 2661 case T_HANDLE:
2365 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle.");
2366 op->play_sound (sound_find ("turn_handle")); 2662 who->play_sound (sound_find ("turn_handle"));
2663 who->statusmsg ("You turn the handle.");
2367 tmp->value = tmp->value ? 0 : 1; 2664 op->value = op->value ? 0 : 1;
2368 SET_ANIMATION (tmp, tmp->value); 2665 SET_ANIMATION (op, op->value);
2369 update_object (tmp, UP_OBJ_FACE); 2666 update_object (op, UP_OBJ_FACE);
2370 push_button (tmp); 2667 push_button (op, who);
2371 return 1; 2668 return 1;
2372 2669
2373 case TRIGGER: 2670 case TRIGGER:
2374 if (check_trigger (tmp, op)) 2671 if (check_trigger (op, who, who))
2375 { 2672 {
2376 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); 2673 who->statusmsg ("You turn the handle.");
2377 op->play_sound (sound_find ("turn_handle")); 2674 who->play_sound (sound_find ("turn_handle"));
2378 } 2675 }
2379 else 2676 else
2380 new_draw_info (NDI_UNIQUE, 0, op, "The handle doesn't move."); 2677 who->failmsg ("The handle doesn't move.");
2381 2678
2382 return 1; 2679 return 1;
2383 2680
2384 case EXIT: 2681 case EXIT:
2385 if (op->type != PLAYER) 2682 if (who->type != PLAYER)
2386 return 0; 2683 return 0;
2387 2684
2388 if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp)) 2685 if (!EXIT_PATH (op))
2389 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s is closed.", query_name (tmp)); 2686 who->failmsg (format ("The %s is closed. H<And will stay closed, until somebody fires up the map editor and adds it.>", query_name (op)));
2390 else 2687 else
2391 { 2688 {
2392 /* Don't display messages for random maps. */ 2689 /* Don't display messages for random maps. */
2393 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2)) 2690 if (op->msg && EXIT_PATH (op) != shstr_random_map_exit)
2394 new_draw_info (NDI_NAVY, 0, op, tmp->msg); 2691 who->statusmsg (op->msg, NDI_NAVY);
2395 2692
2396 op->enter_exit (tmp); 2693 who->enter_exit (op);
2397 } 2694 }
2398 2695
2399 return 1; 2696 return 1;
2400 2697
2698 case INSCRIBABLE:
2699 who->statusmsg (op->msg);
2700 // maybe show a spell menu to chose from or something like that
2701 return 1;
2702
2401 case SIGN: 2703 case SIGN:
2402 apply_sign (op, tmp, 0); 2704 apply_sign (who, op, 0);
2403 return 1; 2705 return 1;
2404 2706
2405 case BOOK: 2707 case BOOK:
2406 if (op->type == PLAYER) 2708 if (who->type == PLAYER)
2407 { 2709 {
2408 apply_book (op, tmp); 2710 apply_book (who, op);
2409 return 1; 2711 return 1;
2410 } 2712 }
2411 else 2713 else
2412 return 0; 2714 return 0;
2413 2715
2414 case SKILLSCROLL: 2716 case SKILLSCROLL:
2415 if (op->type == PLAYER) 2717 if (who->type == PLAYER)
2416 { 2718 {
2417 apply_skillscroll (op, tmp); 2719 apply_skillscroll (who, op);
2418 return 1; 2720 return 1;
2419 } 2721 }
2420 else 2722 else
2421 return 0; 2723 return 0;
2422 2724
2423 case SPELLBOOK: 2725 case SPELLBOOK:
2424 if (op->type == PLAYER) 2726 if (who->type == PLAYER)
2425 { 2727 {
2426 apply_spellbook (op, tmp); 2728 apply_spellbook (who, op);
2427 return 1; 2729 return 1;
2428 } 2730 }
2429 else 2731 else
2430 return 0; 2732 return 0;
2431 2733
2432 case SCROLL: 2734 case SCROLL:
2433 apply_scroll (op, tmp, 0); 2735 apply_scroll (who, op, 0);
2434 return 1; 2736 return 1;
2435 2737
2436 case POTION: 2738 case POTION:
2437 apply_potion (op, tmp); 2739 apply_potion (who, op);
2438 return 1; 2740 return 1;
2439 2741
2440 /* Eneq(@csd.uu.se): Handle apply on containers. */ 2742 /* Eneq(@csd.uu.se): Handle apply on containers. */
2441 //TODO: remove, as it is unsed? 2743 //TODO: remove, as it is unsed?
2442 case CLOSE_CON: 2744 case CLOSE_CON:
2443 apply_container (op, tmp->env); 2745 apply_container (who, op->env);
2444 return 1; 2746 return 1;
2445 2747
2446 case CONTAINER: 2748 case CONTAINER:
2447 apply_container (op, tmp); 2749 apply_container (who, op);
2448 return 1; 2750 return 1;
2449 2751
2450 case TREASURE: 2752 case TREASURE:
2451 if (op->type == PLAYER) 2753 if (who->type == PLAYER)
2452 { 2754 {
2453 apply_treasure (op, tmp); 2755 apply_treasure (who, op);
2454 return 1; 2756 return 1;
2455 } 2757 }
2456 else 2758 else
2457 return 0; 2759 return 0;
2760
2761 case LAMP:
2762 case TORCH:
2763 player_apply_lamp (who, op);
2764 return 1;
2458 2765
2459 case WEAPON: 2766 case WEAPON:
2460 case ARMOUR: 2767 case ARMOUR:
2461 case BOOTS: 2768 case BOOTS:
2462 case GLOVES: 2769 case GLOVES:
2470 case WAND: 2777 case WAND:
2471 case ROD: 2778 case ROD:
2472 case HORN: 2779 case HORN:
2473 case SKILL: 2780 case SKILL:
2474 case BOW: 2781 case BOW:
2475 case LAMP:
2476 case BUILDER: 2782 case BUILDER:
2477 case SKILL_TOOL: 2783 case SKILL_TOOL:
2478 if (tmp->env != op) 2784 if (op->env != who)
2479 return 2; /* not in inventory */ 2785 return 2; /* not in inventory */
2480 2786
2481 apply_special (op, tmp, aflag); 2787 apply_special (who, op, aflag);
2482 return 1; 2788 return 1;
2483 2789
2484 case DRINK: 2790 case DRINK:
2485 case FOOD: 2791 case FOOD:
2486 case FLESH: 2792 case FLESH:
2487 apply_food (op, tmp); 2793 apply_food (who, op);
2488 return 1; 2794 return 1;
2489 2795
2490 case POISON: 2796 case POISON:
2491 apply_poison (op, tmp); 2797 apply_poison (who, op);
2492 return 1; 2798 return 1;
2493 2799
2494 case SAVEBED: 2800 case SAVEBED:
2495 return 1; 2801 return 1;
2496 2802
2497 case ARMOUR_IMPROVER: 2803 case ARMOUR_IMPROVER:
2498 if (op->type == PLAYER) 2804 if (who->type == PLAYER)
2499 { 2805 {
2500 apply_armour_improver (op, tmp); 2806 apply_armour_improver (who, op);
2501 return 1; 2807 return 1;
2502 } 2808 }
2503 else 2809 else
2504 return 0; 2810 return 0;
2505 2811
2506 case WEAPON_IMPROVER: 2812 case WEAPON_IMPROVER:
2507 check_improve_weapon (op, tmp); 2813 check_improve_weapon (who, op);
2508 return 1; 2814 return 1;
2509 2815
2510 case CLOCK: 2816 case CLOCK:
2511 if (op->type == PLAYER) 2817 if (who->type == PLAYER)
2512 { 2818 {
2513 char buf[MAX_BUF]; 2819 char buf[MAX_BUF];
2514 timeofday_t tod; 2820 timeofday_t tod;
2515 2821
2516 get_tod (&tod); 2822 get_tod (&tod);
2517 sprintf (buf, "It is %d minute%s past %d o'clock %s",
2518 tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"),
2519 ((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am"));
2520 op->play_sound (sound_find ("sound_clock")); 2823 who->play_sound (sound_find ("sound_clock"));
2521 new_draw_info (NDI_UNIQUE, 0, op, buf); 2824 who->statusmsg (format (
2825 "It is %d minute%s past %d o'clock %s",
2826 tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"),
2827 ((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am")
2828 ));
2522 return 1; 2829 return 1;
2523 } 2830 }
2524 else 2831 else
2525 return 0; 2832 return 0;
2526 2833
2527 case MENU: 2834 case MENU:
2528 if (op->type == PLAYER) 2835 if (who->type == PLAYER)
2529 { 2836 {
2530 shop_listing (tmp, op); 2837 shop_listing (op, who);
2531 return 1; 2838 return 1;
2532 } 2839 }
2533 else 2840 else
2534 return 0; 2841 return 0;
2535 2842
2536 case POWER_CRYSTAL: 2843 case POWER_CRYSTAL:
2537 apply_power_crystal (op, tmp); /* see egoitem.c */ 2844 apply_power_crystal (who, op); /* see egoitem.c */
2538 return 1; 2845 return 1;
2539 2846
2540 case LIGHTER: /* for lighting torches/lanterns/etc */ 2847 case LIGHTER: /* for lighting torches/lanterns/etc */
2541 if (op->type == PLAYER) 2848 if (who->type == PLAYER)
2542 { 2849 {
2543 apply_lighter (op, tmp); 2850 apply_lighter (who, op);
2544 return 1; 2851 return 1;
2545 } 2852 }
2546 else 2853 else
2547 return 0; 2854 return 0;
2548 2855
2549 case ITEM_TRANSFORMER: 2856 case ITEM_TRANSFORMER:
2550 apply_item_transformer (op, tmp); 2857 apply_item_transformer (who, op);
2551 return 1; 2858 return 1;
2552 2859
2553 default: 2860 default:
2554 return 0; 2861 return 0;
2555 } 2862 }
2556} 2863}
2557
2558 2864
2559/* quiet suppresses the "don't know how to apply" and "you must get it first" 2865/* quiet suppresses the "don't know how to apply" and "you must get it first"
2560 * messages as needed by player_apply_below(). But there can still be 2866 * messages as needed by player_apply_below(). But there can still be
2561 * "but you are floating high above the ground" messages. 2867 * "but you are floating high above the ground" messages.
2562 * 2868 *
2563 * Same return value as apply() function. 2869 * Same return value as apply() function.
2564 */ 2870 */
2565int 2871int
2566player_apply (object *pl, object *op, int aflag, int quiet) 2872player_apply (object *pl, object *op, int aflag, int quiet)
2567{ 2873{
2568 int tmp;
2569
2570 if (op->env && (pl->move_type & MOVE_FLYING)) 2874 if (!op->env && (pl->move_type & MOVE_FLYING))
2571 { 2875 {
2572 /* player is flying and applying object not in inventory */ 2876 /* player is flying and applying object not in inventory */
2573 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING)) 2877 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING))
2574 { 2878 {
2575 new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high above the ground! H<You have to stop levitating first, if you can.>"); 2879 pl->failmsg ("But you are floating high above the ground! "
2880 "H<You have to stop levitating first, if you can, either by using your levitation skill, "
2881 "or waiting till the levitation effect wears off.>");
2576 return 0; 2882 return 0;
2577 } 2883 }
2578 } 2884 }
2579 2885
2580 pl->contr->last_used = op; 2886 pl->contr->last_used = op;
2581 2887
2582 tmp = manual_apply (pl, op, aflag); 2888 int tmp = manual_apply (pl, op, aflag);
2889
2583 if (!quiet) 2890 if (!quiet)
2584 { 2891 {
2585 if (tmp == 0) 2892 if (tmp == 0)
2586 new_draw_info_format (NDI_UNIQUE, 0, pl, "I don't know how to apply the %s.", query_name (op)); 2893 pl->statusmsg (format ("I don't know how to apply the %s.", query_name (op)));
2587 else if (tmp == 2) 2894 else if (tmp == 2)
2588 new_draw_info_format (NDI_UNIQUE, 0, pl, "You must get it first!\n"); 2895 pl->failmsg ("You must get it first!\n");
2589 } 2896 }
2590 2897
2591 return tmp; 2898 return tmp;
2592} 2899}
2593 2900
2607 * we don't use a corrupt pointer for the next object, so we get the 2914 * we don't use a corrupt pointer for the next object, so we get the
2608 * next object in the stack before applying. This is can only be a 2915 * next object in the stack before applying. This is can only be a
2609 * problem if player_apply() has a bug in that it uses the object but does 2916 * problem if player_apply() has a bug in that it uses the object but does
2610 * not return a proper value. 2917 * not return a proper value.
2611 */ 2918 */
2612 for (object *next, *tmp = pl->container ? pl->container->inv : pl->below; tmp; tmp = next) 2919 for (object *next, *tmp = pl->container_ () ? pl->container_ ()->inv : pl->below; tmp; tmp = next)
2613 { 2920 {
2614 next = tmp->below; 2921 next = tmp->below;
2615 2922
2616 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 2923 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
2617 floors++; 2924 floors++;
2622 * person moving on it, also activate. Added code to make it 2929 * person moving on it, also activate. Added code to make it
2623 * so that at least one of players movement types be that which 2930 * so that at least one of players movement types be that which
2624 * the item needs. 2931 * the item needs.
2625 */ 2932 */
2626 if (!tmp->invisible || (tmp->move_on & pl->move_type)) 2933 if (!tmp->invisible || (tmp->move_on & pl->move_type))
2627 {
2628 if (player_apply (pl, tmp, 0, 1) == 1) 2934 if (player_apply (pl, tmp, 0, 1) == 1)
2629 return; 2935 return;
2630 } 2936
2631 if (floors >= 2) 2937 if (floors >= 2)
2632 return; /* process at most two floor objects */ 2938 return; /* process at most two floor objects */
2633 } 2939 }
2634} 2940}
2635 2941
2670 { 2976 {
2671 pl->combat_ob = 0; 2977 pl->combat_ob = 0;
2672 who->change_weapon (pl->ranged_ob); 2978 who->change_weapon (pl->ranged_ob);
2673 } 2979 }
2674 2980
2675 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); 2981 who->statusmsg (format ("You unwield %s.", query_name (op)));
2676 2982
2677 change_abil (who, op); 2983 change_abil (who, op);
2678 CLEAR_FLAG (who, FLAG_READY_WEAPON); 2984 CLEAR_FLAG (who, FLAG_READY_WEAPON);
2679 break; 2985 break;
2680 2986
2681 case SKILL: 2987 case SKILL:
2682 if (who->contr) 2988 if (who->contr)
2683 { 2989 {
2990 if (IS_COMBAT_SKILL (op->subtype))
2991 who->change_weapon (who->contr->combat_ob = 0);
2992 else if (IS_RANGED_SKILL (op->subtype))
2993 who->change_weapon (who->contr->ranged_ob = 0);
2994
2684 if (!op->invisible) 2995 if (op->invisible)
2685 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op)); 2996 who->statusmsg (format ("You can no longer use the skill: %s.", &op->skill));
2686 else 2997 else
2687 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill); 2998 who->statusmsg (format ("You stop using the %s.", query_name (op)));
2688 } 2999 }
2689 3000
2690 change_abil (who, op); 3001 change_abil (who, op);
2691 CLEAR_FLAG (who, FLAG_READY_SKILL); 3002 CLEAR_FLAG (who, FLAG_READY_SKILL);
2692 break; 3003 break;
2699 case GLOVES: 3010 case GLOVES:
2700 case AMULET: 3011 case AMULET:
2701 case GIRDLE: 3012 case GIRDLE:
2702 case BRACERS: 3013 case BRACERS:
2703 case CLOAK: 3014 case CLOAK:
2704 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op)); 3015 who->statusmsg (format ("You unwear %s.", query_name (op)));
2705 change_abil (who, op); 3016 change_abil (who, op);
2706 break; 3017 break;
2707
2708 case LAMP:
2709 {
2710 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name);
2711
2712 object *tmp2 = arch_to_object (op->other_arch);
2713 tmp2->x = op->x;
2714 tmp2->y = op->y;
2715 tmp2->map = op->map;
2716 tmp2->below = op->below;
2717 tmp2->above = op->above;
2718 tmp2->stats.food = op->stats.food;
2719 CLEAR_FLAG (tmp2, FLAG_APPLIED);
2720
2721 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
2722 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2723
2724 if (who->contr)
2725 esrv_del_item (who->contr, op->count);
2726
2727 op->destroy ();
2728 insert_ob_in_ob (tmp2, who);
2729 who->update_stats ();
2730
2731 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2732 {
2733 if (who->contr)
2734 {
2735 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
2736 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
2737 }
2738 }
2739
2740 if (who->contr)
2741 esrv_send_item (who, tmp2);
2742 }
2743
2744 return 1; /* otherwise, an attempt to drop causes problems */
2745 3018
2746 case BOW: 3019 case BOW:
2747 case WAND: 3020 case WAND:
2748 case ROD: 3021 case ROD:
2749 case HORN: 3022 case HORN:
2753 { 3026 {
2754 pl->ranged_ob = 0; 3027 pl->ranged_ob = 0;
2755 who->change_weapon (pl->combat_ob); 3028 who->change_weapon (pl->combat_ob);
2756 } 3029 }
2757 3030
2758 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 3031 who->statusmsg (format ("You unready %s.", query_name (op)));
2759 } 3032 }
2760 else 3033 else
2761 { 3034 {
2762 who->change_skill (0); 3035 who->change_skill (0);
2763 3036
2769 3042
2770 break; 3043 break;
2771 3044
2772 case BUILDER: 3045 case BUILDER:
2773 if (who->contr) 3046 if (who->contr)
2774 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 3047 who->statusmsg (format ("You unready %s.", query_name (op)));
2775 break; 3048 break;
2776 3049
2777 default: 3050 default:
2778 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); 3051 who->statusmsg (format ("You unapply %s.", query_name (op)));
2779 break; 3052 break;
2780 } 3053 }
2781 3054
3055 if (aflags & AP_NO_MERGE || !merge_ob (op, 0))
3056 if (object *pl = op->visible_to ())
3057 esrv_send_item (pl, op);
3058
2782 who->update_stats (); 3059 who->update_stats ();
2783
2784 if (!(aflags & AP_NO_MERGE))
2785 {
2786 object *tmp = merge_ob (op, 0);
2787
2788 if (who->contr)
2789 {
2790 if (tmp)
2791 { /* it was merged */
2792 esrv_del_item (who->contr, op->count);
2793 op = tmp;
2794 }
2795
2796 esrv_send_item (who, op);
2797 }
2798 }
2799 3060
2800 return 0; 3061 return 0;
2801} 3062}
2802 3063
2803/** 3064/**
2841#define CANNOT_REMOVE_CURSED \ 3102#define CANNOT_REMOVE_CURSED \
2842 "H<You cannot remove cursed or damned items, you first have to remove the curse. " \ 3103 "H<You cannot remove cursed or damned items, you first have to remove the curse. " \
2843 "Praying over an altar, scrolls of remove curse/damnation, " \ 3104 "Praying over an altar, scrolls of remove curse/damnation, " \
2844 "priests or even other players might help.>" 3105 "priests or even other players might help.>"
2845 3106
2846int 3107static int
2847unapply_for_ob (object *who, object *op, int aflags) 3108unapply_for_ob (object *who, object *op, int aflags)
2848{ 3109{
2849 if (op->is_range ()) 3110 if (op->is_range ())
2850 for (object *tmp = who->inv; tmp; tmp = tmp->below) 3111 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2851 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ()) 3112 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ())
2852 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))) 3113 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED)))
2853 { 3114 {
2854 if (aflags & AP_PRINT) 3115 if (aflags & AP_PRINT)
2855 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); 3116 who->failmsg (query_name (tmp));
2856 else 3117 else
2857 unapply_special (who, tmp, aflags); 3118 unapply_special (who, tmp, aflags);
2858 } 3119 }
2859 else 3120 else
2860 { 3121 {
2861 /* In this case, we want to try and remove a cursed item. 3122 /* In this case, we want to try and remove a cursed item.
2862 * While we know it won't work, we want unapply_special to 3123 * While we know it won't work, we want unapply_special to
2863 * at least generate the message. 3124 * at least generate the message.
2864 */ 3125 */
2865 new_draw_info_format (NDI_UNIQUE, 0, who, 3126 who->failmsg (format ("No matter how hard you try, you just can't remove the %s." CANNOT_REMOVE_CURSED, query_name (tmp)));
2866 "No matter how hard you try, you just can't remove the %s." CANNOT_REMOVE_CURSED,
2867 query_name (tmp));
2868 return 1; 3127 return 1;
2869 } 3128 }
2870 3129
2871 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 3130 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
2872 { 3131 {
2895 3154
2896 /* If we are just printing, we don't care about cursed status */ 3155 /* If we are just printing, we don't care about cursed status */
2897 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)))) 3156 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))))
2898 { 3157 {
2899 if (aflags & AP_PRINT) 3158 if (aflags & AP_PRINT)
2900 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); 3159 who->failmsg (query_name (tmp));
2901 else 3160 else
2902 unapply_special (who, tmp, aflags); 3161 unapply_special (who, tmp, aflags);
2903 } 3162 }
2904 else 3163 else
2905 { 3164 {
2906 /* Cursed item that we can't unequip - tell the player. 3165 /* Cursed item that we can't unequip - tell the player.
2907 * Note this could be annoying if this is just one of a few, 3166 * Note this could be annoying if this is just one of a few,
2908 * so it may not be critical (eg, putting on a ring and you have 3167 * so it may not be critical (eg, putting on a ring and you have
2909 * one cursed ring.) 3168 * one cursed ring.)
2910 */ 3169 */
2911 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off." CANNOT_REMOVE_CURSED, query_name (tmp)); 3170 who->failmsg (format ("The %s just won't come off." CANNOT_REMOVE_CURSED, query_name (tmp)));
2912 } 3171 }
2913 3172
2914 last = tmp->below; 3173 last = tmp->below;
2915 } 3174 }
2916 /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the 3175 /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the
3097 if (basic_flag == AP_APPLY) 3356 if (basic_flag == AP_APPLY)
3098 return 0; 3357 return 0;
3099 3358
3100 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) 3359 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)))
3101 { 3360 {
3102 new_draw_info_format (NDI_UNIQUE, 0, who, 3361 who->failmsg (format ("No matter how hard you try, you just can't remove %s." CANNOT_REMOVE_CURSED, query_name (op)));
3103 "No matter how hard you try, you just can't remove %s." CANNOT_REMOVE_CURSED,
3104 query_name (op));
3105 return 1; 3362 return 1;
3106 } 3363 }
3107 3364
3108 return unapply_special (who, op, aflags); 3365 return unapply_special (who, op, aflags);
3109 } 3366 }
3110
3111 if (basic_flag == AP_UNAPPLY) 3367 else if (basic_flag == AP_UNAPPLY)
3112 return 0; 3368 return 0;
3113 3369
3114 // if the item is combat/ranged, wield the relevant slot first 3370 // if the item is combat/ranged, wield the relevant slot first
3115 // to resolve conflicts. 3371 // to resolve conflicts.
3116 if (player *pl = who->contr) 3372 if (player *pl = who->contr)
3125 /* Can't just apply this object. Lets see what not and what to do */ 3381 /* Can't just apply this object. Lets see what not and what to do */
3126 if (int i = can_apply_object (who, op)) 3382 if (int i = can_apply_object (who, op))
3127 { 3383 {
3128 if (i & CAN_APPLY_NEVER) 3384 if (i & CAN_APPLY_NEVER)
3129 { 3385 {
3130 new_draw_info_format (NDI_UNIQUE, 0, who, 3386 who->failmsg (format ("You don't have the body to use a %s. H<You can never apply this item.>", query_name (op)));
3131 "You don't have the body to use a %s. H<You can never apply this item.>",
3132 query_name (op));
3133 return 1; 3387 return 1;
3134 } 3388 }
3135 else if (i & CAN_APPLY_RESTRICTION) 3389 else if (i & CAN_APPLY_RESTRICTION)
3136 { 3390 {
3137 new_draw_info_format (NDI_UNIQUE, 0, who, 3391 who->failmsg (format (
3138 "You have a prohibition against using a %s. " 3392 "You have a prohibition against using a %s. "
3139 "H<Your belief, profession or class prevents you from applying this item.>", 3393 "H<Your belief, profession or class prevents you from applying this item.>",
3140 query_name (op)); 3394 query_name (op)
3395 ));
3141 return 1; 3396 return 1;
3142 } 3397 }
3143 3398
3144 if (who->type != PLAYER) 3399 if (who->type != PLAYER)
3145 { 3400 {
3149 } 3404 }
3150 else 3405 else
3151 { 3406 {
3152 if (who->contr->unapply == unapply_never || (i & CAN_APPLY_UNAPPLY_CHOICE && who->contr->unapply == unapply_nochoice)) 3407 if (who->contr->unapply == unapply_never || (i & CAN_APPLY_UNAPPLY_CHOICE && who->contr->unapply == unapply_nochoice))
3153 { 3408 {
3154 new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some of the following item(s) or change your applymode:"); 3409 who->failmsg ("You need to unapply some of the following item(s) or change your applymode:");
3155 unapply_for_ob (who, op, AP_PRINT); 3410 unapply_for_ob (who, op, AP_PRINT);
3156 return 1; 3411 return 1;
3157 } 3412 }
3158 else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE)) 3413 else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE))
3159 if (unapply_for_ob (who, op, aflags)) 3414 if (unapply_for_ob (who, op, aflags))
3165 { 3420 {
3166 skop = find_skill_by_name (who, op->skill); 3421 skop = find_skill_by_name (who, op->skill);
3167 3422
3168 if (!skop) 3423 if (!skop)
3169 { 3424 {
3170 new_draw_info_format (NDI_UNIQUE, 0, who, "You need the %s skill to use this item!", &op->skill); 3425 who->failmsg (format ("You need the %s skill to use this item!", &op->skill));
3171 return 1; 3426 return 1;
3172 } 3427 }
3173 else 3428 else
3174 /* While experience will be credited properly, we want to change the 3429 /* While experience will be credited properly, we want to change the
3175 * skill so that the dam and wc get updated 3430 * skill so that the dam and wc get updated
3176 */ 3431 */
3177 who->change_skill (skop); 3432 who->change_skill (skop);
3178 } 3433 }
3179 3434
3180 if (who->type == PLAYER 3435 if (!check_item_power (who, op->item_power))
3181 && op->item_power
3182 && op->item_power + who->contr->item_power > settings.item_power_factor * who->level)
3183 { 3436 {
3184 new_draw_info (NDI_UNIQUE, 0, who,
3185 "Equipping that combined with other items would consume your soul!" LACK_ITEM_POWER); 3437 who->failmsg ("Equipping that combined with other items would consume your soul!" LACK_ITEM_POWER);
3186 return 1; 3438 return 1;
3187 } 3439 }
3188 3440
3189 /* Ok. We are now at the state where we can apply the new object. 3441 /* Ok. We are now at the state where we can apply the new object.
3190 * Note that we don't have the checks for can_use_... 3442 * Note that we don't have the checks for can_use_...
3191 * below - that is already taken care of by can_apply_object. 3443 * below - that is already taken care of by can_apply_object.
3192 */ 3444 */
3193 if (op->nrof > 1) 3445 tmp = op->nrof > 1 ? op->split (op->nrof - 1) : 0;
3194 tmp = get_split_ob (op, op->nrof - 1);
3195 else
3196 tmp = 0;
3197 3446
3198 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op))) 3447 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op)))
3199 return RESULT_INT (0); 3448 return RESULT_INT (0);
3200 3449
3201 switch (op->type) 3450 switch (op->type)
3202 { 3451 {
3203 case WEAPON: 3452 case WEAPON:
3204 if (!check_weapon_power (who, op->last_eat))
3205 {
3206 new_draw_info (NDI_UNIQUE, 0, who, "This weapon is too powerful for you to use. "
3207 "It would consume your soul!." LACK_ITEM_POWER);
3208
3209 if (tmp)
3210 insert_ob_in_ob (tmp, who);
3211
3212 return 1;
3213 }
3214
3215 //TODO: this obviously fails for players using a shorter prefix 3453 //TODO: this obviously fails for players using a shorter prefix
3216 // i.e. "R" can use Ragnarok's sword. 3454 // i.e. "R" can use Ragnarok's sword.
3217 if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) 3455 if (op->level && !op->name.starts_with (who->name))
3218 { 3456 {
3219 /* if the weapon does not have the name as the character, can't use it. */ 3457 /* if the weapon does not have the name as the character, can't use it. */
3220 /* (Ragnarok's sword attempted to be used by Foo: won't work) */ 3458 /* (Ragnarok's sword attempted to be used by Foo: won't work) */
3221 new_draw_info (NDI_UNIQUE, 0, who, 3459 who->failmsg ("The weapon does not recognize you as its owner. H<Its name indicates that it belongs to somebody else.>");
3222 "The weapon does not recognize you as its owner. "
3223 "H<Its name indicates that it belongs to somebody else.>");
3224 3460
3225 if (tmp) 3461 if (tmp)
3226 insert_ob_in_ob (tmp, who); 3462 insert_ob_in_ob (tmp, who);
3227 3463
3228 return 1; 3464 return 1;
3229 } 3465 }
3230 3466
3231 if (!skop) 3467 if (!skop)
3232 { 3468 {
3233 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO 3469 who->failmsg (format ("The %s is broken, please report this to the dungeon master!", query_name (op)));//TODO
3234 return 1; 3470 return 1;
3235 } 3471 }
3236 3472
3237 SET_FLAG (op, FLAG_APPLIED); 3473 SET_FLAG (op, FLAG_APPLIED);
3238 who->change_skill (skop); 3474 who->change_skill (skop);
3239 3475
3240 if (who->contr) 3476 if (who->contr)
3241 who->change_weapon (who->contr->combat_ob = op); 3477 who->change_weapon (who->contr->combat_ob = op);
3242 3478
3243 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op)); 3479 who->statusmsg (format ("You wield %s.", query_name (op)));
3244 3480
3245 SET_FLAG (who, FLAG_READY_WEAPON); 3481 SET_FLAG (who, FLAG_READY_WEAPON);
3246 change_abil (who, op); 3482 change_abil (who, op);
3247 break; 3483 break;
3248 3484
3255 case BRACERS: 3491 case BRACERS:
3256 case CLOAK: 3492 case CLOAK:
3257 case RING: 3493 case RING:
3258 case AMULET: 3494 case AMULET:
3259 SET_FLAG (op, FLAG_APPLIED); 3495 SET_FLAG (op, FLAG_APPLIED);
3260 new_draw_info_format (NDI_UNIQUE, 0, who, "You wear %s.", query_name (op)); 3496 who->statusmsg (format ("You wear %s.", query_name (op)));
3261 change_abil (who, op); 3497 change_abil (who, op);
3262 break; 3498 break;
3263
3264 case LAMP:
3265 if (op->stats.food < 1)
3266 {
3267 new_draw_info_format (NDI_UNIQUE, 0, who,
3268 "Your %s is out of fuel! "
3269 "H<Lamps and similar items need fuel. They cannot be refilled.>", &op->name);
3270 return 1;
3271 }
3272
3273 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name);
3274 tmp2 = arch_to_object (op->other_arch);
3275 tmp2->stats.food = op->stats.food;
3276 SET_FLAG (tmp2, FLAG_APPLIED);
3277
3278 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
3279 SET_FLAG (tmp2, FLAG_INV_LOCKED);
3280
3281 insert_ob_in_ob (tmp2, who);
3282
3283 /* Remove the old lantern */
3284 if (who->type == PLAYER)
3285 esrv_del_item (who->contr, op->count);
3286
3287 op->destroy ();
3288
3289 /* insert the portion that was split off */
3290 if (tmp)
3291 {
3292 insert_ob_in_ob (tmp, who);
3293 if (who->type == PLAYER)
3294 esrv_send_item (who, tmp);
3295 }
3296
3297 who->update_stats ();
3298
3299 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3300 if (who->type == PLAYER)
3301 {
3302 new_draw_info (NDI_UNIQUE, 0, who,
3303 "Oops, it feels deadly cold! "
3304 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>");
3305 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
3306 }
3307
3308 if (who->type == PLAYER)
3309 esrv_send_item (who, tmp2);
3310
3311 return 0;
3312 3499
3313 case SKILL_TOOL: 3500 case SKILL_TOOL:
3314 // applying a skill tool also readies the skill 3501 // applying a skill tool also readies the skill
3315 SET_FLAG (op, FLAG_APPLIED); 3502 SET_FLAG (op, FLAG_APPLIED);
3316 3503
3325 case SKILL: 3512 case SKILL:
3326 if (player *pl = who->contr) 3513 if (player *pl = who->contr)
3327 { 3514 {
3328 if (IS_COMBAT_SKILL (op->subtype)) 3515 if (IS_COMBAT_SKILL (op->subtype))
3329 { 3516 {
3330 if (skill_flags [op->subtype] & SF_NEED_WEAPON) 3517 if (skill_flags [op->subtype] & SF_NEED_ITEM)
3331 { 3518 {
3332 for (object *item = who->inv; item; item = item->below) 3519 for (object *item = who->inv; item; item = item->below)
3333 if (item->type == WEAPON && item->flag [FLAG_APPLIED]) 3520 if (item->type == item->weapontype && item->flag [FLAG_APPLIED])
3334 { 3521 {
3335 if (item->skill == op->skill) 3522 if (item->skill == op->skill)
3336 { 3523 {
3337 who->change_weapon (pl->combat_ob = item); 3524 who->change_weapon (pl->combat_ob = item);
3338 goto found_weapon; 3525 goto found_weapon;
3339 } 3526 }
3340 } 3527 }
3341 3528
3342 new_draw_info_format (NDI_UNIQUE, 0, who, 3529 who->failmsg (format (
3343 "You need to apply a '%s' melee weapon before readying this skill. " 3530 "You need to apply a '%s' melee weapon before readying this skill. "
3344 "H<Some skills need an item, in this case a melee weapon, to function.>", 3531 "H<Some skills need an item, in this case a melee weapon, to function.>",
3345 &op->skill); 3532 &op->skill
3533 ));
3346 return 1; 3534 return 1;
3347 3535
3348 found_weapon:; 3536 found_weapon:;
3349 } 3537 }
3350 else 3538 else
3351 who->change_weapon (pl->combat_ob = op); 3539 who->change_weapon (pl->combat_ob = op);
3352 } 3540 }
3353 else if (IS_RANGED_SKILL (op->subtype)) 3541 else if (IS_RANGED_SKILL (op->subtype))
3354 { 3542 {
3355 if (skill_flags [op->subtype] & SF_NEED_BOW) 3543 if (skill_flags [op->subtype] & SF_NEED_ITEM)
3356 { 3544 {
3357 for (object *item = who->inv; item; item = item->below) 3545 for (object *item = who->inv; item; item = item->below)
3358 if (item->type == BOW && item->flag [FLAG_APPLIED]) 3546 if (item->type == item->weapontype && item->flag [FLAG_APPLIED])
3359 { 3547 {
3360 //TODO: bows should/must all have skill missile weapon right now 3548 //TODO: bows should/must all have skill missile weapon right now
3361 who->change_weapon (pl->ranged_ob = item); 3549 who->change_weapon (pl->ranged_ob = item);
3362 goto found_bow; 3550 goto found_bow;
3363 } 3551 }
3364 3552
3365 new_draw_info (NDI_UNIQUE, 0, who, 3553 who->failmsg (
3366 "You need to apply a missile weapon before readying this skill. " 3554 "You need to apply a missile weapon before readying this skill. "
3367 "H<Some skills need an item, in this case a missile weapon, to function.>"); 3555 "H<Some skills need an item, in this case a missile weapon, to function.>"
3556 );
3368 return 1; 3557 return 1;
3369 3558
3370 found_bow:; 3559 found_bow:;
3371 } 3560 }
3372 else 3561 else
3373 who->change_weapon (pl->ranged_ob = op); 3562 who->change_weapon (pl->ranged_ob = op);
3374 } 3563 }
3375 3564
3376 if (!op->invisible) 3565 if (!op->invisible)
3377 { 3566 {
3378 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); 3567 who->statusmsg (format (
3379 new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill); 3568 "You ready %s."
3569 "You can now use the skill: %s.",
3570 query_name (op),
3571 &op->skill
3572 ));
3380 } 3573 }
3381 else 3574 else
3382 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name); 3575 who->statusmsg (format ("Readied skill: %s.", op->skill ? &op->skill : &op->name));
3383 } 3576 }
3384 else 3577 else
3385 { 3578 {
3386 SET_FLAG (op, FLAG_APPLIED); 3579 SET_FLAG (op, FLAG_APPLIED);
3387 change_abil (who, op); 3580 change_abil (who, op);
3390 } 3583 }
3391 3584
3392 break; 3585 break;
3393 3586
3394 case BOW: 3587 case BOW:
3395 if (!check_weapon_power (who, op->last_eat)) 3588 if (op->level && !op->name.starts_with (who->name))
3396 { 3589 {
3397 new_draw_info (NDI_UNIQUE, 0, who,
3398 "That weapon is too powerful for you to use. It would consume your soul!" LACK_ITEM_POWER);
3399
3400 if (tmp)
3401 insert_ob_in_ob (tmp, who);
3402
3403 return 1;
3404 }
3405
3406 if (op->level && (strncmp (op->name, who->name, strlen (who->name))))
3407 {
3408 new_draw_info (NDI_UNIQUE, 0, who,
3409 "The weapon does not recognize you as its owner. " 3590 who->failmsg ("The weapon does not recognize you as its owner. "
3410 "H<Its name indicates that it belongs to somebody else.>"); 3591 "H<Its name indicates that it belongs to somebody else.>");
3411 if (tmp) 3592 if (tmp)
3412 insert_ob_in_ob (tmp, who); 3593 insert_ob_in_ob (tmp, who);
3413 3594
3414 return 1; 3595 return 1;
3420 case HORN: 3601 case HORN:
3421 /* check for skill, alter player status */ 3602 /* check for skill, alter player status */
3422 3603
3423 if (!skop) 3604 if (!skop)
3424 { 3605 {
3425 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO 3606 who->failmsg (format ("The %s is broken, please report this to the dungeon master!", query_name (op)));//TODO
3426 return 1; 3607 return 1;
3427 } 3608 }
3428 3609
3429 SET_FLAG (op, FLAG_APPLIED); 3610 SET_FLAG (op, FLAG_APPLIED);
3430 who->change_skill (skop); 3611 who->change_skill (skop);
3431 3612
3432 if (who->contr) 3613 if (who->contr)
3433 { 3614 {
3434 who->contr->ranged_ob = op; 3615 who->contr->ranged_ob = op;
3435 3616
3436 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); 3617 who->statusmsg (format ("You ready %s.", query_name (op)));
3437 3618
3438 if (op->type == BOW) 3619 if (op->type == BOW)
3439 { 3620 {
3440 who->current_weapon = op; 3621 who->current_weapon = op;
3441 change_abil (who, op); 3622 change_abil (who, op);
3442 new_draw_info_format (NDI_UNIQUE, 0, who,
3443 "You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op)); 3623 who->statusmsg (format ("You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op)));
3444 } 3624 }
3445 } 3625 }
3446 else 3626 else
3447 { 3627 {
3448 if (op->type == BOW) 3628 if (op->type == BOW)
3458 { 3638 {
3459 //TODO: wtf does this do? shouldn't this be managed automatically (slots?) 3639 //TODO: wtf does this do? shouldn't this be managed automatically (slots?)
3460 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER) 3640 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER)
3461 unapply_special (who, who->contr->ranged_ob, 0); 3641 unapply_special (who, who->contr->ranged_ob, 0);
3462 3642
3463 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op)); 3643 who->statusmsg (format ("You ready your %s.", query_name (op)));
3464 3644
3465 who->contr->ranged_ob = op; 3645 who->contr->ranged_ob = op;
3466 } 3646 }
3467 break; 3647 break;
3468 3648
3469 default: 3649 default:
3470 new_draw_info_format (NDI_UNIQUE, 0, who, "You apply %s.", query_name (op)); 3650 who->statusmsg (format ("You apply %s.", query_name (op)));
3471 } /* end of switch op->type */ 3651 }
3472 3652
3473 SET_FLAG (op, FLAG_APPLIED); 3653 SET_FLAG (op, FLAG_APPLIED);
3474 3654
3475 if (tmp) 3655 if (tmp)
3476 tmp = insert_ob_in_ob (tmp, who); 3656 who->insert (tmp);
3477 3657
3478 who->update_stats (); 3658 who->update_stats ();
3479 3659
3480 /* We exclude spell casting objects. The fire code will set the 3660 /* We exclude spell casting objects. The fire code will set the
3481 * been applied flag when they are used - until that point, 3661 * been applied flag when they are used - until that point,
3485 SET_FLAG (op, FLAG_BEEN_APPLIED); 3665 SET_FLAG (op, FLAG_BEEN_APPLIED);
3486 3666
3487 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3667 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3488 if (who->type == PLAYER) 3668 if (who->type == PLAYER)
3489 { 3669 {
3490 new_draw_info (NDI_UNIQUE, 0, who, 3670 who->failmsg (
3491 "Oops, it feels deadly cold! " 3671 "Oops, it feels deadly cold! "
3492 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>"); 3672 "H<Maybe it wasn't such a bright idea to apply this cursed or damned item.>"
3673 );
3493 SET_FLAG (op, FLAG_KNOWN_CURSED); 3674 SET_FLAG (op, FLAG_KNOWN_CURSED);
3494 } 3675 }
3495 3676
3496 if (who->type == PLAYER) 3677 if (object *pl = op->visible_to ())
3497 {
3498 /* if multiple objects were applied, update both slots */
3499 if (tmp)
3500 esrv_send_item (who, tmp);
3501
3502 esrv_send_item (who, op); 3678 esrv_send_item (pl, op);
3503 }
3504 3679
3505 return 0; 3680 return 0;
3506}
3507
3508int
3509monster_apply_special (object *who, object *op, int aflags)
3510{
3511 if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED))
3512 return 1;
3513
3514 return apply_special (who, op, aflags);
3515} 3681}
3516 3682
3517/** 3683/**
3518 * Map was just loaded, handle op's initialisation. 3684 * Map was just loaded, handle op's initialisation.
3519 * 3685 *
3522int 3688int
3523auto_apply (object *op) 3689auto_apply (object *op)
3524{ 3690{
3525 object *tmp = NULL, *tmp2; 3691 object *tmp = NULL, *tmp2;
3526 int i; 3692 int i;
3693
3694 CLEAR_FLAG (op, FLAG_AUTO_APPLY);
3527 3695
3528 switch (op->type) 3696 switch (op->type)
3529 { 3697 {
3530 case SHOP_FLOOR: 3698 case SHOP_FLOOR:
3531 if (!op->has_random_items ()) 3699 if (!op->has_random_items ())
3533 3701
3534 do 3702 do
3535 { 3703 {
3536 i = 10; /* let's give it 10 tries */ 3704 i = 10; /* let's give it 10 tries */
3537 while ((tmp = generate_treasure (op->randomitems, 3705 while ((tmp = generate_treasure (op->randomitems,
3538 op->stats.exp ? (int) op->stats.exp : MAX (op->map->difficulty, 5))) == NULL && --i); 3706 op->stats.exp
3707 ? (int) op->stats.exp
3708 : max (op->map->difficulty, 5)))
3709 == NULL && --i);
3710
3539 if (tmp == NULL) 3711 if (tmp == NULL)
3540 return 0; 3712 return 0;
3713
3541 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 3714 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
3542 { 3715 {
3543 tmp->destroy (); 3716 tmp->destroy ();
3544 tmp = NULL; 3717 tmp = NULL;
3545 } 3718 }
3548 3721
3549 tmp->x = op->x; 3722 tmp->x = op->x;
3550 tmp->y = op->y; 3723 tmp->y = op->y;
3551 SET_FLAG (tmp, FLAG_UNPAID); 3724 SET_FLAG (tmp, FLAG_UNPAID);
3552 insert_ob_in_map (tmp, op->map, NULL, 0); 3725 insert_ob_in_map (tmp, op->map, NULL, 0);
3553 CLEAR_FLAG (op, FLAG_AUTO_APPLY);
3554 identify (tmp); 3726 identify (tmp);
3555 break; 3727 break;
3556 3728
3557 case TREASURE: 3729 case TREASURE:
3558 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) 3730 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))
3565 /* If we generated an object and put it in this object inventory, 3737 /* If we generated an object and put it in this object inventory,
3566 * move it to the parent object as the current object is about 3738 * move it to the parent object as the current object is about
3567 * to disappear. An example of this item is the random_* stuff 3739 * to disappear. An example of this item is the random_* stuff
3568 * that is put inside other objects. 3740 * that is put inside other objects.
3569 */ 3741 */
3570 for (tmp = op->inv; tmp; tmp = tmp2)
3571 {
3572 tmp2 = tmp->below;
3573 tmp->remove ();
3574
3575 if (op->env) 3742 if (op->env)
3576 insert_ob_in_ob (tmp, op->env); 3743 while (op->inv)
3577 else 3744 op->env->insert (op->inv);
3578 tmp->destroy ();
3579 }
3580 3745
3581 op->destroy (); 3746 op->destroy ();
3582 break; 3747 break;
3583 } 3748 }
3584 return tmp ? 1 : 0; 3749
3750 return !!tmp;
3585} 3751}
3586 3752
3587/** 3753/**
3588 * fix_auto_apply goes through the entire map every time a map 3754 * fix_auto_apply goes through the entire map every time a map
3589 * is loaded or swapped in and performs special actions for 3755 * is loaded or swapped in and performs special actions for
3603 3769
3604 if (tmp->inv) 3770 if (tmp->inv)
3605 { 3771 {
3606 object *invtmp, *invnext; 3772 object *invtmp, *invnext;
3607 3773
3608 for (invtmp = tmp->inv; invtmp != NULL; invtmp = invnext) 3774 for (invtmp = tmp->inv; invtmp; invtmp = invnext)
3609 { 3775 {
3610 invnext = invtmp->below; 3776 invnext = invtmp->below;
3611 3777
3612 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY)) 3778 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY))
3613 auto_apply (invtmp); 3779 auto_apply (invtmp);
3614 else if (invtmp->type == TREASURE && invtmp->has_random_items ()) 3780 else if (invtmp->type == TREASURE && invtmp->has_random_items ())
3615 { 3781 {
3616 while ((invtmp->stats.hp--) > 0) 3782 while (invtmp->stats.hp-- > 0)
3617 create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0); 3783 create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0);
3618 3784
3619 invtmp->randomitems = NULL; 3785 invtmp->randomitems = NULL;
3620 } 3786 }
3621 else if (invtmp && invtmp->arch 3787 else if (invtmp && invtmp->arch
3626 * treasure again for this object 3792 * treasure again for this object
3627 */ 3793 */
3628 invtmp->randomitems = NULL; 3794 invtmp->randomitems = NULL;
3629 } 3795 }
3630 } 3796 }
3797
3631 /* This is really temporary - the code at the bottom will 3798 /* This is really temporary - the code at the bottom will
3632 * also set randomitems to null. The problem is there are bunches 3799 * also set randomitems to null. The problem is there are bunches
3633 * of maps/players already out there with items that have spells 3800 * of maps/players already out there with items that have spells
3634 * which haven't had the randomitems set to null yet. 3801 * which haven't had the randomitems set to null yet.
3635 * MSW 2004-05-13 3802 * MSW 2004-05-13
3639 * Ryo 2004-08-16 3806 * Ryo 2004-08-16
3640 */ 3807 */
3641 if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL 3808 if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL
3642 || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK) 3809 || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK)
3643 tmp->randomitems = NULL; 3810 tmp->randomitems = NULL;
3644
3645 } 3811 }
3646 3812
3647 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY)) 3813 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY))
3648 auto_apply (tmp); 3814 auto_apply (tmp);
3649 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ()) 3815 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ())
3682 } 3848 }
3683 3849
3684 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 3850 for (mapspace *ms = spaces + size (); ms-- > spaces; )
3685 for (object *tmp = ms->bot; tmp; tmp = tmp->above) 3851 for (object *tmp = ms->bot; tmp; tmp = tmp->above)
3686 if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL)) 3852 if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL))
3687 check_trigger (tmp, tmp->above); 3853 check_trigger (tmp, tmp->above, tmp->above);
3688} 3854}
3689 3855
3690/** 3856/**
3691 * Handles player eating food that temporarily changes status (resistances, stats). 3857 * Handles player eating food that temporarily changes status (resistances, stats).
3692 * This used to call cast_change_attr(), but 3858 * This used to call cast_change_attr(), but
3697eat_special_food (object *who, object *food) 3863eat_special_food (object *who, object *food)
3698{ 3864{
3699 object *force; 3865 object *force;
3700 int i, did_one = 0; 3866 int i, did_one = 0;
3701 3867
3702 force = get_archetype (FORCE_NAME); 3868 char buf[64];
3869 snprintf (buf, sizeof(buf), "sp_food_%s", &food->title);
3870 shstr key (buf);
3703 3871
3704 for (i = 0; i < NUM_STATS; i++)
3705 if (sint8 k = food->stats.stat (i))
3706 {
3707 force->stats.stat (i) = k;
3708 did_one = 1;
3709 }
3710
3711 /* check if we can protect the eater */
3712 for (i = 0; i < NROFATTACKS; i++)
3713 {
3714 if (food->resist[i] > 0)
3715 {
3716 force->resist[i] = food->resist[i] / 2;
3717 did_one = 1;
3718 }
3719 }
3720
3721 if (did_one)
3722 {
3723 force->set_speed (0.1);
3724 /* bigger morsel of food = longer effect time */ 3872 /* bigger morsel of food = longer effect time */
3725 force->duration = food->stats.food / 5; 3873 int duration = TIME2TICK (food->stats.food);
3726 SET_FLAG (force, FLAG_APPLIED); 3874
3727 change_abil (who, force); 3875 if (force = who->force_find (key))
3728 insert_ob_in_ob (force, who); 3876 {
3877 if (duration > fabs (force->speed_left / force->speed))
3878 {
3879 new_draw_info_format (NDI_UNIQUE, 0, who, "More magical force spreads through you. H<The effect will last for about %.10g more seconds.>", TICK2TIME (duration));
3880 force->force_set_timer (duration);
3881 }
3882 else
3883 new_draw_info (NDI_UNIQUE, 0, who, "It had no additional effect.");
3884
3885 return;
3729 } 3886 }
3730 else 3887 else
3888 {
3889 force = who->force_add (key, duration);
3890 force->name = key;
3891
3892 /* check if the food affects a stat */
3893 for (i = 0; i < NUM_STATS; i++)
3894 if (sint8 k = food->stats.stat (i))
3895 {
3896 force->stats.stat (i) = k;
3897 did_one = 1;
3898 }
3899
3900 /* check if we can protect the eater */
3901 for (i = 0; i < NROFATTACKS; i++)
3902 {
3903 if (food->resist[i] > 0)
3904 {
3905 force->resist[i] = food->resist[i];
3906 did_one = 1;
3907 }
3908 }
3909
3910 if (did_one)
3911 {
3912 new_draw_info_format (NDI_UNIQUE, 0, who, "You are suffused with magical force. H<The effect will last for about %.10g seconds.>", TICK2TIME (duration));
3913
3914 /* make the force take effect and report effects to user */
3915 change_abil (who, force);
3916 }
3917 else
3731 force->destroy (); 3918 force->destroy ();
3919 }
3732 3920
3733 /* check for hp, sp change */ 3921 /* check for hp, sp change */
3734 if (food->stats.hp != 0) 3922 if (food->stats.hp != 0)
3735 { 3923 {
3736 if (QUERY_FLAG (food, FLAG_CURSED)) 3924 if (QUERY_FLAG (food, FLAG_CURSED))
3737 { 3925 {
3738 assign (who->contr->killer, food->name); 3926 who->contr->killer = food;
3739 hit_player (who, food->stats.hp, food, AT_POISON, 1); 3927 hit_player (who, food->stats.hp, food, AT_POISON, 1);
3740 new_draw_info (NDI_UNIQUE, 0, who, "Eck!...that was poisonous!"); 3928 who->failmsg ("Eck!...that was poisonous!");
3741 } 3929 }
3742 else 3930 else
3743 { 3931 {
3744 if (food->stats.hp > 0) 3932 if (food->stats.hp > 0)
3745 new_draw_info (NDI_UNIQUE, 0, who, "You begin to feel better."); 3933 who->statusmsg ("You begin to feel better.");
3746 else 3934 else
3747 new_draw_info (NDI_UNIQUE, 0, who, "Eck!...that was poisonous!"); 3935 who->failmsg ("Eck!...that was poisonous!");
3936
3748 who->stats.hp += food->stats.hp; 3937 who->stats.hp += food->stats.hp;
3749 } 3938 }
3750 } 3939 }
3940
3751 if (food->stats.sp != 0) 3941 if (food->stats.sp != 0)
3752 { 3942 {
3753 if (QUERY_FLAG (food, FLAG_CURSED)) 3943 if (QUERY_FLAG (food, FLAG_CURSED))
3754 { 3944 {
3755 new_draw_info (NDI_UNIQUE, 0, who, "You are drained of mana!"); 3945 who->failmsg ("You are drained of mana!");
3756 who->stats.sp -= food->stats.sp; 3946 who->stats.sp -= food->stats.sp;
3757 if (who->stats.sp < 0) 3947 if (who->stats.sp < 0)
3758 who->stats.sp = 0; 3948 who->stats.sp = 0;
3759 } 3949 }
3760 else 3950 else
3761 { 3951 {
3762 new_draw_info (NDI_UNIQUE, 0, who, "You feel a rush of magical energy!"); 3952 who->statusmsg ("You feel a rush of magical energy!");
3763 who->stats.sp += food->stats.sp; 3953 who->stats.sp += food->stats.sp;
3764 /* place limit on max sp from food? */ 3954 /* place limit on max sp from food? */
3765 } 3955 }
3766 } 3956 }
3957
3767 who->update_stats (); 3958 who->update_stats ();
3768}
3769
3770/**
3771 * Designed primarily to light torches/lanterns/etc.
3772 * Also burns up burnable material too. First object in the inventory is
3773 * the selected object to "burn". -b.t.
3774 */
3775void
3776apply_lighter (object *who, object *lighter)
3777{
3778 object *item;
3779 int is_player_env = 0;
3780
3781 item = find_marked_object (who);
3782 if (item)
3783 {
3784 if (lighter->last_eat && lighter->stats.food)
3785 { /* lighter gets used up */
3786 /* Split multiple lighters if they're being used up. Otherwise *
3787 * one charge from each would be used up. --DAMN */
3788 if (lighter->nrof > 1)
3789 {
3790 object *oneLighter = lighter->clone ();
3791
3792 lighter->nrof -= 1;
3793 oneLighter->nrof = 1;
3794 oneLighter->stats.food--;
3795 esrv_send_item (who, lighter);
3796 oneLighter = insert_ob_in_ob (oneLighter, who);
3797 esrv_send_item (who, oneLighter);
3798 }
3799 else
3800 lighter->stats.food--;
3801 }
3802 else if (lighter->last_eat)
3803 { /* no charges left in lighter */
3804 new_draw_info_format (NDI_UNIQUE, 0, who, "You attempt to light the %s with a used up %s.", &item->name, &lighter->name);
3805 return;
3806 }
3807
3808 /* Perhaps we should split what we are trying to light on fire?
3809 * I can't see many times when you would want to light multiple
3810 * objects at once.
3811 */
3812
3813 if (who == item->in_player ())
3814 is_player_env = 1;
3815
3816 save_throw_object (item, AT_FIRE, who);
3817
3818 if (item->destroyed ())
3819 {
3820 new_draw_info_format (NDI_UNIQUE, 0, who, "You light the %s with the %s.", &item->name, &lighter->name);
3821 /* Need to update the player so that the players glow radius
3822 * gets changed.
3823 */
3824 if (is_player_env)
3825 who->update_stats ();
3826 }
3827 else
3828 new_draw_info_format (NDI_UNIQUE, 0, who, "You attempt to light the %s with the %s and fail.", &item->name, &lighter->name);
3829 }
3830 else /* nothing to light */
3831 new_draw_info (NDI_UNIQUE, 0, who, "You need to mark a lightable object.");
3832
3833}
3834
3835/**
3836 * op made some mistake with a scroll, this takes care of punishment.
3837 * scroll_failure()- hacked directly from spell_failure
3838 */
3839void
3840scroll_failure (object *op, int failure, int power)
3841{
3842 if (abs (failure / 4) > power)
3843 power = abs (failure / 4); /* set minimum effect */
3844
3845 if (failure <= -1 && failure > -15)
3846 { /* wonder */
3847 object *tmp;
3848
3849 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!");
3850 tmp = get_archetype (SPELL_WONDER);
3851 cast_wonder (op, op, 0, tmp);
3852 tmp->destroy ();
3853 }
3854 else if (failure <= -15 && failure > -35)
3855 { /* drain mana */
3856 new_draw_info (NDI_UNIQUE, 0, op, "Your mana is drained!.");
3857 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW);
3858 if (op->stats.sp < 0)
3859 op->stats.sp = 0;
3860 }
3861 else if (settings.spell_failure_effects == TRUE)
3862 {
3863 if (failure <= -35 && failure > -60)
3864 { /* confusion */
3865 new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils on you!");
3866 confuse_player (op, op, power);
3867 }
3868 else if (failure <= -60 && failure > -70)
3869 { /* paralysis */
3870 new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils and paralyzes " "you!");
3871 paralyze_player (op, op, power);
3872 }
3873 else if (failure <= -70 && failure > -80)
3874 { /* blind */
3875 new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils on you!");
3876 blind_player (op, op, power);
3877 }
3878 else if (failure <= -80)
3879 { /* blast the immediate area */
3880 object *tmp = get_archetype (LOOSE_MANA);
3881 cast_magic_storm (op, tmp, power);
3882 new_draw_info (NDI_UNIQUE, 0, op, "You unleash uncontrolled mana!");
3883 tmp->destroy ();
3884 }
3885 }
3886} 3959}
3887 3960
3888void 3961void
3889apply_changes_to_player (object *pl, object *change) 3962apply_changes_to_player (object *pl, object *change)
3890{ 3963{
3938 } 4011 }
3939 4012
3940 /* insert the randomitems from the change's treasurelist into 4013 /* insert the randomitems from the change's treasurelist into
3941 * the player ref: player.c 4014 * the player ref: player.c
3942 */ 4015 */
3943 if (change->randomitems != NULL) 4016 if (change->randomitems)
3944 give_initial_items (pl, change->randomitems); 4017 give_initial_items (pl, change->randomitems);
3945 4018
3946 /* set up the face, for some races. */ 4019 /* set up the face, for some races. */
3947 4020
3948 /* first, look for the force object banning 4021 /* first, look for the force object banning
3949 * changing the face. Certain races never change face with class. 4022 * changing the face. Certain races never change face with class.
3950 */ 4023 */
3951 for (walk = pl->inv; walk != NULL; walk = walk->below) 4024 for (walk = pl->inv; walk; walk = walk->below)
3952 if (!strcmp (walk->name, "NOCLASSFACECHANGE")) 4025 if (walk->name == shstr_NOCLASSFACECHANGE)
3953 flag_change_face = 0; 4026 flag_change_face = 0;
3954 4027
3955 if (flag_change_face) 4028 if (flag_change_face)
3956 { 4029 {
3957 pl->animation_id = GET_ANIM_ID (change);
3958 pl->face = change->face; 4030 pl->face = change->face;
3959 4031 pl->animation_id = change->animation_id;
3960 if (QUERY_FLAG (change, FLAG_ANIMATE)) 4032 pl->flag [FLAG_ANIMATE] = change->flag [FLAG_ANIMATE];
3961 SET_FLAG (pl, FLAG_ANIMATE);
3962 else
3963 CLEAR_FLAG (pl, FLAG_ANIMATE);
3964 } 4033 }
3965 4034
3966 /* check the special case of can't use weapons */ 4035 /* check the special case of can't use weapons */
3967 /*if(QUERY_FLAG(change,FLAG_USE_WEAPON)) CLEAR_FLAG(pl,FLAG_USE_WEAPON); */ 4036 /*if(QUERY_FLAG(change,FLAG_USE_WEAPON)) CLEAR_FLAG(pl,FLAG_USE_WEAPON); */
3968 if (!strcmp (change->name, "monk")) 4037 if (change->name == shstr_monk)
3969 CLEAR_FLAG (pl, FLAG_USE_WEAPON); 4038 CLEAR_FLAG (pl, FLAG_USE_WEAPON);
3970 4039
3971 break; 4040 break;
3972 } 4041 }
3973 } 4042 }
3974} 4043}
3975 4044
3976/**
3977 * This handles items of type 'transformer'.
3978 * Basically those items, used with a marked item, transform both items into something
3979 * else.
3980 * "Transformer" item has food decreased by 1, removed if 0 (0 at start means illimited)..
3981 * Change information is contained in the 'slaying' field of the marked item.
3982 * The format is as follow: transformer:[number ]yield[;transformer:...].
3983 * This way an item can be transformed in many things, and/or many objects.
3984 * The 'slaying' field for transformer is used as verb for the action.
3985 */
3986void
3987apply_item_transformer (object *pl, object *transformer)
3988{
3989 object *marked;
3990 object *new_item;
3991 char *find;
3992 char *separator;
3993 int yield;
3994 char got[MAX_BUF];
3995 int len;
3996
3997 if (!pl || !transformer)
3998 return;
3999
4000 marked = find_marked_object (pl);
4001
4002 if (!marked)
4003 {
4004 new_draw_info_format (NDI_UNIQUE, 0, pl, "Use the %s with what item?", query_name (transformer));
4005 return;
4006 }
4007
4008 if (!marked->slaying)
4009 {
4010 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked));
4011 return;
4012 }
4013
4014 /* check whether they are compatible or not */
4015 find = strstr (marked->slaying, transformer->arch->archname);
4016 if (!find || (*(find + strlen (transformer->arch->archname)) != ':'))
4017 {
4018 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked));
4019 return;
4020 }
4021
4022 find += strlen (transformer->arch->archname) + 1;
4023 /* Item can be used, now find how many and what it yields */
4024 if (isdigit (*(find)))
4025 {
4026 yield = atoi (find);
4027 if (yield < 1)
4028 {
4029 LOG (llevDebug, "apply_item_transformer: item %s has slaying-yield %d.", query_base_name (marked, 0), yield);
4030 yield = 1;
4031 }
4032 }
4033 else
4034 yield = 1;
4035
4036 while (isdigit (*find))
4037 find++;
4038 while (*find == ' ')
4039 find++;
4040
4041 memset (got, 0, MAX_BUF);
4042
4043 if ((separator = strchr (find, ';')) != NULL)
4044 len = separator - find;
4045 else
4046 len = strlen (find);
4047
4048 if (len > MAX_BUF - 1)
4049 len = MAX_BUF - 1;
4050
4051 strcpy (got, find);
4052 got[len] = '\0';
4053
4054 /* Now create new item, remove used ones when required. */
4055 new_item = get_archetype (got);
4056 if (!new_item)
4057 {
4058 new_draw_info_format (NDI_UNIQUE, 0, pl, "This %s is strange, better to not use it.", query_base_name (marked, 0));
4059 return;
4060 }
4061
4062 new_item->nrof = yield;
4063 new_draw_info_format (NDI_UNIQUE, 0, pl, "You %s the %s.", &transformer->slaying, query_base_name (marked, 0));
4064 insert_ob_in_ob (new_item, pl);
4065 esrv_send_inventory (pl, pl);
4066 /* Eat up one item */
4067 decrease_ob_nr (marked, 1);
4068
4069 /* Eat one transformer if needed */
4070 if (transformer->stats.food)
4071 if (--transformer->stats.food == 0)
4072 decrease_ob_nr (transformer, 1);
4073}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines