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

Comparing deliantra/server/server/skills.C (file contents):
Revision 1.39 by root, Tue Jul 3 06:07:07 2007 UTC vs.
Revision 1.64 by root, Tue May 5 04:51:56 2009 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2003,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2003,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 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
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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,
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 GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * 20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <object.h> 25#include <object.h>
26#include <sproto.h> 26#include <sproto.h>
41 /* Only prohibit stealing if the player does not have a free 41 /* Only prohibit stealing if the player does not have a free
42 * hand available and in fact does have hands. 42 * hand available and in fact does have hands.
43 */ 43 */
44 if (op->type == PLAYER && op->slot[body_arm].used <= 0 && op->slot[body_arm].info) 44 if (op->type == PLAYER && op->slot[body_arm].used <= 0 && op->slot[body_arm].info)
45 { 45 {
46 new_draw_info (NDI_UNIQUE, 0, op, "But you have no free hands to steal with!"); 46 new_draw_info (NDI_UNIQUE, 0, op, "But you have no free hands to steal with! "
47 "H<Try to unapply weapons or things you hold in your hands, use the C<body> command.>");
47 return -1; 48 return -1;
48 } 49 }
49 50
50 /* ADJUSTMENTS */ 51 /* ADJUSTMENTS */
51 52
64 * it quite a bit harder to steal. 65 * it quite a bit harder to steal.
65 */ 66 */
66 for (equip = op->inv; equip; equip = equip->below) 67 for (equip = op->inv; equip; equip = equip->below)
67 { 68 {
68 if (equip->type == WEAPON && QUERY_FLAG (equip, FLAG_APPLIED)) 69 if (equip->type == WEAPON && QUERY_FLAG (equip, FLAG_APPLIED))
69 {
70 roll -= equip->weight / 10000; 70 roll -= equip->weight / 10000;
71 } 71
72 if (equip->type == BOW && QUERY_FLAG (equip, FLAG_APPLIED)) 72 if (equip->type == BOW && QUERY_FLAG (equip, FLAG_APPLIED))
73 roll -= equip->weight / 5000; 73 roll -= equip->weight / 5000;
74
74 if (equip->type == SHIELD && QUERY_FLAG (equip, FLAG_APPLIED)) 75 if (equip->type == SHIELD && QUERY_FLAG (equip, FLAG_APPLIED))
75 {
76 roll -= equip->weight / 2000; 76 roll -= equip->weight / 2000;
77 } 77
78 if (equip->type == ARMOUR && QUERY_FLAG (equip, FLAG_APPLIED)) 78 if (equip->type == ARMOUR && QUERY_FLAG (equip, FLAG_APPLIED))
79 roll -= equip->weight / 5000; 79 roll -= equip->weight / 5000;
80
80 if (equip->type == GLOVES && QUERY_FLAG (equip, FLAG_APPLIED)) 81 if (equip->type == GLOVES && QUERY_FLAG (equip, FLAG_APPLIED))
81 roll -= equip->weight / 100; 82 roll -= equip->weight / 100;
82 } 83 }
84
83 if (roll < 0) 85 if (roll < 0)
84 roll = 0; 86 roll = 0;
87
85 return roll; 88 return roll;
86} 89}
87 90
88/* 91/*
89 * When stealing: dependent on the intelligence/wisdom of whom you're 92 * When stealing: dependent on the intelligence/wisdom of whom you're
99{ 102{
100 object *success = NULL, *tmp = NULL, *next; 103 object *success = NULL, *tmp = NULL, *next;
101 int roll = 0, chance = 0, stats_value; 104 int roll = 0, chance = 0, stats_value;
102 rv_vector rv; 105 rv_vector rv;
103 106
104 stats_value = ((who->stats.Dex + who->stats.Int) * 3) / 2; 107 stats_value = (who->stats.Dex + who->stats.Int) * 3 / 2;
105 108
106 /* if the victim is aware of a thief in the area (FLAG_NO_STEAL set on them) 109 /* if the victim is aware of a thief in the area (FLAG_NO_STEAL set on them)
107 * they will try to prevent stealing if they can. Only unseen theives will 110 * they will try to prevent stealing if they can. Only unseen theives will
108 * have much chance of success. 111 * have much chance of success.
109 */ 112 */
110 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_NO_STEAL)) 113 if (!op->is_player () && op->flag [FLAG_NO_STEAL])
111 { 114 {
112 if (can_detect_enemy (op, who, &rv)) 115 if (can_detect_enemy (op, who, &rv))
113 { 116 {
114 npc_call_help (op); 117 npc_call_help (op);
115 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); 118 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE);
116 new_draw_info (NDI_UNIQUE, 0, who, "Your attempt is prevented!"); 119 new_draw_info (NDI_UNIQUE, 0, who, "Your attempt is prevented!");
117 return 0; 120 return 0;
118 } 121 }
119 else /* help npc to detect thief next time by raising its wisdom */ 122 else /* help npc to detect thief next time by raising its wisdom */
120 op->stats.Wis += (op->stats.Int / 5) + 1; 123 op->stats.Wis += (op->stats.Int / 5) + 1;
124
121 if (op->stats.Wis > MAX_STAT) 125 if (op->stats.Wis > MAX_STAT)
122 op->stats.Wis = MAX_STAT; 126 op->stats.Wis = MAX_STAT;
123 } 127 }
124 128
125 if (op->type == PLAYER && QUERY_FLAG (op, FLAG_WIZ)) 129 if (op->is_player () && op->flag [FLAG_WIZ])
126 { 130 {
127 new_draw_info (NDI_UNIQUE, 0, who, "You can't steal from the dungeon master!\n"); 131 new_draw_info (NDI_UNIQUE, 0, who, "You can't steal from the dungeon master!\n");
128 return 0; 132 return 0;
129 } 133 }
130 134
131 // only allow stealing between hostile players (TODO: probably should change) 135 // only allow stealing between hostile players (TODO: probably should change)
132 if (op->type == PLAYER && who->type == PLAYER && (who->contr->peaceful || op->contr->peaceful)) 136 if (op->is_player () && who->is_player () && (who->contr->peaceful || op->contr->peaceful))
133 { 137 {
134 new_draw_info (NDI_UNIQUE, 0, who, "You can't steal from other players!\n"); 138 new_draw_info (NDI_UNIQUE, 0, who, "You can't steal from other players!\n");
135 return 0; 139 return 0;
136 } 140 }
137 141
138 /* Ok then, go thru their inventory, stealing */ 142 /* Ok then, go through their inventory, stealing */
139 for (tmp = op->inv; tmp; tmp = next) 143 for (tmp = op->inv; tmp; tmp = next)
140 { 144 {
141 next = tmp->below; 145 next = tmp->below;
142 146
143 /* you can't steal worn items, starting items, wiz stuff, 147 /* you can't steal worn items, starting items, wiz stuff,
177 if (tmp->destroyed () || tmp->env != op) 181 if (tmp->destroyed () || tmp->env != op)
178 { 182 {
179 /* for players, play_sound: steals item */ 183 /* for players, play_sound: steals item */
180 success = tmp; 184 success = tmp;
181 CLEAR_FLAG (tmp, FLAG_INV_LOCKED); 185 CLEAR_FLAG (tmp, FLAG_INV_LOCKED);
182
183 /* Don't delete it from target player until we know
184 * the thief has picked it up. can't just look at tmp->count,
185 * as it's possible that it got merged when picked up.
186 */
187 if (op->type == PLAYER)
188 esrv_del_item (op->contr, tmp->count);
189 } 186 }
187
190 break; 188 break;
191 } 189 }
192 } /* for loop looking for an item */ 190 } /* for loop looking for an item */
193 191
194 if (!tmp) 192 if (!tmp)
203 */ 201 */
204 202
205 if ((roll >= skill->level) || !chance 203 if ((roll >= skill->level) || !chance
206 || (tmp && tmp->weight > (250 * (random_roll (0, stats_value + skill->level * 10 - 1, who, PREFER_LOW))))) 204 || (tmp && tmp->weight > (250 * (random_roll (0, stats_value + skill->level * 10 - 1, who, PREFER_LOW)))))
207 { 205 {
208
209 /* victim figures out where the thief is! */ 206 /* victim figures out where the thief is! */
210 if (who->hide) 207 if (who->flag [FLAG_HIDDEN])
211 make_visible (who); 208 make_visible (who);
212 209
213 if (op->type != PLAYER) 210 if (op->type != PLAYER)
214 { 211 {
215 /* The unaggressives look after themselves 8) */ 212 /* The unaggressives look after themselves 8) */
216 if (who->type == PLAYER) 213 if (who->type == PLAYER)
217 { 214 {
218 npc_call_help (op); 215 npc_call_help (op);
219 new_draw_info_format (NDI_UNIQUE, 0, who, "%s notices your attempted pilfering!", query_name (op)); 216 new_draw_info_format (NDI_UNIQUE, 0, who, "%s notices your attempted pilfering!", query_name (op));
220 } 217 }
218
221 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); 219 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE);
222 /* all remaining npc items are guarded now. Set flag NO_STEAL 220 /* all remaining npc items are guarded now. Set flag NO_STEAL
223 * on the victim. 221 * on the victim.
224 */ 222 */
225 SET_FLAG (op, FLAG_NO_STEAL); 223 SET_FLAG (op, FLAG_NO_STEAL);
228 { /* stealing from another player */ 226 { /* stealing from another player */
229 char buf[MAX_BUF]; 227 char buf[MAX_BUF];
230 228
231 /* Notify the other player */ 229 /* Notify the other player */
232 if (success && who->stats.Int > random_roll (0, 19, op, PREFER_LOW)) 230 if (success && who->stats.Int > random_roll (0, 19, op, PREFER_LOW))
233 {
234 sprintf (buf, "Your %s is missing!", query_name (success)); 231 sprintf (buf, "Your %s is missing!", query_name (success));
235 }
236 else 232 else
237 {
238 sprintf (buf, "Your pack feels strangely lighter."); 233 sprintf (buf, "Your pack feels strangely lighter.");
239 } 234
240 new_draw_info (NDI_UNIQUE, 0, op, buf); 235 new_draw_info (NDI_UNIQUE, 0, op, buf);
241 if (!success) 236 if (!success)
242 { 237 {
243 if (who->invisible) 238 if (who->invisible)
244 {
245 sprintf (buf, "you feel itchy fingers getting at your pack."); 239 sprintf (buf, "you feel itchy fingers getting at your pack.");
246 }
247 else 240 else
248 {
249 sprintf (buf, "%s looks very shifty.", query_name (who)); 241 sprintf (buf, "%s looks very shifty.", query_name (who));
250 } 242
251 new_draw_info (NDI_UNIQUE, 0, op, buf); 243 new_draw_info (NDI_UNIQUE, 0, op, buf);
252 } 244 }
253 } /* else stealing from another player */ 245 } /* else stealing from another player */
254 /* play_sound("stop! thief!"); kindofthing */ 246 /* play_sound("stop! thief!"); kindofthing */
255 } /* if you weren't 100% successful */ 247 } /* if you weren't 100% successful */
248
256 return success ? 1 : 0; 249 return success ? 1 : 0;
257} 250}
258 251
259int 252int
260steal (object *op, int dir, object *skill) 253steal (object *op, int dir, object *skill)
437 op->invisible += 100; /* set the level of 'hiddeness' */ 430 op->invisible += 100; /* set the level of 'hiddeness' */
438 431
439 if (op->type == PLAYER) 432 if (op->type == PLAYER)
440 op->contr->tmp_invis = 1; 433 op->contr->tmp_invis = 1;
441 434
442 op->hide = 1; 435 op->flag [FLAG_HIDDEN] = 1;
443 return 1; 436 return 1;
444 } 437 }
445 438
446 return 0; 439 return 0;
447} 440}
456 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 449 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
457 { 450 {
458 new_draw_info (NDI_UNIQUE, 0, op, "You don't need to hide while invisible!"); 451 new_draw_info (NDI_UNIQUE, 0, op, "You don't need to hide while invisible!");
459 return 0; 452 return 0;
460 } 453 }
461 else if (!op->hide && op->invisible > 0 && op->type == PLAYER) 454 else if (!op->flag [FLAG_HIDDEN] && op->invisible > 0 && op->type == PLAYER)
462 { 455 {
463 new_draw_info (NDI_UNIQUE, 0, op, "Your attempt to hide breaks the invisibility spell!"); 456 new_draw_info (NDI_UNIQUE, 0, op, "Your attempt to hide breaks the invisibility spell!");
464 make_visible (op); 457 make_visible (op);
465 } 458 }
466 459
488static void 481static void
489stop_jump (object *pl, int dist, int spaces) 482stop_jump (object *pl, int dist, int spaces)
490{ 483{
491 pl->update_stats (); 484 pl->update_stats ();
492 pl->map->insert (pl, pl->x, pl->y, pl); 485 pl->map->insert (pl, pl->x, pl->y, pl);
486 pl->speed_left -= fabs (pl->speed * 8);
493} 487}
494 488
495static int 489static int
496attempt_jump (object *pl, int dir, int spaces, object *skill) 490attempt_jump (object *pl, int dir, int spaces, object *skill)
497{ 491{
498 object *tmp; 492 object *tmp;
499 int i, exp = 0, dx = freearr_x[dir], dy = freearr_y[dir], mflags; 493 int i, dx = freearr_x[dir], dy = freearr_y[dir], mflags;
500 sint16 x, y; 494 sint16 x, y;
501 maptile *m; 495 maptile *m;
502 496
503 /* Jump loop. Go through spaces opject wants to jump. Halt the 497 /* Jump loop. Go through spaces object wants to jump. Halt the
504 * jump if a wall or creature is in the way. We set FLAG_FLYING 498 * jump if a wall or creature is in the way. We set FLAG_FLYING
505 * temporarily to allow player to aviod exits/archs that are not 499 * temporarily to allow player to aviod exits/archs that are not
506 * fly_on, fly_off. This will also prevent pickup of objects 500 * fly_on, fly_off. This will also prevent pickup of objects
507 * while jumping over them. 501 * while jumping over them.
508 */ 502 */
509
510 pl->remove (); 503 pl->remove ();
511
512 /*
513 * I don't think this is actually needed - all the movement
514 * code is handled in this function, and I don't see anyplace
515 * that cares about the move_type being flying.
516 */
517 pl->move_type |= MOVE_FLY_LOW; 504 pl->move_type |= MOVE_FLY_LOW;
518 505
519 for (i = 0; i <= spaces; i++) 506 for (i = 0; i <= spaces; i++)
520 { 507 {
521 x = pl->x + dx; 508 x = pl->x + dx;
524 511
525 mflags = get_map_flags (m, &m, x, y, &x, &y); 512 mflags = get_map_flags (m, &m, x, y, &x, &y);
526 513
527 if (mflags & P_OUT_OF_MAP) 514 if (mflags & P_OUT_OF_MAP)
528 { 515 {
529 (void) stop_jump (pl, i, spaces); 516 stop_jump (pl, i, spaces);
530 return 0; 517 return 0;
531 } 518 }
519
520 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
521 {
522 /* Jump into creature */
523 if (QUERY_FLAG (tmp, FLAG_MONSTER)
524 || (tmp->type == PLAYER && (!QUERY_FLAG (tmp, FLAG_WIZ) || !tmp->contr->hidden)))
525 {
526 new_draw_info_format (NDI_UNIQUE, 0, pl, "You jump into %s%s.", tmp->type == PLAYER ? "" : "the ", &tmp->name);
527
528 stop_jump (pl, i, spaces);
529
530 int exp = 0;
531
532 if (tmp->type != PLAYER
533 || (pl->type == PLAYER && !pl->contr->party)
534 || (pl->type == PLAYER && tmp->type == PLAYER && pl->contr->party != tmp->contr->party))
535 exp = skill_attack (tmp, pl, pl->facing, "kicked", skill); /* pl makes an attack */
536
537 return exp; /* note that calc_skill_exp() is already called by skill_attack() */
538 }
539 }
540
532 if (OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, x, y))) 541 if (OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, x, y)))
533 { 542 {
534 new_draw_info (NDI_UNIQUE, 0, pl, "Your jump is blocked."); 543 new_draw_info (NDI_UNIQUE, 0, pl, "Your jump is blocked.");
535 stop_jump (pl, i, spaces); 544 stop_jump (pl, i, spaces);
536 return 0; 545 return 0;
537 } 546 }
538 547
539 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
540 {
541 /* Jump into creature */
542 if (QUERY_FLAG (tmp, FLAG_MONSTER) || (tmp->type == PLAYER && (!QUERY_FLAG (tmp, FLAG_WIZ) || !tmp->contr->hidden)))
543 {
544 new_draw_info_format (NDI_UNIQUE, 0, pl, "You jump into %s%s.", tmp->type == PLAYER ? "" : "the ", &tmp->name);
545 if (tmp->type != PLAYER ||
546 (pl->type == PLAYER && pl->contr->party == NULL) ||
547 (pl->type == PLAYER && tmp->type == PLAYER && pl->contr->party != tmp->contr->party))
548 exp = skill_attack (tmp, pl, pl->facing, "kicked", skill); /* pl makes an attack */
549 stop_jump (pl, i, spaces);
550 return exp; /* note that calc_skill_exp() is already called by skill_attack() */
551 }
552 /* If the space has fly on set (no matter what the space is),
553 * we should get the effects - after all, the player is
554 * effectively flying.
555 */
556 if (tmp->move_on & MOVE_FLY_LOW)
557 {
558 pl->x = x;
559 pl->y = y;
560 pl->map = m;
561 stop_jump (pl, i, spaces);
562 return calc_skill_exp (pl, NULL, skill);
563 }
564 }
565 pl->x = x; 548 pl->x = x;
566 pl->y = y; 549 pl->y = y;
567 pl->map = m; 550 pl->map = m;
551
552 if (m->at (x, y).move_on & pl->move_type)
553 {
554 new_draw_info (NDI_UNIQUE, 0, pl, "Your jump is stopped.");
555 stop_jump (pl, i, spaces);
556 return 0;
557 }
568 } 558 }
559
569 stop_jump (pl, i, spaces); 560 stop_jump (pl, i, spaces);
561
570 return calc_skill_exp (pl, NULL, skill); 562 return calc_skill_exp (pl, NULL, skill);
571} 563}
572 564
573/* jump() - this is both a new type of movement for player/monsters and 565/* jump() - this is both a new type of movement for player/monsters and
574 * an attack as well. 566 * an attack as well.
575 * Perhaps we should allow more spaces based on level, eg, level 50 567 * Perhaps we should allow more spaces based on level, eg, level 50
576 * jumper can jump several spaces? 568 * jumper can jump several spaces?
577 */ 569 */
578
579int 570int
580jump (object *pl, int dir, object *skill) 571jump (object *pl, int dir, object *skill)
581{ 572{
582 int spaces = 0, stats;
583 int str = pl->stats.Str; 573 int str = pl->stats.Str;
584 int dex = pl->stats.Dex; 574 int dex = pl->stats.Dex;
585 575
586 dex = dex ? dex : 15; 576 dex = dex ? dex : 15;
587 str = str ? str : 10; 577 str = str ? str : 10;
588 578
589 stats = str * str * str * dex * skill->level; 579 int stats = str * str * str * dex * skill->level;
580 int spaces = min (3, skill->level, stats / (pl->carrying + 1));
590 581
591 if (pl->carrying != 0) /* don't want div by zero !! */
592 spaces = (int) (stats / pl->carrying);
593 else
594 spaces = 2; /* pl has no objects - gets the far jump */
595
596 if (spaces > 2)
597 spaces = 2;
598 else if (spaces == 0) 582 if (spaces == 0)
599 { 583 {
600 new_draw_info (NDI_UNIQUE, 0, pl, "You are carrying too much weight to jump."); 584 new_draw_info (NDI_UNIQUE, 0, pl, "You are carrying too much weight to jump.");
601 return 0; 585 return 0;
602 } 586 }
587
603 return attempt_jump (pl, dir, spaces, skill); 588 return attempt_jump (pl, dir, spaces, skill);
604} 589}
605
606 590
607/* skill_ident() - this code is supposed to allow players to identify 591/* skill_ident() - this code is supposed to allow players to identify
608 * classes of objects with the various "auto-ident" skills. Player must 592 * classes of objects with the various "auto-ident" skills. Player must
609 * have unidentified objects of the right type in order for the skill 593 * have unidentified objects of the right type in order for the skill
610 * to work. While multiple classes of objects may be identified, 594 * to work. While multiple classes of objects may be identified,
611 * this code is kind of yucky -- it would be nice to make it a bit 595 * this code is kind of yucky -- it would be nice to make it a bit
612 * more generalized. Right now, skill indices are embedded in this routine. 596 * more generalized. Right now, skill indices are embedded in this routine.
613 * Returns amount of experience gained (on successful ident). 597 * Returns amount of experience gained (on successful ident).
614 * - b.t. (thomas@astro.psu.edu) 598 * - b.t. (thomas@astro.psu.edu)
615 */ 599 */
616
617static int 600static int
618do_skill_detect_curse (object *pl, object *skill) 601do_skill_detect_curse (object *pl, object *skill)
619{ 602{
620 object *tmp; 603 object *tmp;
621 int success = 0; 604 int success = 0;
699 if (tmp->msg) 682 if (tmp->msg)
700 { 683 {
701 new_draw_info (NDI_UNIQUE, 0, pl, "The item has a story:"); 684 new_draw_info (NDI_UNIQUE, 0, pl, "The item has a story:");
702 new_draw_info (NDI_UNIQUE, 0, pl, tmp->msg); 685 new_draw_info (NDI_UNIQUE, 0, pl, tmp->msg);
703 } 686 }
704
705 /* identify will take care of updating the item if it is in the players inventory. IF on map, do it here */
706 if (tmp->map)
707 esrv_send_item (pl, tmp);
708 } 687 }
688
709 success += calc_skill_exp (pl, tmp, skill); 689 success += calc_skill_exp (pl, tmp, skill);
710 } 690 }
711 else 691 else
712 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); 692 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT);
713 } 693 }
896 /* Ok, got a 'sucker' lets try to make them a follower */ 876 /* Ok, got a 'sucker' lets try to make them a follower */
897 if (level > 0 && tmp->level < (random_roll (0, level - 1, pl, PREFER_HIGH) - 1)) 877 if (level > 0 && tmp->level < (random_roll (0, level - 1, pl, PREFER_HIGH) - 1))
898 { 878 {
899 new_draw_info_format (NDI_UNIQUE, 0, pl, "You convince the %s to become your follower.\n", query_name (tmp)); 879 new_draw_info_format (NDI_UNIQUE, 0, pl, "You convince the %s to become your follower.\n", query_name (tmp));
900 880
881 INVOKE_OBJECT (KILL, tmp, ARG_OBJECT (pl));
901 tmp->set_owner (pl); 882 tmp->set_owner (pl);
902 tmp->skill = skill->skill; 883 tmp->skill = skill->skill;
903 tmp->stats.exp = 0; 884 tmp->stats.exp = 0;
904 add_friendly_object (tmp);
905 tmp->attack_movement = PETMOVE; 885 tmp->attack_movement = PETMOVE;
886
887 if (!QUERY_FLAG (tmp, FLAG_FRIENDLY))
888 add_friendly_object (tmp);
889
906 return calc_skill_exp (pl, tmp, skill); 890 return calc_skill_exp (pl, tmp, skill);
907 } 891 }
908 /* Charm failed. Creature may be angry now */ 892 /* Charm failed. Creature may be angry now */
909 else if ((skill->level + ((pl->stats.Cha - 10) / 2)) < random_roll (1, 2 * tmp->level, pl, PREFER_LOW)) 893 else if ((skill->level + ((pl->stats.Cha - 10) / 2)) < random_roll (1, 2 * tmp->level, pl, PREFER_LOW))
910 { 894 {
911 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your speech angers the %s!\n", query_name (tmp)); 895 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your speech angers the %s!\n", query_name (tmp));
912 if (QUERY_FLAG (tmp, FLAG_FRIENDLY)) 896 if (QUERY_FLAG (tmp, FLAG_FRIENDLY))
913 { 897 {
914 CLEAR_FLAG (tmp, FLAG_FRIENDLY);
915 remove_friendly_object (tmp); 898 remove_friendly_object (tmp);
916 tmp->attack_movement = 0; /* needed? */ 899 tmp->attack_movement = 0; /* needed? */
917 } 900 }
918 901
919 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); 902 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE);
1120 success += calc_skill_exp (op, tmp, skill); 1103 success += calc_skill_exp (op, tmp, skill);
1121 } 1104 }
1122 } 1105 }
1123 } 1106 }
1124 } 1107 }
1108
1125 return success; 1109 return success;
1126} 1110}
1127
1128 1111
1129/* pray() - when this skill is called from do_skill(), it allows 1112/* pray() - when this skill is called from do_skill(), it allows
1130 * the player to regain lost grace points at a faster rate. -b.t. 1113 * the player to regain lost grace points at a faster rate. -b.t.
1131 * This always returns 0 - return value is used by calling function 1114 * This always returns 0 - return value is used by calling function
1132 * such that if it returns true, player gets exp in that skill. This 1115 * such that if it returns true, player gets exp in that skill. This
1133 * the effect here can be done on demand, we probably don't want to 1116 * the effect here can be done on demand, we probably don't want to
1134 * give infinite exp by returning true in any cases. 1117 * give infinite exp by returning true in any cases.
1135 */ 1118 */
1136
1137int 1119int
1138pray (object *pl, object *skill) 1120pray (object *pl, object *skill)
1139{ 1121{
1140 char buf[MAX_BUF]; 1122 char buf[MAX_BUF];
1141 object *tmp; 1123 object *tmp;
1166 if (pl->stats.grace < pl->stats.maxgrace) 1148 if (pl->stats.grace < pl->stats.maxgrace)
1167 { 1149 {
1168 pl->stats.grace++; 1150 pl->stats.grace++;
1169 pl->last_grace = -1; 1151 pl->last_grace = -1;
1170 } 1152 }
1153
1171 return 0; 1154 return 0;
1172} 1155}
1173 1156
1174/* This skill allows the player to regain a few sp or hp for a 1157/* This skill allows the player to regain a few sp or hp for a
1175 * brief period of concentration. No armour or weapons may be 1158 * brief period of concentration. No armour or weapons may be
1176 * wielded/applied for this to work. The amount of time needed 1159 * wielded/applied for this to work. The amount of time needed
1177 * to concentrate and the # of points regained is dependant on 1160 * to concentrate and the # of points regained is dependant on
1178 * the level of the user. - b.t. thomas@astro.psu.edu 1161 * the level of the user. - b.t. thomas@astro.psu.edu
1179 */ 1162 */
1180
1181void 1163void
1182meditate (object *pl, object *skill) 1164meditate (object *pl, object *skill)
1183{ 1165{
1184 object *tmp; 1166 object *tmp;
1185 1167
1228 pl->last_heal = -1; 1210 pl->last_heal = -1;
1229 } 1211 }
1230} 1212}
1231 1213
1232/* write_note() - this routine allows players to inscribe messages in 1214/* write_note() - this routine allows players to inscribe messages in
1233 * ordinary 'books' (anything that is type BOOK). b.t. 1215 * ordinary inscribable 'books' (anything that is not a SPELL). b.t.
1234 */ 1216 */
1235static int 1217static int
1236write_note (object *pl, object *item, const char *msg, object *skill) 1218write_note (object *pl, object *item, const char *msg, object *skill)
1237{ 1219{
1220 if (strstr (msg, "\nendmsg"))
1221 {
1222 new_draw_info (NDI_UNIQUE, 0, pl, "Trying to cheat now are we?");
1223 return 0;
1224 }
1225
1226 int len = strlen (msg);
1227
1228 if (!is_utf8_string ((U8 *)msg, len))
1229 {
1230 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your message is garbled (text must be UTF-8, client-bug)!");
1231 return 0;
1232 }
1233
1234 if (INVOKE_OBJECT (INSCRIBE_NOTE, item, ARG_PLAYER (pl->contr), ARG_STRING (msg), ARG_OBJECT (skill)))
1235 return RESULT_INT (0);
1236
1238 char buf[1024]; 1237 char buf[1024];
1239 object *newBook = NULL;
1240 1238
1241 /* a pair of sanity checks */ 1239 if (len < sizeof (buf) - 2)
1242 if (!item || item->type != BOOK)
1243 return 0;
1244
1245 if (!msg)
1246 {
1247 new_draw_info (NDI_UNIQUE, 0, pl, "No message to write!");
1248 new_draw_info_format (NDI_UNIQUE, 0, pl, "Usage: use_skill %s <message>", &skill->skill);
1249 return 0;
1250 } 1240 {
1241 snprintf (buf, sizeof (buf), "%s\n", msg);
1251 1242
1252 if (strcasestr_local (msg, "endmsg")) 1243 object *newbook = arch_to_object (item->other_arch);
1253 { 1244 item->decrease ();
1254 new_draw_info (NDI_UNIQUE, 0, pl, "Trying to cheat now are we?");
1255 return 0;
1256 }
1257
1258 if (INVOKE_OBJECT (INSCRIBE_NOTE, item, ARG_PLAYER (pl->contr), ARG_STRING (msg), ARG_OBJECT (skill)))
1259 return strlen (msg);
1260
1261 buf[0] = 0;
1262 if (!book_overflow (item->msg, msg, sizeof (buf)))
1263 { /* add msg string to book */
1264 if (item->msg)
1265 strcpy (buf, item->msg);
1266
1267 strcat (buf, msg);
1268 strcat (buf, "\n"); /* new msg needs a LF */
1269 if (item->nrof > 1)
1270 {
1271 newBook = item->clone ();
1272 decrease_ob (item);
1273 esrv_send_item (pl, item);
1274 newBook->nrof = 1; 1245 newbook->nrof = 1;
1275 newBook->msg = buf; 1246 newbook->msg = buf;
1276 newBook = insert_ob_in_ob (newBook, pl); 1247 newbook->flag [FLAG_IDENTIFIED] = true;
1277 esrv_send_item (pl, newBook); 1248
1249 if (item->subtype == 1) // mailscrolls
1278 } 1250 {
1279 else 1251 newbook->name = item->name;
1252 newbook->name_pl = item->name_pl;
1280 { 1253 }
1281 item->msg = buf;
1282 /* This shouldn't be necessary - the object hasn't changed in any
1283 * visible way
1284 */
1285 /* esrv_send_item(pl, item); */
1286 }
1287 1254
1255 pl->insert (newbook);
1256
1257 pl->contr->play_sound (sound_find ("inscribe_success"));
1288 new_draw_info_format (NDI_UNIQUE, 0, pl, "You write in the %s.", query_short_name (item)); 1258 new_draw_info_format (NDI_UNIQUE, 0, pl, "You write in the %s.", &item->name);
1289 return strlen (msg); 1259 return strlen (msg);
1290 } 1260 }
1291 else 1261 else
1292 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your message won't fit in the %s!", query_short_name (item)); 1262 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your message won't fit in the %s!", &item->name);
1293 1263
1294 return 0; 1264 return 0;
1295} 1265}
1296 1266
1297/* write_scroll() - this routine allows players to inscribe spell scrolls 1267/* write_scroll() - this routine allows players to inscribe spell scrolls
1298 * of spells which they know. Backfire effects are possible with the 1268 * of spells which they know. Backfire effects are possible with the
1299 * severity of the backlash correlated with the difficulty of the scroll 1269 * severity of the backlash correlated with the difficulty of the scroll
1300 * that is attempted. -b.t. thomas@astro.psu.edu 1270 * that is attempted. -b.t. thomas@astro.psu.edu
1301 */ 1271 */
1302
1303static int 1272static int
1304write_scroll (object *pl, object *scroll, object *skill) 1273write_scroll (object *pl, object *scroll, object *skill)
1305{ 1274{
1306 int success = 0, confused = 0; 1275 int success = 0, confused = 0;
1307 object *newscroll, *chosen_spell, *tmp;
1308
1309 /* this is a sanity check */
1310 if (scroll->type != SCROLL)
1311 {
1312 new_draw_info (NDI_UNIQUE, 0, pl, "A spell can only be inscribed into a scroll!");
1313 return 0;
1314 }
1315 1276
1316 /* Check if we are ready to attempt inscription */ 1277 /* Check if we are ready to attempt inscription */
1317 chosen_spell = pl->contr->ranged_ob; 1278 object *chosen_spell = pl->contr->ranged_ob;
1279
1318 if (!chosen_spell || chosen_spell->type != SPELL) 1280 if (!chosen_spell || chosen_spell->type != SPELL)
1319 { 1281 {
1320 new_draw_info (NDI_UNIQUE, 0, pl, "You need a spell readied in order to inscribe!"); 1282 new_draw_info (NDI_UNIQUE, 0, pl, "You need a spell readied in order to inscribe!");
1321 return 0; 1283 return 0;
1322 } 1284 }
1328 } 1290 }
1329 1291
1330 if (SP_level_spellpoint_cost (pl, chosen_spell, SPELL_MANA) > pl->stats.sp) 1292 if (SP_level_spellpoint_cost (pl, chosen_spell, SPELL_MANA) > pl->stats.sp)
1331 { 1293 {
1332 new_draw_info_format (NDI_UNIQUE, 0, pl, "You don't have enough mana to write a scroll of %s.", &chosen_spell->name); 1294 new_draw_info_format (NDI_UNIQUE, 0, pl, "You don't have enough mana to write a scroll of %s.", &chosen_spell->name);
1333 return 0;
1334 }
1335
1336 /* if there is a spell already on the scroll then player could easily
1337 * accidently read it while trying to write the new one. give player
1338 * a 50% chance to overwrite spell at their own level
1339 */
1340 if ((scroll->stats.sp || scroll->inv) && random_roll (0, scroll->level * 2, pl, PREFER_LOW) > skill->level)
1341 {
1342 new_draw_info_format (NDI_UNIQUE, 0, pl, "Oops! You accidently read it while trying to write on it.");
1343 manual_apply (pl, scroll, 0);
1344 return 0; 1295 return 0;
1345 } 1296 }
1346 1297
1347 /* ok, we are ready to try inscription */ 1298 /* ok, we are ready to try inscription */
1348 if (QUERY_FLAG (pl, FLAG_CONFUSED)) 1299 if (QUERY_FLAG (pl, FLAG_CONFUSED))
1352 pl->stats.grace -= SP_level_spellpoint_cost (pl, chosen_spell, SPELL_GRACE); 1303 pl->stats.grace -= SP_level_spellpoint_cost (pl, chosen_spell, SPELL_GRACE);
1353 pl->stats.sp -= SP_level_spellpoint_cost (pl, chosen_spell, SPELL_MANA); 1304 pl->stats.sp -= SP_level_spellpoint_cost (pl, chosen_spell, SPELL_MANA);
1354 1305
1355 if (random_roll (0, chosen_spell->level * 4 - 1, pl, PREFER_LOW) < skill->level) 1306 if (random_roll (0, chosen_spell->level * 4 - 1, pl, PREFER_LOW) < skill->level)
1356 { 1307 {
1357 if (scroll->nrof > 1) 1308 object *newscroll = arch_to_object (scroll->other_arch);
1358 { 1309 scroll->decrease ();
1359 newscroll = scroll->clone ();
1360 decrease_ob (scroll);
1361 newscroll->nrof = 1; 1310 newscroll->nrof = 1;
1362 } 1311
1363 else 1312 pl->contr->play_sound (sound_find ("inscribe_success"));
1364 newscroll = scroll;
1365 1313
1366 if (!confused) 1314 if (!confused)
1367 { 1315 {
1368 newscroll->level = MAX (skill->level, chosen_spell->level); 1316 newscroll->level = MAX (skill->level, chosen_spell->level);
1317 newscroll->flag [FLAG_IDENTIFIED] = true;
1369 new_draw_info (NDI_UNIQUE, 0, pl, "You succeed in writing a new scroll."); 1318 new_draw_info (NDI_UNIQUE, 0, pl, "You succeed in writing the spell.");
1370 } 1319 }
1371 else 1320 else
1372 { 1321 {
1373 chosen_spell = find_random_spell_in_ob (pl, NULL); 1322 chosen_spell = find_random_spell_in_ob (pl, NULL);
1374 if (!chosen_spell) 1323 if (!chosen_spell)
1376 1325
1377 newscroll->level = MAX (skill->level, chosen_spell->level); 1326 newscroll->level = MAX (skill->level, chosen_spell->level);
1378 new_draw_info (NDI_UNIQUE, 0, pl, "In your confused state, you write down some odd spell."); 1327 new_draw_info (NDI_UNIQUE, 0, pl, "In your confused state, you write down some odd spell.");
1379 } 1328 }
1380 1329
1381 if (newscroll->inv)
1382 newscroll->inv->destroy ();
1383
1384 tmp = chosen_spell->clone (); 1330 object *tmp = chosen_spell->clone ();
1385 insert_ob_in_ob (tmp, newscroll); 1331 insert_ob_in_ob (tmp, newscroll);
1386 1332
1387 /* Same code as from treasure.c - so they can better merge. 1333 /* Same code as from treasure.C - so they can better merge.
1388 * if players want to sell them, so be it. 1334 * if players want to sell them, so be it.
1389 */ 1335 */
1390 newscroll->value = newscroll->arch->value * newscroll->inv->value * (newscroll->level + 50) / (newscroll->inv->level + 50); 1336 newscroll->value = newscroll->arch->value * newscroll->inv->value * (newscroll->level + 50) / (newscroll->inv->level + 50);
1391 newscroll->stats.exp = newscroll->value / 5; 1337 newscroll->stats.exp = newscroll->value / 5;
1392 1338
1393 /* wait until finished manipulating the scroll before inserting it */ 1339 pl->insert (newscroll);
1394 if (newscroll == scroll)
1395 {
1396 /* Remove to correctly merge with other items which may exist in inventory */
1397 newscroll->remove ();
1398 esrv_del_item (pl->contr, newscroll->count);
1399 }
1400 1340
1401 newscroll = insert_ob_in_ob (newscroll, pl);
1402 esrv_send_item (pl, newscroll);
1403 success = calc_skill_exp (pl, newscroll, skill); 1341 success = calc_skill_exp (pl, newscroll, skill);
1404 if (!confused) 1342 if (!confused)
1405 success *= 2; 1343 success *= 2;
1344
1406 success = success * skill->level; 1345 success = success * skill->level;
1407 return success; 1346 return success;
1408
1409 } 1347 }
1410 else 1348 else
1411 { /* Inscription has failed */ 1349 { /* Inscription has failed */
1350 pl->contr->play_sound (sound_find ("inscribe_fail"));
1412 1351
1413 if (chosen_spell->level > skill->level || confused) 1352 if (chosen_spell->level > skill->level || confused)
1414 { /*backfire! */ 1353 { /*backfire! */
1415 new_draw_info (NDI_UNIQUE, 0, pl, "Ouch! Your attempt to write a new scroll strains your mind!"); 1354 new_draw_info (NDI_UNIQUE, 0, pl, "Ouch! Your attempt to write a new scroll strains your mind!");
1355
1416 if (random_roll (0, 1, pl, PREFER_LOW) == 1) 1356 if (random_roll (0, 1, pl, PREFER_LOW) == 1)
1417 pl->drain_specific_stat (4); 1357 pl->drain_specific_stat (4);
1418 else 1358 else
1419 { 1359 {
1420 confuse_player (pl, pl, 99); 1360 confuse_player (pl, pl, 99);
1421 return (-30 * chosen_spell->level); 1361 return -30 * chosen_spell->level;
1422 } 1362 }
1423 } 1363 }
1424 else if (random_roll (0, pl->stats.Int - 1, pl, PREFER_HIGH) < 15) 1364 else if (random_roll (0, pl->stats.Int - 1, pl, PREFER_HIGH) < 15)
1425 { 1365 {
1426 new_draw_info (NDI_UNIQUE, 0, pl, "Your attempt to write a new scroll rattles your mind!"); 1366 new_draw_info (NDI_UNIQUE, 0, pl, "Your attempt to write a new scroll rattles your mind! H<Frankly spoken, you were too dumb and unlucky.>");
1427 confuse_player (pl, pl, 99); 1367 confuse_player (pl, pl, 99);
1428 } 1368 }
1429 else 1369 else
1430 new_draw_info (NDI_UNIQUE, 0, pl, "You fail to write a new scroll."); 1370 new_draw_info (NDI_UNIQUE, 0, pl, "You fail to write a new scroll. H<Try a lower-level spell, if possible at all.>");
1431 } 1371 }
1432 1372
1433 return 0; 1373 return 0;
1434} 1374}
1435 1375
1436/* write_on_item() - wrapper for write_note and write_scroll */ 1376/* write_on_item() - wrapper for write_note and write_scroll */
1437int 1377int
1438write_on_item (object *pl, const char *params, object *skill) 1378write_on_item (object *pl, const char *params, object *skill)
1439{ 1379{
1440 object *item;
1441 const char *string = params;
1442 int msgtype;
1443 archetype *skat; 1380 archetype *skat;
1444 1381
1445 if (pl->type != PLAYER) 1382 if (pl->type != PLAYER)
1446 return 0; 1383 return 0;
1447 1384
1448 if (!params) 1385 if (!params)
1449 {
1450 params = ""; 1386 params = "";
1451 string = params;
1452 }
1453 1387
1454 skat = get_archetype_by_type_subtype (SKILL, SK_LITERACY); 1388 skat = get_archetype_by_type_subtype (SKILL, SK_LITERACY);
1455 1389
1456 /* Need to be able to read before we can write! */ 1390 /* Need to be able to read before we can write! */
1457 if (!find_skill_by_name (pl, skat->skill)) 1391 if (!find_skill_by_name (pl, skat->skill))
1458 { 1392 {
1459 new_draw_info (NDI_UNIQUE, 0, pl, "You must learn to read before you can write!"); 1393 new_draw_info (NDI_UNIQUE, 0, pl, "You must learn to read before you can write! H<You lack the literacy skill.>");
1460 return 0; 1394 return 0;
1461 } 1395 }
1462 1396
1463 /* if there is a message then it goes in a book and no message means 1397 object *item = find_marked_object (pl);
1464 * write active spell into the scroll
1465 */
1466 msgtype = (string[0] != '\0') ? BOOK : SCROLL;
1467 1398
1468 /* find an item of correct type to write on */ 1399 /* find an item of correct type to write on */
1469 if (!(item = find_marked_object (pl))) 1400 if (!item)
1401 {
1402 new_draw_info (NDI_UNIQUE, 0, pl, "You don't have any marked item to write on. H<Use the mark command or the popup menu to make an item.>");
1403 return 0;
1470 { 1404 }
1471 new_draw_info (NDI_UNIQUE, 0, pl, "You don't have any marked item to write on."); 1405
1406 if (item->type != INSCRIBABLE)
1407 {
1408 new_draw_info_format (NDI_UNIQUE, 0, pl, "You cannot inscribe this! H<You can only inscribe empty scrolls and books.>");
1472 return 0; 1409 return 0;
1473 } 1410 }
1474 1411
1475 if (QUERY_FLAG (item, FLAG_UNPAID)) 1412 if (QUERY_FLAG (item, FLAG_UNPAID))
1476 { 1413 {
1477 new_draw_info (NDI_UNIQUE, 0, pl, "You had better pay for that before you write on it."); 1414 new_draw_info (NDI_UNIQUE, 0, pl, "You had better pay for that before you write on it.");
1478 return 0; 1415 return 0;
1479 } 1416 }
1480 if (msgtype != item->type) 1417
1418 if (item->other_arch->type == SCROLL)
1481 { 1419 {
1482 new_draw_info_format (NDI_UNIQUE, 0, pl, "You have no %s to write on", msgtype == BOOK ? "book" : "scroll"); 1420 if (*params)
1421 {
1422 // check readied scroll
1423 new_draw_info_format (NDI_UNIQUE, 0, pl,
1424 "When inscribing spells you need to ready a spell and do not specify a string argument.\n"
1425 "Usage: cast [spell name]; use_skill %s", &skill->skill);
1483 return 0; 1426 return 0;
1484 } 1427 }
1485 1428
1486 if (msgtype == SCROLL)
1487 return write_scroll (pl, item, skill); 1429 return write_scroll (pl, item, skill);
1488 else if (msgtype == BOOK) 1430 }
1431 else
1432 {
1433 if (!*params)
1434 {
1435 new_draw_info_format (NDI_UNIQUE, 0, pl,
1436 "When inscribing books you need to specify the words you want to inscribe as command argument.\n"
1437 "Usage: use_skill %s <message>", &skill->skill);
1438 return 0;
1439 }
1440
1489 return write_note (pl, item, string, skill); 1441 return write_note (pl, item, params, skill);
1442 }
1490 1443
1491 return 0; 1444 return 0;
1492} 1445}
1493 1446
1494/* find_throw_ob() - if we request an object, then 1447/* find_throw_ob() - if we request an object, then
1527 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1480 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
1528 { 1481 {
1529 /* can't toss invisible or inv-locked items */ 1482 /* can't toss invisible or inv-locked items */
1530 if (tmp->invisible || QUERY_FLAG (tmp, FLAG_INV_LOCKED)) 1483 if (tmp->invisible || QUERY_FLAG (tmp, FLAG_INV_LOCKED))
1531 continue; 1484 continue;
1532 if (!request || !strcmp (query_name (tmp), request) || !strcmp (tmp->name, request)) 1485 if (!request || !strcmp (query_name (tmp), request) || !strcmp (&tmp->name, request))
1533 break; 1486 break;
1534 } 1487 }
1535 } 1488 }
1536 1489
1537 /* this should prevent us from throwing away 1490 /* this should prevent us from throwing away
1576 return tmp; 1529 return tmp;
1577} 1530}
1578 1531
1579/* make_throw_ob() We construct the 'carrier' object in 1532/* make_throw_ob() We construct the 'carrier' object in
1580 * which we will insert the object that is being thrown. 1533 * which we will insert the object that is being thrown.
1581 * This combination becomes the 'thrown object'. -b.t. 1534 * This combination becomes the 'thrown object'. -b.t.
1582 */ 1535 */
1583static object * 1536static object *
1584make_throw_ob (object *orig) 1537make_throw_ob (object *orig)
1585{ 1538{
1586 if (!orig) 1539 if (!orig)
1587 return NULL; 1540 return 0;
1588 1541
1589 if (QUERY_FLAG (orig, FLAG_APPLIED)) 1542 if (QUERY_FLAG (orig, FLAG_APPLIED))
1590 { 1543 {
1591 LOG (llevError, "BUG: make_throw_ob(): ob is applied\n"); 1544 LOG (llevError, "BUG: make_throw_ob(): ob is applied\n");
1592 /* insufficient workaround, but better than nothing */ 1545 /* insufficient workaround, but better than nothing */
1596 object *toss_item = orig->clone (); 1549 object *toss_item = orig->clone ();
1597 1550
1598 toss_item->type = THROWN_OBJ; 1551 toss_item->type = THROWN_OBJ;
1599 CLEAR_FLAG (toss_item, FLAG_CHANGING); 1552 CLEAR_FLAG (toss_item, FLAG_CHANGING);
1600 toss_item->stats.dam = 0; /* default damage */ 1553 toss_item->stats.dam = 0; /* default damage */
1601 insert_ob_in_ob (orig, toss_item); 1554 toss_item->insert (orig);
1555
1602 return toss_item; 1556 return toss_item;
1603} 1557}
1604 1558
1605/* do_throw() - op throws any object toss_item. This code 1559/* do_throw() - op throws any object toss_item. This code
1606 * was borrowed from fire_bow. 1560 * was borrowed from fire_bow.
1699 left = throw_ob; /* these are throwing objects left to the player */ 1653 left = throw_ob; /* these are throwing objects left to the player */
1700 1654
1701 /* sometimes get_split_ob can't split an object (because op->nrof==0?) 1655 /* sometimes get_split_ob can't split an object (because op->nrof==0?)
1702 * and returns NULL. We must use 'left' then 1656 * and returns NULL. We must use 'left' then
1703 */ 1657 */
1704 1658 if (!(throw_ob = throw_ob->split ()))
1705 if ((throw_ob = get_split_ob (throw_ob, 1)) == NULL)
1706 { 1659 {
1707 throw_ob = left; 1660 throw_ob = left;
1708 left->remove (); 1661 left->remove ();
1709 if (op->type == PLAYER)
1710 esrv_del_item (op->contr, left->count);
1711 }
1712 else if (op->type == PLAYER)
1713 {
1714 if (left->destroyed ())
1715 esrv_del_item (op->contr, left->count);
1716 else
1717 esrv_update_item (UPD_NROF, op, left);
1718 } 1662 }
1719 1663
1720 /* special case: throwing powdery substances like dust, dirt */ 1664 /* special case: throwing powdery substances like dust, dirt */
1721 if (throw_ob->type == POTION && throw_ob->subtype == POT_DUST) 1665 if (throw_ob->type == POTION && throw_ob->subtype == POT_DUST)
1722 { 1666 {
1746 */ 1690 */
1747 throw_ob->inv->set_owner (op); 1691 throw_ob->inv->set_owner (op);
1748 throw_ob->direction = dir; 1692 throw_ob->direction = dir;
1749 1693
1750 /* the damage bonus from the force of the throw */ 1694 /* the damage bonus from the force of the throw */
1751 dam = (int) (str_factor * dam_bonus[eff_str]); 1695 dam = int (str_factor * dam_bonus[eff_str]);
1752 1696
1753 /* Now, lets adjust the properties of the thrown_ob. */ 1697 /* Now, lets adjust the properties of the thrown_ob. */
1754 1698
1755 /* how far to fly */ 1699 /* how far to fly */
1756 throw_ob->last_sp = (eff_str * 3) / 5; 1700 throw_ob->last_sp = (eff_str * 3) / 5;
1777 { 1721 {
1778 throw_ob->last_sp += eff_str / 3; /* fly a little further */ 1722 throw_ob->last_sp += eff_str / 3; /* fly a little further */
1779 throw_ob->stats.dam += throw_ob->inv->stats.dam + throw_ob->magic + 2; 1723 throw_ob->stats.dam += throw_ob->inv->stats.dam + throw_ob->magic + 2;
1780 throw_ob->stats.wc -= throw_ob->magic + throw_ob->inv->stats.wc; 1724 throw_ob->stats.wc -= throw_ob->magic + throw_ob->inv->stats.wc;
1781 /* only throw objects get directional faces */ 1725 /* only throw objects get directional faces */
1782 if (GET_ANIM_ID (throw_ob) && NUM_ANIMATIONS (throw_ob)) 1726 if (throw_ob->has_anim () && throw_ob->anim_frames ())
1783 SET_ANIMATION (throw_ob, dir); 1727 throw_ob->set_anim_frame (dir);
1784 } 1728 }
1785 else 1729 else
1786 { 1730 {
1787 uint16 mat = throw_ob->materials; 1731 uint16 mat = throw_ob->materials;
1788 1732

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines