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

Comparing deliantra/server/server/time.C (file contents):
Revision 1.11 by root, Thu Sep 14 01:12:28 2006 UTC vs.
Revision 1.45 by root, Sun Apr 22 13:06:45 2007 UTC

1
2/* 1/*
3 * static char *rcsid_time_c = 2 * CrossFire, A Multiplayer game
4 * "$Id: time.C,v 1.11 2006/09/14 01:12:28 root Exp $"; 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
5 */ 23 */
6
7/*
8 CrossFire, A Multiplayer game for X-windows
9
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27 The authors can be reached via e-mail at crossfire-devel@real-time.com
28*/
29 24
30/* 25/*
31 * Routines that is executed from objects based on their speed have been 26 * Routines that is executed from objects based on their speed have been
32 * collected in this file. 27 * collected in this file.
33 */ 28 */
34
35#include <global.h> 29#include <global.h>
36#include <spells.h> 30#include <spells.h>
37#ifndef __CEXTRACT__
38# include <sproto.h> 31#include <sproto.h>
39#endif
40 32
41/* The following removes doors. The functions check to see if similar 33/* The following removes doors. The functions check to see if similar
42 * doors are next to the one that is being removed, and if so, set it 34 * doors are next to the one that is being removed, and if so, set it
43 * so those will be removed shortly (in a cascade like fashion.) 35 * so those will be removed shortly (in a cascade like fashion.)
44 */ 36 */
45
46void 37void
47remove_door (object *op) 38remove_door (object *op)
48{ 39{
49 int i; 40 int i;
50 object *tmp; 41 object *tmp;
51 42
52 for (i = 1; i < 9; i += 2) 43 for (i = 1; i < 9; i += 2)
53 if ((tmp = present (DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i])) != NULL) 44 if ((tmp = present (DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i])) != NULL)
54 { 45 {
55 tmp->speed = 0.1; 46 tmp->set_speed (0.1);
56 update_ob_speed (tmp);
57 tmp->speed_left = -0.2; 47 tmp->speed_left = -0.2;
58 } 48 }
59 49
60 if (op->other_arch) 50 if (op->other_arch)
61 { 51 {
64 tmp->y = op->y; 54 tmp->y = op->y;
65 tmp->map = op->map; 55 tmp->map = op->map;
66 tmp->level = op->level; 56 tmp->level = op->level;
67 insert_ob_in_map (tmp, op->map, op, 0); 57 insert_ob_in_map (tmp, op->map, op, 0);
68 } 58 }
69 remove_ob (op); 59
70 free_object (op); 60 op->destroy ();
71} 61}
72 62
73void 63void
74remove_door2 (object *op) 64remove_door2 (object *op)
75{ 65{
79 for (i = 1; i < 9; i += 2) 69 for (i = 1; i < 9; i += 2)
80 { 70 {
81 tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]); 71 tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]);
82 if (tmp && tmp->slaying == op->slaying) 72 if (tmp && tmp->slaying == op->slaying)
83 { /* same key both doors */ 73 { /* same key both doors */
84 tmp->speed = 0.1; 74 tmp->set_speed (0.1);
85 update_ob_speed (tmp);
86 tmp->speed_left = -0.2; 75 tmp->speed_left = -0.2;
87 } 76 }
88 } 77 }
78
89 if (op->other_arch) 79 if (op->other_arch)
90 { 80 {
91 tmp = arch_to_object (op->other_arch); 81 tmp = arch_to_object (op->other_arch);
92 tmp->x = op->x; 82 tmp->x = op->x;
93 tmp->y = op->y; 83 tmp->y = op->y;
94 tmp->map = op->map; 84 tmp->map = op->map;
95 tmp->level = op->level; 85 tmp->level = op->level;
96 insert_ob_in_map (tmp, op->map, op, 0); 86 insert_ob_in_map (tmp, op->map, op, 0);
97 } 87 }
98 remove_ob (op);
99 free_object (op);
100}
101 88
102/* Will generate a monster according to content 89 op->destroy ();
103 * of generator. 90}
104 */ 91
105void 92void
106generate_monster_inv (object *gen) 93generate_monster (object *gen)
107{ 94{
108 int i;
109 object *op, *head = NULL;
110
111 int qty = 0;
112
113 /* Code below assumes the generator is on a map, as it tries
114 * to place the monster on the map. So if the generator
115 * isn't on a map, complain and exit.
116 */
117 if (gen->map == NULL) 95 if (!gen->map)
118 {
119 //LOG(llevError,"Generator (%s) not on a map?\n", gen->name);
120 return;
121 }
122 /*First count numer of objects in inv */
123 for (op = gen->inv; op; op = op->below)
124 qty++;
125 if (!qty)
126 {
127 LOG (llevError, "Generator (%s) has no inventory in generate_monster_inv?\n", &gen->name);
128 return; /*No inventory */
129 }
130 qty = rndm (0, qty - 1);
131 for (op = gen->inv; qty; qty--)
132 op = op->below;
133 i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9);
134 if (i == -1)
135 return; 96 return;
136 head = object_create_clone (op);
137 CLEAR_FLAG (head, FLAG_IS_A_TEMPLATE);
138 unflag_inv (head, FLAG_IS_A_TEMPLATE);
139 if (rndm (0, 9))
140 generate_artifact (head, gen->map->difficulty);
141 insert_ob_in_map_at (head, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]);
142 if (QUERY_FLAG (head, FLAG_FREED))
143 return;
144 if (HAS_RANDOM_ITEMS (head))
145 create_treasure (head->randomitems, head, GT_APPLY, gen->map->difficulty, 0);
146}
147
148void
149generate_monster_arch (object *gen)
150{
151 int i;
152 object *op, *head = NULL, *prev = NULL;
153 archetype *at = gen->other_arch;
154
155 if (gen->other_arch == NULL)
156 {
157 //LOG(llevError,"Generator without other_arch: %s\n",gen->name);
158 return;
159 }
160 /* Code below assumes the generator is on a map, as it tries
161 * to place the monster on the map. So if the generator
162 * isn't on a map, complain and exit.
163 */
164 if (gen->map == NULL)
165 {
166 //LOG(llevError,"Generator (%s) not on a map?\n", gen->name);
167 return;
168 }
169 i = find_free_spot (&at->clone, gen->map, gen->x, gen->y, 1, 9);
170 if (i == -1)
171 return;
172 while (at != NULL)
173 {
174 op = arch_to_object (at);
175 op->x = gen->x + freearr_x[i] + at->clone.x;
176 op->y = gen->y + freearr_y[i] + at->clone.y;
177
178 if (head != NULL)
179 op->head = head, prev->more = op;
180
181 if (rndm (0, 9))
182 generate_artifact (op, gen->map->difficulty);
183 insert_ob_in_map (op, gen->map, gen, 0);
184 if (QUERY_FLAG (op, FLAG_FREED))
185 return;
186 if (HAS_RANDOM_ITEMS (op))
187 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty, 0);
188 if (head == NULL)
189 head = op;
190 prev = op;
191 at = at->more;
192 }
193}
194
195void
196generate_monster (object *gen)
197{
198 97
199 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) 98 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1))
200 return; 99 return;
100
101 object *op;
102
201 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) 103 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN))
202 generate_monster_inv (gen); 104 {
105 // either copy one item form the inventory...
106 if (!gen->inv)
107 return;
108
109 // first select one item from the inventory
110 int index = 0;
111 for (object *tmp = gen->inv; tmp; tmp = tmp->below)
112 if (!rndm (++index))
113 op = tmp;
114
115 op = object_create_clone (op);
116
117 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE);
118 unflag_inv (op, FLAG_IS_A_TEMPLATE);
119 }
203 else 120 else
204 generate_monster_arch (gen); 121 {
122 // ...or use other_arch
123 if (archetype *at = gen->other_arch)
124 op = arch_to_object (at);
125 else
126 return;
127 }
205 128
129 op->expand_tail ();
130
131 int i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9);
132 if (i >= 0)
133 {
134 if (insert_ob_in_map_at (op, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]))
135 {
136 if (rndm (0, 9))
137 generate_artifact (op, gen->map->difficulty);
138
139 if (op->has_random_items ())
140 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty);
141
142 return;
143 }
144 }
145
146 op->destroy ();
206} 147}
207 148
208void 149void
209remove_force (object *op) 150remove_force (object *op)
210{ 151{
211 if (--op->duration > 0) 152 if (--op->duration > 0)
212 return; 153 return;
213 154
155 if (op->env)
214 switch (op->subtype) 156 switch (op->subtype)
215 { 157 {
216 case FORCE_CONFUSION: 158 case FORCE_CONFUSION:
217 if (op->env != NULL)
218 {
219 CLEAR_FLAG (op->env, FLAG_CONFUSED); 159 CLEAR_FLAG (op->env, FLAG_CONFUSED);
220 new_draw_info (NDI_UNIQUE, 0, op->env, "You regain your senses.\n"); 160 new_draw_info (NDI_UNIQUE, 0, op->env, "You regain your senses.\n");
221 }
222 161
223 default: 162 default:
224 if (op->env != NULL)
225 {
226 CLEAR_FLAG (op, FLAG_APPLIED); 163 CLEAR_FLAG (op, FLAG_APPLIED);
227 change_abil (op->env, op); 164 change_abil (op->env, op);
228 fix_player (op->env); 165 op->env->update_stats ();
229 }
230 } 166 }
231 remove_ob (op); 167
232 free_object (op); 168 op->destroy ();
233} 169}
234 170
235void 171void
236remove_blindness (object *op) 172remove_blindness (object *op)
237{ 173{
238 if (--op->stats.food > 0) 174 if (--op->stats.food > 0)
239 return; 175 return;
176
240 CLEAR_FLAG (op, FLAG_APPLIED); 177 CLEAR_FLAG (op, FLAG_APPLIED);
178
241 if (op->env != NULL) 179 if (op->env)
242 { 180 {
243 change_abil (op->env, op); 181 change_abil (op->env, op);
244 fix_player (op->env); 182 op->env->update_stats ();
245 } 183 }
246 remove_ob (op); 184
247 free_object (op); 185 op->destroy ();
248} 186}
249 187
250void 188void
251poison_more (object *op) 189poison_more (object *op)
252{ 190{
253 if (op->env == NULL || !QUERY_FLAG (op->env, FLAG_ALIVE) || op->env->stats.hp < 0) 191 if (op->env == NULL || !QUERY_FLAG (op->env, FLAG_ALIVE) || op->env->stats.hp < 0)
254 { 192 {
255 remove_ob (op); 193 op->destroy ();
256 free_object (op);
257 return; 194 return;
258 } 195 }
196
259 if (op->stats.food == 1) 197 if (op->stats.food == 1)
260 { 198 {
261 /* need to remove the object before fix_player is called, else fix_player 199 /* need to unapply the object before update_stats is called, else fix_player
262 * will not do anything. 200 * will not do anything.
263 */ 201 */
264 if (op->env->type == PLAYER) 202 if (op->env->type == PLAYER)
265 { 203 {
266 CLEAR_FLAG (op, FLAG_APPLIED); 204 CLEAR_FLAG (op, FLAG_APPLIED);
267 fix_player (op->env); 205 op->env->update_stats ();
268 new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now."); 206 new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now.");
269 } 207 }
270 remove_ob (op); 208
271 free_object (op); 209 op->destroy ();
272 return; 210 return;
273 } 211 }
212
274 if (op->env->type == PLAYER) 213 if (op->env->type == PLAYER)
275 { 214 {
276 op->env->stats.food--; 215 op->env->stats.food--;
277 new_draw_info (NDI_UNIQUE, 0, op->env, "You feel very sick..."); 216 new_draw_info (NDI_UNIQUE, 0, op->env, "You feel very sick...");
278 } 217 }
218
279 (void) hit_player (op->env, op->stats.dam, op, AT_INTERNAL, 1); 219 hit_player (op->env, op->stats.dam, op, AT_INTERNAL, 1);
280} 220}
281 221
282 222
283void 223void
284move_gate (object *op) 224move_gate (object *op)
286 object *tmp; 226 object *tmp;
287 227
288 if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op)) 228 if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op))
289 { 229 {
290 LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op)); 230 LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op));
291 dump_object (op);
292 LOG (llevError, "%s\n", errmsg);
293 op->stats.wc = 0; 231 op->stats.wc = 0;
294 } 232 }
295 233
296 /* We're going down */ 234 /* We're going down */
297 if (op->value) 235 if (op->value)
300 { /* Reached bottom, let's stop */ 238 { /* Reached bottom, let's stop */
301 op->stats.wc = 0; 239 op->stats.wc = 0;
302 if (op->arch->clone.speed) 240 if (op->arch->clone.speed)
303 op->value = 0; 241 op->value = 0;
304 else 242 else
305 {
306 op->speed = 0; 243 op->set_speed (0);
307 update_ob_speed (op);
308 } 244 }
309 } 245
310 if ((int) op->stats.wc < (NUM_ANIMATIONS (op) / 2 + 1)) 246 if ((int) op->stats.wc < (NUM_ANIMATIONS (op) / 2 + 1))
311 { 247 {
312 op->move_block = 0; 248 op->move_block = 0;
313 CLEAR_FLAG (op, FLAG_BLOCKSVIEW); 249 CLEAR_FLAG (op, FLAG_BLOCKSVIEW);
314 update_all_los (op->map, op->x, op->y); 250 update_all_los (op->map, op->x, op->y);
315 } 251 }
252
316 SET_ANIMATION (op, op->stats.wc); 253 SET_ANIMATION (op, op->stats.wc);
317 update_object (op, UP_OBJ_CHANGE); 254 update_object (op, UP_OBJ_CHANGE);
318 return; 255 return;
319 } 256 }
320 257
337 if (tmp == NULL) 274 if (tmp == NULL)
338 { 275 {
339 if (op->arch->clone.speed) 276 if (op->arch->clone.speed)
340 op->value = 1; 277 op->value = 1;
341 else 278 else
342 {
343 op->speed = 0; 279 op->set_speed (0);
344 update_ob_speed (op); /* Reached top, let's stop */ 280
345 }
346 return; 281 return;
347 } 282 }
348 } 283 }
349 284
350 if (op->stats.food) 285 if (op->stats.food)
390 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); 325 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9);
391 326
392 /* If there is a free spot, move the object someplace */ 327 /* If there is a free spot, move the object someplace */
393 if (i != -1) 328 if (i != -1)
394 { 329 {
395 remove_ob (tmp); 330 tmp->remove ();
396 tmp->x += freearr_x[i], tmp->y += freearr_y[i]; 331 tmp->x += freearr_x[i], tmp->y += freearr_y[i];
397 insert_ob_in_map (tmp, op->map, op, 0); 332 insert_ob_in_map (tmp, op->map, op, 0);
398 } 333 }
399 } 334 }
400 } 335 }
441 } 376 }
442 if (--op->stats.hp <= 0) 377 if (--op->stats.hp <= 0)
443 { /* keep gate down */ 378 { /* keep gate down */
444 move_gate (op); 379 move_gate (op);
445 if (op->value != v) 380 if (op->value != v)
446 { /* ready ? */
447 op->speed = 0; 381 op->set_speed (0);
448 update_ob_speed (op);
449 }
450 } 382 }
451} 383}
452 384
453/* slaying: name of the thing the detector is to look for 385/* slaying: name of the thing the detector is to look for
454 * speed: frequency of 'glances' 386 * speed: frequency of 'glances'
464 int last = op->value; 396 int last = op->value;
465 int detected; 397 int detected;
466 398
467 detected = 0; 399 detected = 0;
468 400
469 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL && !detected; tmp = tmp->above) 401 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL && !detected; tmp = tmp->above)
470 { 402 {
471 object *tmp2; 403 object *tmp2;
472 404
473 if (op->stats.hp) 405 if (op->stats.hp)
474 { 406 {
475 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) 407 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
476 { 408 {
477 if (op->slaying && !strcmp (op->slaying, tmp->name)) 409 if (op->slaying && op->slaying == tmp->name)
478 detected = 1; 410 detected = 1;
411
479 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying)) 412 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying)
480 detected = 1; 413 detected = 1;
481 } 414 }
482 } 415 }
416
483 if (op->slaying && !strcmp (op->slaying, tmp->name)) 417 if (op->slaying && op->slaying == tmp->name)
484 {
485 detected = 1; 418 detected = 1;
486 }
487 else if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying) 419 else if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying)
488 detected = 1; 420 detected = 1;
489 } 421 }
490 422
491 /* the detector sets the button if detection is found */ 423 /* the detector sets the button if detection is found */
541 if (op->value) 473 if (op->value)
542 { /* We're opening */ 474 { /* We're opening */
543 if (--op->stats.wc <= 0) 475 if (--op->stats.wc <= 0)
544 { /* Opened, let's stop */ 476 { /* Opened, let's stop */
545 op->stats.wc = 0; 477 op->stats.wc = 0;
546 op->speed = 0; 478 op->set_speed (0);
547 update_ob_speed (op);
548 479
549 /* Hard coding this makes sense for holes I suppose */ 480 /* Hard coding this makes sense for holes I suppose */
550 op->move_on = MOVE_WALK; 481 op->move_on = MOVE_WALK;
551 for (tmp = op->above; tmp != NULL; tmp = next) 482 for (tmp = op->above; tmp != NULL; tmp = next)
552 { 483 {
553 next = tmp->above; 484 next = tmp->above;
554 move_apply (op, tmp, tmp); 485 move_apply (op, tmp, tmp);
555 } 486 }
556 } 487 }
488
557 SET_ANIMATION (op, op->stats.wc); 489 SET_ANIMATION (op, op->stats.wc);
558 update_object (op, UP_OBJ_FACE); 490 update_object (op, UP_OBJ_FACE);
559 return; 491 return;
560 } 492 }
561 /* We're closing */ 493 /* We're closing */
562 op->move_on = 0; 494 op->move_on = 0;
563 495
564 op->stats.wc++; 496 op->stats.wc++;
565 if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) 497 if ((int) op->stats.wc >= NUM_ANIMATIONS (op))
566 op->stats.wc = NUM_ANIMATIONS (op) - 1; 498 op->stats.wc = NUM_ANIMATIONS (op) - 1;
499
567 SET_ANIMATION (op, op->stats.wc); 500 SET_ANIMATION (op, op->stats.wc);
568 update_object (op, UP_OBJ_FACE); 501 update_object (op, UP_OBJ_FACE);
569 if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1)) 502 if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1))
570 {
571 op->speed = 0;
572 update_ob_speed (op); /* closed, let's stop */ 503 op->set_speed (0); /* closed, let's stop */
573 return;
574 }
575} 504}
576 505
577 506
578/* stop_item() returns a pointer to the stopped object. The stopped object 507/* stop_item() returns a pointer to the stopped object. The stopped object
579 * may or may not have been removed from maps or inventories. It will not 508 * may or may not have been removed from maps or inventories. It will not
599 { 528 {
600 object *payload = op->inv; 529 object *payload = op->inv;
601 530
602 if (payload == NULL) 531 if (payload == NULL)
603 return NULL; 532 return NULL;
604 remove_ob (payload); 533 payload->remove ();
605 remove_ob (op); 534 op->destroy ();
606 free_object (op);
607 return payload; 535 return payload;
608 } 536 }
609 537
610 case ARROW: 538 case ARROW:
611 if (op->speed >= MIN_ACTIVE_SPEED) 539 if (op->has_active_speed ())
612 op = fix_stopped_arrow (op); 540 op = fix_stopped_arrow (op);
613 return op; 541 return op;
614 542
615 default: 543 default:
616 return op; 544 return op;
621 * Inserts item into the old map, or merges it if it already is on the map. 549 * Inserts item into the old map, or merges it if it already is on the map.
622 * 550 *
623 * 'map' must be the value of op->map before stop_item() was called. 551 * 'map' must be the value of op->map before stop_item() was called.
624 */ 552 */
625void 553void
626fix_stopped_item (object *op, mapstruct *map, object *originator) 554fix_stopped_item (object *op, maptile *map, object *originator)
627{ 555{
628 if (map == NULL) 556 if (map == NULL)
629 return; 557 return;
558
630 if (QUERY_FLAG (op, FLAG_REMOVED)) 559 if (QUERY_FLAG (op, FLAG_REMOVED))
631 insert_ob_in_map (op, map, originator, 0); 560 insert_ob_in_map (op, map, originator, 0);
632 else if (op->type == ARROW) 561 else if (op->type == ARROW)
633 merge_ob (op, NULL); /* only some arrows actually need this */ 562 merge_ob (op, NULL); /* only some arrows actually need this */
634} 563}
635 564
636
637object * 565object *
638fix_stopped_arrow (object *op) 566fix_stopped_arrow (object *op)
639{ 567{
640 if (rndm (0, 99) < op->stats.food) 568 if (rndm (0, 99) < op->stats.food)
641 { 569 {
642 /* Small chance of breaking */ 570 /* Small chance of breaking */
643 remove_ob (op); 571 op->destroy ();
644 free_object (op);
645 return NULL; 572 return NULL;
646 } 573 }
647 574
575 op->set_speed (0);
648 op->direction = 0; 576 op->direction = 0;
649 op->move_on = 0; 577 op->move_on = 0;
650 op->move_type = 0; 578 op->move_type = 0;
651 op->speed = 0;
652 update_ob_speed (op);
653 op->stats.wc = op->stats.sp; 579 op->stats.wc = op->stats.sp;
654 op->stats.dam = op->stats.hp; 580 op->stats.dam = op->stats.hp;
655 op->attacktype = op->stats.grace; 581 op->attacktype = op->stats.grace;
656 op->slaying = 0; 582 op->slaying = 0;
657 op->skill = 0; 583 op->skill = 0;
663 op->spellarg = NULL; 589 op->spellarg = NULL;
664 } 590 }
665 else 591 else
666 op->slaying = NULL; 592 op->slaying = NULL;
667 593
668 /* Reset these to zero, so that CAN_MERGE will work properly */ 594 /* Reset these to zero, so that object::can_merge will work properly */
669 op->spellarg = NULL; 595 op->spellarg = NULL;
670 op->stats.sp = 0; 596 op->stats.sp = 0;
671 op->stats.hp = 0; 597 op->stats.hp = 0;
672 op->stats.grace = 0; 598 op->stats.grace = 0;
673 op->level = 0; 599 op->level = 0;
674 op->face = op->arch->clone.face; 600 op->face = op->arch->clone.face;
675 op->owner = NULL; /* So that stopped arrows will be saved */ 601 op->owner = NULL; /* So that stopped arrows will be saved */
676 update_object (op, UP_OBJ_FACE); 602 update_object (op, UP_OBJ_CHANGE);
677 return op; 603 return op;
678} 604}
679 605
680/* stop_arrow() - what to do when a non-living flying object 606/* stop_arrow() - what to do when a non-living flying object
681 * has to stop. Sept 96 - I added in thrown object code in 607 * has to stop. Sept 96 - I added in thrown object code in
682 * here too. -b.t. 608 * here too. -b.t.
683 * 609 *
684 * Returns a pointer to the stopped object (which will have been removed 610 * Returns a pointer to the stopped object (which will have been removed
685 * from maps or inventories), or NULL if was destroyed. 611 * from maps or inventories), or NULL if was destroyed.
686 */ 612 */
687
688static void 613static void
689stop_arrow (object *op) 614stop_arrow (object *op)
690{ 615{
691 if (INVOKE_OBJECT (STOP, op)) 616 if (INVOKE_OBJECT (STOP, op))
692 return; 617 return;
693 618
694 if (op->inv) 619 if (op->inv)
695 { 620 {
696 object *payload = op->inv; 621 object *payload = op->inv;
697 622
698 remove_ob (payload); 623 payload->remove ();
699 clear_owner (payload); 624 payload->owner = 0;
700 insert_ob_in_map (payload, op->map, payload, 0); 625 insert_ob_in_map (payload, op->map, payload, 0);
701 remove_ob (op); 626 op->destroy ();
702 free_object (op);
703 } 627 }
704 else 628 else
705 { 629 {
706 op = fix_stopped_arrow (op); 630 op = fix_stopped_arrow (op);
707 if (op) 631 if (op)
709 } 633 }
710} 634}
711 635
712/* Move an arrow along its course. op is the arrow or thrown object. 636/* Move an arrow along its course. op is the arrow or thrown object.
713 */ 637 */
714
715void 638void
716move_arrow (object *op) 639move_arrow (object *op)
717{ 640{
718 object *tmp; 641 object *tmp;
719 sint16 new_x, new_y; 642 sint16 new_x, new_y;
720 int was_reflected, mflags; 643 int was_reflected, mflags;
721 mapstruct *m; 644 maptile *m;
722 645
723 if (op->map == NULL) 646 if (op->map == NULL)
724 { 647 {
725 LOG (llevError, "BUG: Arrow had no map.\n"); 648 LOG (llevError, "BUG: Arrow had no map.\n");
726 remove_ob (op); 649 op->destroy ();
727 free_object (op);
728 return; 650 return;
729 } 651 }
730 652
731 /* we need to stop thrown objects at some point. Like here. */ 653 /* we need to stop thrown objects at some point. Like here. */
732 if (op->type == THROWN_OBJ) 654 if (op->type == THROWN_OBJ)
739 * bomb code, but there are potential other cases where that could happen, 661 * bomb code, but there are potential other cases where that could happen,
740 * and it is easy enough to clean it up here. 662 * and it is easy enough to clean it up here.
741 */ 663 */
742 if (op->inv == NULL) 664 if (op->inv == NULL)
743 { 665 {
744 remove_ob (op); 666 op->destroy ();
745 free_object (op);
746 return; 667 return;
747 } 668 }
669
748 if (op->last_sp-- < 0) 670 if (op->last_sp-- < 0)
749 { 671 {
750 stop_arrow (op); 672 stop_arrow (op);
751 return; 673 return;
752 } 674 }
775 } 697 }
776 698
777 /* only need to look for living creatures if this flag is set */ 699 /* only need to look for living creatures if this flag is set */
778 if (mflags & P_IS_ALIVE) 700 if (mflags & P_IS_ALIVE)
779 { 701 {
780 for (tmp = get_map_ob (m, new_x, new_y); tmp != NULL; tmp = tmp->above) 702 for (tmp = GET_MAP_OB (m, new_x, new_y); tmp != NULL; tmp = tmp->above)
781 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 703 if (QUERY_FLAG (tmp, FLAG_ALIVE))
782 break; 704 break;
783
784 705
785 /* Not really fair, but don't let monsters hit themselves with 706 /* Not really fair, but don't let monsters hit themselves with
786 * their own arrow - this can be because they fire it then 707 * their own arrow - this can be because they fire it then
787 * move into it. 708 * move into it.
788 */ 709 */
789
790 if (tmp != NULL && tmp != op->owner) 710 if (tmp && tmp != op->owner)
791 { 711 {
792 /* Found living object, but it is reflecting the missile. Update 712 /* Found living object, but it is reflecting the missile. Update
793 * as below. (Note that for living creatures there is a small 713 * as below. (Note that for living creatures there is a small
794 * chance that reflect_missile fails.) 714 * chance that reflect_missile fails.)
795 */ 715 */
796
797 if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) 716 if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10))
798 { 717 {
799
800 int number = op->face->number; 718 int number = op->face;
801 719
802 op->direction = absdir (op->direction + 4); 720 op->direction = absdir (op->direction + 4);
803 op->state = 0; 721 update_turn_face (op);
804 if (GET_ANIM_ID (op))
805 {
806 number += 4;
807 if (number > GET_ANIMATION (op, 8))
808 number -= 8;
809 op->face = &new_faces[number];
810 }
811 was_reflected = 1; /* skip normal movement calculations */ 722 was_reflected = 1; /* skip normal movement calculations */
812 } 723 }
813 else 724 else
814 { 725 {
815 /* Attack the object. */ 726 /* Attack the object. */
816 op = hit_with_arrow (op, tmp); 727 op = hit_with_arrow (op, tmp);
728
817 if (op == NULL) 729 if (!op)
818 return; 730 return;
819 } 731 }
820 } /* if this is not hitting its owner */ 732 } /* if this is not hitting its owner */
821 } /* if there is something alive on this space */ 733 } /* if there is something alive on this space */
822
823 734
824 if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))) 735 if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y)))
825 { 736 {
826 int retry = 0; 737 int retry = 0;
827 738
849 * that did the same thing. 760 * that did the same thing.
850 */ 761 */
851 while (retry < 2) 762 while (retry < 2)
852 { 763 {
853 int left, right, mflags; 764 int left, right, mflags;
854 mapstruct *m1; 765 maptile *m1;
855 sint16 x1, y1; 766 sint16 x1, y1;
856 767
857 retry++; 768 retry++;
858 769
859 /* Need to check for P_OUT_OF_MAP: if the arrow is tavelling 770 /* Need to check for P_OUT_OF_MAP: if the arrow is tavelling
899 SET_ANIMATION (op, op->direction); 810 SET_ANIMATION (op, op->direction);
900 } /* object is reflected */ 811 } /* object is reflected */
901 } /* object ran into a wall */ 812 } /* object ran into a wall */
902 813
903 /* Move the arrow. */ 814 /* Move the arrow. */
904 remove_ob (op); 815 op->remove ();
905 op->x = new_x; 816 op->x = new_x;
906 op->y = new_y; 817 op->y = new_y;
907 818
908 /* decrease the speed as it flies. 0.05 means a standard bow will shoot 819 /* decrease the speed as it flies. 0.05 means a standard bow will shoot
909 * about 17 squares. Tune as needed. 820 * about 17 squares. Tune as needed.
917 * Modified this routine to allow held objects. b.t. */ 828 * Modified this routine to allow held objects. b.t. */
918 829
919void 830void
920change_object (object *op) 831change_object (object *op)
921{ /* Doesn`t handle linked objs yet */ 832{ /* Doesn`t handle linked objs yet */
922 object *tmp, *env, *pl;
923 int i, j; 833 int i, j;
924 834
925 if (op->other_arch == NULL) 835 if (op->other_arch == NULL)
926 { 836 {
927 LOG (llevError, "Change object (%s) without other_arch error.\n", &op->name); 837 LOG (llevError, "Change object (%s) without other_arch error.\n", &op->name);
934 if (op->stats.food-- > 0) 844 if (op->stats.food-- > 0)
935 return; 845 return;
936 else 846 else
937 op->stats.food = 1; /* so 1 other_arch is made */ 847 op->stats.food = 1; /* so 1 other_arch is made */
938 } 848 }
849
850 object *pl = op->in_player ();
939 env = op->env; 851 object *env = op->env;
940 remove_ob (op); 852
853 op->remove ();
941 for (i = 0; i < NROFNEWOBJS (op); i++) 854 for (i = 0; i < NROFNEWOBJS (op); i++)
942 { 855 {
943 tmp = arch_to_object (op->other_arch); 856 object *tmp = arch_to_object (op->other_arch);
857
944 if (op->type == LAMP) 858 if (op->type == LAMP)
945 tmp->stats.food = op->stats.food - 1; 859 tmp->stats.food = op->stats.food - 1;
860
946 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ 861 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */
947 if (env) 862 if (env)
948 { 863 {
949 tmp->x = env->x, tmp->y = env->y; 864 tmp->x = env->x, tmp->y = env->y;
950 tmp = insert_ob_in_ob (tmp, env); 865 tmp = insert_ob_in_ob (tmp, env);
866
951 /* If this object is the players inventory, we need to tell the 867 /* If this object is the players inventory, we need to tell the
952 * client of the change. Insert_ob_in_map takes care of the 868 * client of the change. Insert_ob_in_map takes care of the
953 * updating the client, so we don't need to do that below. 869 * updating the client, so we don't need to do that below.
954 */ 870 */
955 if ((pl = is_player_inv (env)) != NULL) 871 if (pl)
956 { 872 {
957 esrv_del_item (pl->contr, op->count); 873 esrv_del_item (pl->contr, op->count);
958 esrv_send_item (pl, tmp); 874 esrv_send_item (pl, tmp);
959 } 875 }
960 } 876 }
961 else 877 else
962 { 878 {
963 j = find_first_free_spot (tmp, op->map, op->x, op->y); 879 j = find_first_free_spot (tmp, op->map, op->x, op->y);
964 if (j == -1) /* No free spot */ 880 if (j == -1) /* No free spot */
965 free_object (tmp); 881 tmp->destroy ();
966 else 882 else
967 { 883 {
968 tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; 884 tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j];
969 insert_ob_in_map (tmp, op->map, op, 0); 885 insert_ob_in_map (tmp, op->map, op, 0);
970 } 886 }
971 } 887 }
972 } 888 }
973 free_object (op); 889
890 op->destroy ();
974} 891}
975 892
976void 893void
977move_teleporter (object *op) 894move_teleporter (object *op)
978{ 895{
983 * there is an old multipart teleporter in which the other parts 900 * there is an old multipart teleporter in which the other parts
984 * have speed, we don't really want to call it twice for the same 901 * have speed, we don't really want to call it twice for the same
985 * function - in fact, as written below, part N would get called 902 * function - in fact, as written below, part N would get called
986 * N times without the speed check. 903 * N times without the speed check.
987 */ 904 */
988 if (op->more && FABS (op->more->speed) < MIN_ACTIVE_SPEED) 905 if (op->more && !op->more->has_active_speed ())
989 move_teleporter (op->more); 906 move_teleporter (op->more);
990 907
991 if (op->head) 908 if (op->head)
992 head = op->head; 909 head = op->head;
993 910
1004 if (tmp->type == PLAYER) 921 if (tmp->type == PLAYER)
1005 { 922 {
1006 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) 923 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp)))
1007 return; 924 return;
1008 925
1009 enter_exit (tmp, head); 926 tmp->enter_exit (head);
1010 } 927 }
1011 else 928 else
1012 /* Currently only players can transfer maps */ 929 /* Currently only players can transfer maps */
1013 return; 930 return;
1014 } 931 }
1015 else if (EXIT_X (head) || EXIT_Y (head)) 932 else if (EXIT_X (head) || EXIT_Y (head))
1016 { 933 {
1017 if (out_of_map (head->map, EXIT_X (head), EXIT_Y (head))) 934 if (out_of_map (head->map, EXIT_X (head), EXIT_Y (head)))
1018 { 935 {
1019 LOG (llevError, "Removed illegal teleporter.\n"); 936 LOG (llevError, "Removed illegal teleporter.\n");
1020 remove_ob (head); 937 head->destroy ();
1021 free_object (head);
1022 return; 938 return;
1023 } 939 }
940
1024 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) 941 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp)))
1025 return; 942 return;
943
1026 transfer_ob (tmp, EXIT_X (head), EXIT_Y (head), 0, head); 944 transfer_ob (tmp, EXIT_X (head), EXIT_Y (head), 0, head);
1027 } 945 }
1028 else 946 else
1029 { 947 {
1030 /* Random teleporter */ 948 /* Random teleporter */
1038/* This object will teleport someone to a different map 956/* This object will teleport someone to a different map
1039 and will also apply changes to the player from its inventory. 957 and will also apply changes to the player from its inventory.
1040 This was invented for giving classes, but there's no reason it 958 This was invented for giving classes, but there's no reason it
1041 can't be generalized. 959 can't be generalized.
1042*/ 960*/
1043
1044void 961void
1045move_player_changer (object *op) 962move_player_changer (object *op)
1046{ 963{
1047 object *player; 964 object *player;
1048 object *walk; 965 object *walk;
1049 char c;
1050 966
1051 if (!op->above || !EXIT_PATH (op)) 967 if (!op->above || !EXIT_PATH (op))
1052 return; 968 return;
1053 969
1054 /* This isn't all that great - means that the player_mover 970 /* This isn't all that great - means that the player_mover
1055 * needs to be on top. 971 * needs to be on top.
1056 */ 972 */
1057 if (op->above->type == PLAYER) 973 if (op->above->type == PLAYER)
1058 { 974 {
1059 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (player))) 975 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (player)))
1060 return; 976 return;
977
1061 player = op->above; 978 player = op->above;
1062 979
1063 for (walk = op->inv; walk != NULL; walk = walk->below) 980 for (walk = op->inv; walk; walk = walk->below)
1064 apply_changes_to_player (player, walk); 981 apply_changes_to_player (player, walk);
1065 982
1066 fix_player (player); 983 player->update_stats ();
1067 984
1068 esrv_send_inventory (op->above, op->above); 985 esrv_send_inventory (op->above, op->above);
1069 esrv_update_item (UPD_FACE, op->above, op->above); 986 esrv_update_item (UPD_FACE, op->above, op->above);
1070 987
1071 /* update players death & WoR home-position */ 988 /* update players death & WoR home-position */
1072 sscanf (EXIT_PATH (op), "%c", &c); 989 if (*EXIT_PATH (op) == '/')
1073 if (c == '/')
1074 { 990 {
1075 strcpy (player->contr->savebed_map, EXIT_PATH (op)); 991 player->contr->savebed_map = EXIT_PATH (op);
1076 player->contr->bed_x = EXIT_X (op); 992 player->contr->bed_x = EXIT_X (op);
1077 player->contr->bed_y = EXIT_Y (op); 993 player->contr->bed_y = EXIT_Y (op);
1078 } 994 }
1079 else 995 else
1080 LOG (llevDebug, "WARNING: destination '%s' in player_changer must be an absolute path!\n", &EXIT_PATH (op)); 996 LOG (llevDebug, "WARNING: destination '%s' in player_changer must be an absolute path!\n", &EXIT_PATH (op));
1081 997
1082 enter_exit (op->above, op); 998 op->above->enter_exit (op);
1083 save_player (player, 1);
1084 } 999 }
1085} 1000}
1086 1001
1087/* firewalls fire other spells. 1002/* firewalls fire other spells.
1088 * The direction of the wall is stored in op->stats.sp. 1003 * The direction of the wall is stored in op->stats.sp.
1095 1010
1096 if (!op->map) 1011 if (!op->map)
1097 return; /* dm has created a firewall in his inventory */ 1012 return; /* dm has created a firewall in his inventory */
1098 1013
1099 spell = op->inv; 1014 spell = op->inv;
1015
1100 if (!spell || spell->type != SPELL) 1016 if (!spell || spell->type != SPELL)
1101 spell = &op->other_arch->clone; 1017 spell = &op->other_arch->clone;
1018
1102 if (!spell) 1019 if (!spell)
1103 { 1020 {
1104 LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, op->map->name, op->x, op->y); 1021 LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, &op->map->name, op->x, op->y);
1105 return; 1022 return;
1106 } 1023 }
1107 1024
1108 cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL); 1025 cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL);
1109} 1026}
1110
1111 1027
1112/* move_player_mover: this function takes a "player mover" as an 1028/* move_player_mover: this function takes a "player mover" as an
1113 * argument, and performs the function of a player mover, which is: 1029 * argument, and performs the function of a player mover, which is:
1114 * 1030 *
1115 * a player mover finds any players that are sitting on it. It 1031 * a player mover finds any players that are sitting on it. It
1122move_player_mover (object *op) 1038move_player_mover (object *op)
1123{ 1039{
1124 object *victim, *nextmover; 1040 object *victim, *nextmover;
1125 int dir = op->stats.sp; 1041 int dir = op->stats.sp;
1126 sint16 nx, ny; 1042 sint16 nx, ny;
1127 mapstruct *m; 1043 maptile *m;
1128 1044
1129 /* Determine direction now for random movers so we do the right thing */ 1045 /* Determine direction now for random movers so we do the right thing */
1130 if (!dir) 1046 if (!dir)
1131 dir = rndm (1, 8); 1047 dir = rndm (1, 8);
1132 1048
1133 for (victim = get_map_ob (op->map, op->x, op->y); victim != NULL; victim = victim->above) 1049 for (victim = GET_MAP_OB (op->map, op->x, op->y); victim != NULL; victim = victim->above)
1134 { 1050 {
1135 if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_WIZPASS) && 1051 if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_WIZPASS) &&
1136 (victim->move_type & op->move_type || !victim->move_type)) 1052 (victim->move_type & op->move_type || !victim->move_type))
1137 { 1053 {
1138 1054
1139 if (victim->head) 1055 if (victim->head)
1140 victim = victim->head; 1056 victim = victim->head;
1141 1057
1142 if (QUERY_FLAG (op, FLAG_LIFESAVE) && op->stats.hp-- < 0) 1058 if (QUERY_FLAG (op, FLAG_LIFESAVE) && op->stats.hp-- < 0)
1143 { 1059 {
1144 remove_ob (op); 1060 op->remove ();
1145 free_object (op);
1146 return; 1061 return;
1147 } 1062 }
1063
1148 nx = op->x + freearr_x[dir]; 1064 nx = op->x + freearr_x[dir];
1149 ny = op->y + freearr_y[dir]; 1065 ny = op->y + freearr_y[dir];
1150 m = op->map; 1066 m = op->map;
1151 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) 1067 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP)
1152 { 1068 {
1153 LOG (llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", m->path, op->x, op->y); 1069 LOG (llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", &m->path, op->x, op->y);
1154 return; 1070 return;
1155 } 1071 }
1156 1072
1157 if (should_director_abort (op, victim)) 1073 if (should_director_abort (op, victim))
1158 return; 1074 return;
1159 1075
1160 for (nextmover = get_map_ob (m, nx, ny); nextmover != NULL; nextmover = nextmover->above) 1076 for (nextmover = GET_MAP_OB (m, nx, ny); nextmover != NULL; nextmover = nextmover->above)
1161 { 1077 {
1162 if (nextmover->type == PLAYERMOVER) 1078 if (nextmover->type == PLAYERMOVER)
1163 nextmover->speed_left = -.99; 1079 nextmover->speed_left = -.99;
1164 if (QUERY_FLAG (nextmover, FLAG_ALIVE)) 1080 if (QUERY_FLAG (nextmover, FLAG_ALIVE))
1165 { 1081 {
1219{ 1135{
1220 object *tmp; 1136 object *tmp;
1221 1137
1222 if (!op->other_arch) 1138 if (!op->other_arch)
1223 { 1139 {
1224 LOG (llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? op->map->path : "nullmap"); 1140 LOG (llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? &op->map->path : "nullmap");
1225 return; 1141 return;
1226 } 1142 }
1227 1143
1228 if (op->above == NULL) 1144 if (op->above == NULL)
1229 return; 1145 return;
1146
1230 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 1147 for (tmp = op->above; tmp; tmp = tmp->above)
1231 { 1148 {
1232 if (strcmp (op->other_arch->name, tmp->arch->name) == 0) 1149 if (op->other_arch->name == tmp->arch->name)
1233 { 1150 {
1234 if (op->level <= 0) 1151 if (op->level <= 0)
1235 { 1152 tmp->destroy ();
1236 remove_ob (tmp);
1237 free_object (tmp);
1238 }
1239 else 1153 else
1240 { 1154 {
1241 uint64 new_nrof = (uint64) tmp->nrof * op->level; 1155 uint64 new_nrof = (uint64) tmp->nrof * op->level;
1242 1156
1243 if (new_nrof >= 1UL << 31) 1157 if (new_nrof >= 1UL << 31)
1244 new_nrof = 1UL << 31; 1158 new_nrof = 1UL << 31;
1159
1245 tmp->nrof = new_nrof; 1160 tmp->nrof = new_nrof;
1246 } 1161 }
1162
1247 break; 1163 break;
1248 } 1164 }
1249 } 1165 }
1250} 1166}
1251 1167
1295 } 1211 }
1296 else 1212 else
1297 { 1213 {
1298 if (creator->other_arch == NULL) 1214 if (creator->other_arch == NULL)
1299 { 1215 {
1300 LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", &creator->name, creator->map->path, 1216 LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n",
1301 creator->x, creator->y); 1217 &creator->name, &creator->map->path, creator->x, creator->y);
1302 return; 1218 return;
1303 } 1219 }
1304 1220
1305 new_ob = object_create_arch (creator->other_arch); 1221 new_ob = object_create_arch (creator->other_arch);
1306 fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); 1222 fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL);
1307 } 1223 }
1308 1224
1309 /* Make sure this multipart object fits */ 1225 /* Make sure this multipart object fits */
1310 if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y)) 1226 if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y))
1311 { 1227 {
1312 free_object (new_ob); 1228 new_ob->destroy ();
1313 return; 1229 return;
1314 } 1230 }
1315 1231
1316 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); 1232 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y);
1317 if (QUERY_FLAG (new_ob, FLAG_FREED)) 1233 if (QUERY_FLAG (new_ob, FLAG_FREED))
1329 with a specific code as the slaying field. 1245 with a specific code as the slaying field.
1330 At that time, it writes the contents of its own message 1246 At that time, it writes the contents of its own message
1331 field to the player. The marker will decrement hp to 1247 field to the player. The marker will decrement hp to
1332 0 and then delete itself every time it grants a mark. 1248 0 and then delete itself every time it grants a mark.
1333 unless hp was zero to start with, in which case it is infinite.*/ 1249 unless hp was zero to start with, in which case it is infinite.*/
1334
1335void 1250void
1336move_marker (object *op) 1251move_marker (object *op)
1337{ 1252{
1253 if (object *tmp = op->ms ().player ())
1254 {
1338 object *tmp, *tmp2; 1255 object *tmp2;
1339 1256
1340 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above)
1341 {
1342 if (tmp->type == PLAYER)
1343 { /* we've got someone to MARK */
1344
1345 /* remove an old force with a slaying field == op->name */ 1257 /* remove an old force with a slaying field == op->name */
1346 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) 1258 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1259 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->name)
1347 { 1260 {
1348 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->name)) 1261 tmp2->destroy ();
1349 break; 1262 break;
1350 } 1263 }
1351 1264
1352 if (tmp2)
1353 {
1354 remove_ob (tmp2);
1355 free_object (tmp2);
1356 }
1357
1358 /* cycle through his inventory to look for the MARK we want to 1265 /* cycle through his inventory to look for the MARK we want to
1359 * place 1266 * place
1360 */ 1267 */
1361 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) 1268 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1362 {
1363 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying)) 1269 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying)
1364 break; 1270 break;
1365 }
1366 1271
1367 /* if we didn't find our own MARK */ 1272 /* if we didn't find our own MARK */
1368 if (tmp2 == NULL) 1273 if (!tmp2)
1369 { 1274 {
1370 object *force = get_archetype (FORCE_NAME); 1275 object *force = get_archetype (FORCE_NAME);
1371 1276
1372 force->speed = 0;
1373 if (op->stats.food) 1277 if (op->stats.food)
1278 {
1279 force->set_speed (0.01);
1280 force->speed_left = -op->stats.food;
1281 }
1282 else
1283 force->set_speed (0);
1284
1285 /* put in the lock code */
1286 force->slaying = op->slaying;
1287
1288 if (op->lore)
1289 force->lore = op->lore;
1290
1291 insert_ob_in_ob (force, tmp);
1292 if (op->msg)
1293 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg);
1294
1295 if (op->stats.hp > 0)
1296 {
1297 op->stats.hp--;
1298 if (op->stats.hp == 0)
1374 { 1299 {
1375 force->speed = 0.01; 1300 /* marker expires--granted mark number limit */
1376 force->speed_left = -op->stats.food; 1301 op->destroy ();
1302 return;
1377 } 1303 }
1378 update_ob_speed (force);
1379 /* put in the lock code */
1380 force->slaying = op->slaying;
1381
1382 if (op->lore)
1383 force->lore = op->lore;
1384
1385 insert_ob_in_ob (force, tmp);
1386 if (op->msg)
1387 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg);
1388
1389 if (op->stats.hp > 0)
1390 {
1391 op->stats.hp--;
1392 if (op->stats.hp == 0)
1393 {
1394 /* marker expires--granted mark number limit */
1395 remove_ob (op);
1396 free_object (op);
1397 return;
1398 }
1399 } 1304 }
1400 } /* if tmp2 == NULL */ 1305 }
1401 } /* if tmp->type == PLAYER */ 1306 }
1402 } /* For all objects on this space */
1403} 1307}
1404 1308
1405int 1309int
1406process_object (object *op) 1310process_object (object *op)
1407{ 1311{
1440 if (QUERY_FLAG (op, FLAG_APPLIED)) 1344 if (QUERY_FLAG (op, FLAG_APPLIED))
1441 remove_force (op); 1345 remove_force (op);
1442 else 1346 else
1443 { 1347 {
1444 /* IF necessary, delete the item from the players inventory */ 1348 /* IF necessary, delete the item from the players inventory */
1445 object *pl = is_player_inv (op); 1349 object *pl = op->in_player ();
1446 1350
1447 if (pl) 1351 if (pl)
1448 esrv_del_item (pl->contr, op->count); 1352 esrv_del_item (pl->contr, op->count);
1449 1353
1450 remove_ob (op); 1354 op->remove ();
1451 1355
1452 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1356 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))
1453 make_sure_not_seen (op); 1357 make_sure_not_seen (op);
1454 1358
1455 free_object (op); 1359 op->destroy ();
1456 } 1360 }
1457 1361
1458 return 1; 1362 return 1;
1459 } 1363 }
1460 1364
1491 return 0; 1395 return 0;
1492 1396
1493 case THROWN_OBJ: 1397 case THROWN_OBJ:
1494 case ARROW: 1398 case ARROW:
1495 move_arrow (op); 1399 move_arrow (op);
1496 return 0;
1497
1498 case LIGHTNING: /* It now moves twice as fast */
1499 move_bolt (op);
1500 return 0; 1400 return 0;
1501 1401
1502 case DOOR: 1402 case DOOR:
1503 remove_door (op); 1403 remove_door (op);
1504 return 0; 1404 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines