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

Comparing deliantra/server/common/button.C (file contents):
Revision 1.1 by elmex, Sun Aug 13 17:16:00 2006 UTC vs.
Revision 1.2 by root, Tue Aug 29 08:01:35 2006 UTC

1/* 1/*
2 * static char *rcsid_button_c = 2 * static char *rcsid_button_c =
3 * "$Id: button.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; 3 * "$Id: button.C,v 1.2 2006/08/29 08:01:35 root Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
44 object *tmp; 44 object *tmp;
45 objectlink *ol; 45 objectlink *ol;
46 46
47/* LOG(llevDebug, "push_button: %s (%d)\n", op->name, op->count); */ 47/* LOG(llevDebug, "push_button: %s (%d)\n", op->name, op->count); */
48 for (ol = get_button_links(op); ol; ol = ol->next) { 48 for (ol = get_button_links(op); ol; ol = ol->next) {
49 if (!ol->ob || ol->ob->count != ol->id) { 49 if (!ol->ob || ol->ob->count != ol->id) {
50 LOG(llevError, "Internal error in push_button (%s).\n", op->name); 50 LOG(llevError, "Internal error in push_button (%s).\n", op->name);
51 continue; 51 continue;
52 } 52 }
53 /* a button link object can become freed when the map is saving. As 53 /* a button link object can become freed when the map is saving. As
54 * a map is saved, objects are removed and freed, and if an object is 54 * a map is saved, objects are removed and freed, and if an object is
55 * on top of a button, this function is eventually called. If a map 55 * on top of a button, this function is eventually called. If a map
56 * is getting moved out of memory, the status of buttons and levers 56 * is getting moved out of memory, the status of buttons and levers
57 * probably isn't important - it will get sorted out when the map is 57 * probably isn't important - it will get sorted out when the map is
58 * re-loaded. As such, just exit this function if that is the case. 58 * re-loaded. As such, just exit this function if that is the case.
59 */ 59 */
60 60
61 if (QUERY_FLAG(ol->ob, FLAG_FREED)) return; 61 if (QUERY_FLAG(ol->ob, FLAG_FREED)) return;
62 tmp = ol->ob; 62 tmp = ol->ob;
63 63
64 /* if the criteria isn't appropriate, don't do anything */ 64 /* if the criteria isn't appropriate, don't do anything */
65 if (op->value && !QUERY_FLAG(tmp, FLAG_ACTIVATE_ON_PUSH)) continue; 65 if (op->value && !QUERY_FLAG(tmp, FLAG_ACTIVATE_ON_PUSH)) continue;
66 if (!op->value && !QUERY_FLAG(tmp, FLAG_ACTIVATE_ON_RELEASE)) continue; 66 if (!op->value && !QUERY_FLAG(tmp, FLAG_ACTIVATE_ON_RELEASE)) continue;
67 67
68 switch(tmp->type) { 68 switch(tmp->type) {
69 69
70 case GATE: 70 case GATE:
71 case HOLE: 71 case HOLE:
72 tmp->value=tmp->stats.maxsp?!op->value:op->value; 72 tmp->value=tmp->stats.maxsp?!op->value:op->value;
73 tmp->speed=0.5; 73 tmp->speed=0.5;
74 update_ob_speed(tmp); 74 update_ob_speed(tmp);
75 break; 75 break;
76 76
77 case CF_HANDLE: 77 case CF_HANDLE:
78 SET_ANIMATION(tmp, (tmp->value=tmp->stats.maxsp?!op->value:op->value)); 78 SET_ANIMATION(tmp, (tmp->value=tmp->stats.maxsp?!op->value:op->value));
79 update_object(tmp,UP_OBJ_FACE); 79 update_object(tmp,UP_OBJ_FACE);
80 break; 80 break;
81 81
82 case SIGN: 82 case SIGN:
83 if (!tmp->stats.food || tmp->last_eat < tmp->stats.food) { 83 if (!tmp->stats.food || tmp->last_eat < tmp->stats.food) {
84 new_info_map(NDI_UNIQUE | NDI_NAVY,tmp->map,tmp->msg); 84 new_info_map(NDI_UNIQUE | NDI_NAVY,tmp->map,tmp->msg);
85 if (tmp->stats.food) tmp->last_eat++; 85 if (tmp->stats.food) tmp->last_eat++;
86 } 86 }
87 break; 87 break;
88 88
89 case ALTAR: 89 case ALTAR:
90 tmp->value = 1; 90 tmp->value = 1;
91 SET_ANIMATION(tmp, tmp->value); 91 SET_ANIMATION(tmp, tmp->value);
92 update_object(tmp,UP_OBJ_FACE); 92 update_object(tmp,UP_OBJ_FACE);
93 break; 93 break;
94 94
95 case BUTTON: 95 case BUTTON:
96 case PEDESTAL: 96 case PEDESTAL:
97 tmp->value=op->value; 97 tmp->value=op->value;
98 SET_ANIMATION(tmp, tmp->value); 98 SET_ANIMATION(tmp, tmp->value);
99 update_object(tmp,UP_OBJ_FACE); 99 update_object(tmp,UP_OBJ_FACE);
100 break; 100 break;
101 101
102 case MOOD_FLOOR: 102 case MOOD_FLOOR:
103 do_mood_floor(tmp, op); 103 do_mood_floor(tmp, op);
104 break; 104 break;
105 105
106 case TIMED_GATE: 106 case TIMED_GATE:
107 tmp->speed = tmp->arch->clone.speed; 107 tmp->speed = tmp->arch->clone.speed;
108 update_ob_speed(tmp); /* original values */ 108 update_ob_speed(tmp); /* original values */
109 tmp->value = tmp->arch->clone.value; 109 tmp->value = tmp->arch->clone.value;
110 tmp->stats.sp = 1; 110 tmp->stats.sp = 1;
111 tmp->stats.hp = tmp->stats.maxhp; 111 tmp->stats.hp = tmp->stats.maxhp;
112 /* Handle multipart gates. We copy the value for the other parts 112 /* Handle multipart gates. We copy the value for the other parts
113 * from the head - this ensures that the data will consistent 113 * from the head - this ensures that the data will consistent
114 */ 114 */
115 for (tmp=tmp->more; tmp!=NULL; tmp=tmp->more) { 115 for (tmp=tmp->more; tmp!=NULL; tmp=tmp->more) {
116 tmp->speed = tmp->head->speed; 116 tmp->speed = tmp->head->speed;
117 tmp->value = tmp->head->value; 117 tmp->value = tmp->head->value;
118 tmp->stats.sp = tmp->head->stats.sp; 118 tmp->stats.sp = tmp->head->stats.sp;
119 tmp->stats.hp = tmp->head->stats.hp; 119 tmp->stats.hp = tmp->head->stats.hp;
120 update_ob_speed(tmp); 120 update_ob_speed(tmp);
121 } 121 }
122 break; 122 break;
123 123
124 case DIRECTOR: 124 case DIRECTOR:
125 case FIREWALL: 125 case FIREWALL:
126 if(!QUERY_FLAG(tmp,FLAG_ANIMATE)&&tmp->type==FIREWALL) move_firewall(tmp); 126 if(!QUERY_FLAG(tmp,FLAG_ANIMATE)&&tmp->type==FIREWALL) move_firewall(tmp);
127 else { 127 else {
128 if ((tmp->stats.sp += tmp->stats.maxsp) > 8) /* next direction */ 128 if ((tmp->stats.sp += tmp->stats.maxsp) > 8) /* next direction */
129 tmp->stats.sp = ((tmp->stats.sp-1)%8)+1; 129 tmp->stats.sp = ((tmp->stats.sp-1)%8)+1;
130 animate_turning(tmp); 130 animate_turning(tmp);
131 } 131 }
132 break; 132 break;
133 133
134 case TELEPORTER: 134 case TELEPORTER:
135 move_teleporter(tmp); 135 move_teleporter(tmp);
136 break; 136 break;
137 137
138 case CREATOR: 138 case CREATOR:
139 move_creator(tmp); 139 move_creator(tmp);
140 break; 140 break;
141 141
142 case TRIGGER_MARKER: 142 case TRIGGER_MARKER:
143 move_marker(tmp); 143 move_marker(tmp);
144 break; 144 break;
145 145
146 case DUPLICATOR: 146 case DUPLICATOR:
147 move_duplicator(tmp); 147 move_duplicator(tmp);
148 break; 148 break;
149 } 149 }
150 } 150 }
151} 151}
152 152
153/* 153/*
154 * Updates everything connected with the button op. 154 * Updates everything connected with the button op.
162 int tot,any_down=0, old_value=op->value; 162 int tot,any_down=0, old_value=op->value;
163 objectlink *ol; 163 objectlink *ol;
164 164
165 /* LOG(llevDebug, "update_button: %s (%d)\n", op->name, op->count); */ 165 /* LOG(llevDebug, "update_button: %s (%d)\n", op->name, op->count); */
166 for (ol = get_button_links(op); ol; ol = ol->next) { 166 for (ol = get_button_links(op); ol; ol = ol->next) {
167 if (!ol->ob || ol->ob->count != ol->id) { 167 if (!ol->ob || ol->ob->count != ol->id) {
168 LOG(llevDebug, "Internal error in update_button (%s).\n", op->name); 168 LOG(llevDebug, "Internal error in update_button (%s).\n", op->name);
169 continue; 169 continue;
170 } 170 }
171 tmp = ol->ob; 171 tmp = ol->ob;
172 if (tmp->type==BUTTON) { 172 if (tmp->type==BUTTON) {
173 for(ab=tmp->above,tot=0;ab!=NULL;ab=ab->above) 173 for(ab=tmp->above,tot=0;ab!=NULL;ab=ab->above)
174 /* Bug? The pedestal code below looks for the head of 174 /* Bug? The pedestal code below looks for the head of
175 * the object, this bit doesn't. I'd think we should check 175 * the object, this bit doesn't. I'd think we should check
176 * for head here also. Maybe it also makese sense to 176 * for head here also. Maybe it also makese sense to
177 * make the for ab=tmp->above loop common, and alter 177 * make the for ab=tmp->above loop common, and alter
178 * behaviour based on object within that loop? 178 * behaviour based on object within that loop?
179 */ 179 */
180 180
181 /* Basically, if the move_type matches that on what the 181 /* Basically, if the move_type matches that on what the
182 * button wants, we count it. The second check is so that 182 * button wants, we count it. The second check is so that
183 * objects don't move (swords, etc) will count. Note that 183 * objects don't move (swords, etc) will count. Note that
184 * this means that more work is needed to make buttons 184 * this means that more work is needed to make buttons
185 * that are only triggered by flying objects. 185 * that are only triggered by flying objects.
186 */ 186 */
187 if ((ab->move_type & tmp->move_on) || ab->move_type==0 ) 187 if ((ab->move_type & tmp->move_on) || ab->move_type==0 )
188 tot+=ab->weight*(ab->nrof?ab->nrof:1)+ab->carrying; 188 tot+=ab->weight*(ab->nrof?ab->nrof:1)+ab->carrying;
189 189
190 tmp->value=(tot>=tmp->weight)?1:0; 190 tmp->value=(tot>=tmp->weight)?1:0;
191 if(tmp->value) 191 if(tmp->value)
192 any_down=1; 192 any_down=1;
193 } else if (tmp->type == PEDESTAL) { 193 } else if (tmp->type == PEDESTAL) {
194 tmp->value = 0; 194 tmp->value = 0;
195 for(ab=tmp->above; ab!=NULL; ab=ab->above) { 195 for(ab=tmp->above; ab!=NULL; ab=ab->above) {
196 head = ab->head ? ab->head : ab; 196 head = ab->head ? ab->head : ab;
197 /* Same note regarding move_type for buttons above apply here. */ 197 /* Same note regarding move_type for buttons above apply here. */
198 if ( ((head->move_type & tmp->move_on) || ab->move_type==0) && 198 if ( ((head->move_type & tmp->move_on) || ab->move_type==0) &&
199 (head->race==tmp->slaying || 199 (head->race==tmp->slaying ||
200 ((head->type==SPECIAL_KEY) && (head->slaying==tmp->slaying)) || 200 ((head->type==SPECIAL_KEY) && (head->slaying==tmp->slaying)) ||
201 (!strcmp (tmp->slaying, "player") && 201 (!strcmp (tmp->slaying, "player") &&
202 head->type == PLAYER))) 202 head->type == PLAYER)))
203 tmp->value = 1; 203 tmp->value = 1;
204 } 204 }
205 if(tmp->value) 205 if(tmp->value)
206 any_down=1; 206 any_down=1;
207 } 207 }
208 } 208 }
209 if(any_down) /* If any other buttons were down, force this to remain down */ 209 if(any_down) /* If any other buttons were down, force this to remain down */
210 op->value=1; 210 op->value=1;
211 211
212 /* If this button hasn't changed, don't do anything */ 212 /* If this button hasn't changed, don't do anything */
213 if (op->value != old_value) { 213 if (op->value != old_value) {
214 SET_ANIMATION(op, op->value); 214 SET_ANIMATION(op, op->value);
215 update_object(op, UP_OBJ_FACE); 215 update_object(op, UP_OBJ_FACE);
216 push_button(op); /* Make all other buttons the same */ 216 push_button(op); /* Make all other buttons the same */
217 } 217 }
218} 218}
219 219
220/* 220/*
221 * Updates every button on the map (by calling update_button() for them). 221 * Updates every button on the map (by calling update_button() for them).
226 oblinkpt *obp; 226 oblinkpt *obp;
227 for (obp = m->buttons; obp; obp = obp->next) 227 for (obp = m->buttons; obp; obp = obp->next)
228 for (ol = obp->link; ol; ol = ol->next) { 228 for (ol = obp->link; ol; ol = ol->next) {
229 if (!ol->ob || ol->ob->count != ol->id) { 229 if (!ol->ob || ol->ob->count != ol->id) {
230 LOG(llevError, "Internal error in update_button (%s (%dx%d):%d, connected %ld).\n", 230 LOG(llevError, "Internal error in update_button (%s (%dx%d):%d, connected %ld).\n",
231 ol->ob?ol->ob->name:"null", 231 ol->ob?ol->ob->name:"null",
232 ol->ob?ol->ob->x:-1, 232 ol->ob?ol->ob->x:-1,
233 ol->ob?ol->ob->y:-1, 233 ol->ob?ol->ob->y:-1,
234 ol->id, 234 ol->id,
235 obp->value); 235 obp->value);
236 continue; 236 continue;
237 } 237 }
238 if (ol->ob->type==BUTTON || ol->ob->type==PEDESTAL) 238 if (ol->ob->type==BUTTON || ol->ob->type==PEDESTAL)
239 { 239 {
240 update_button(ol->ob); 240 update_button(ol->ob);
259void animate_turning(object *op) /* only one part objects */ 259void animate_turning(object *op) /* only one part objects */
260{ 260{
261 if (++op->state >= NUM_ANIMATIONS(op)/8) 261 if (++op->state >= NUM_ANIMATIONS(op)/8)
262 op->state=0; 262 op->state=0;
263 SET_ANIMATION(op, (op->stats.sp-1) * NUM_ANIMATIONS(op) / 8 + 263 SET_ANIMATION(op, (op->stats.sp-1) * NUM_ANIMATIONS(op) / 8 +
264 op->state); 264 op->state);
265 update_object(op,UP_OBJ_FACE); 265 update_object(op,UP_OBJ_FACE);
266} 266}
267 267
268#define ARCH_SACRIFICE(xyz) ((xyz)->slaying) 268#define ARCH_SACRIFICE(xyz) ((xyz)->slaying)
269#define NROF_SACRIFICE(xyz) ((uint32)(xyz)->stats.food) 269#define NROF_SACRIFICE(xyz) ((uint32)(xyz)->stats.food)
285 && ! QUERY_FLAG (sacrifice, FLAG_IS_LINKED) 285 && ! QUERY_FLAG (sacrifice, FLAG_IS_LINKED)
286 && sacrifice->type != PLAYER) 286 && sacrifice->type != PLAYER)
287 { 287 {
288 if ((ARCH_SACRIFICE(altar) == sacrifice->arch->name || 288 if ((ARCH_SACRIFICE(altar) == sacrifice->arch->name ||
289 ARCH_SACRIFICE(altar) == sacrifice->name || 289 ARCH_SACRIFICE(altar) == sacrifice->name ||
290 ARCH_SACRIFICE(altar) == sacrifice->slaying || 290 ARCH_SACRIFICE(altar) == sacrifice->slaying ||
291 (!strcmp(ARCH_SACRIFICE(altar),query_base_name(sacrifice,0)))) 291 (!strcmp(ARCH_SACRIFICE(altar),query_base_name(sacrifice,0))))
292 && NROF_SACRIFICE(altar) <= (sacrifice->nrof?sacrifice->nrof:1)) 292 && NROF_SACRIFICE(altar) <= (sacrifice->nrof?sacrifice->nrof:1))
293 return 1; 293 return 1;
294 if (strcmp (ARCH_SACRIFICE(altar), "money") == 0 294 if (strcmp (ARCH_SACRIFICE(altar), "money") == 0
295 && sacrifice->type == MONEY 295 && sacrifice->type == MONEY
296 && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE(altar)) 296 && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE(altar))
297 return 1; 297 return 1;
298 } 298 }
299 return 0; 299 return 0;
300} 300}
301 301
302 302
326 326
327 /* check_altar_sacrifice should have already verified that enough money 327 /* check_altar_sacrifice should have already verified that enough money
328 * has been dropped. 328 * has been dropped.
329 */ 329 */
330 if (!strcmp(ARCH_SACRIFICE(altar), "money")) { 330 if (!strcmp(ARCH_SACRIFICE(altar), "money")) {
331 int number=NROF_SACRIFICE(altar) / (*sacrifice)->value; 331 int number=NROF_SACRIFICE(altar) / (*sacrifice)->value;
332 332
333 /* Round up any sacrifices. Altars don't make change either */ 333 /* Round up any sacrifices. Altars don't make change either */
334 if (NROF_SACRIFICE(altar) % (*sacrifice)->value) number++; 334 if (NROF_SACRIFICE(altar) % (*sacrifice)->value) number++;
335 *sacrifice = decrease_ob_nr (*sacrifice, number); 335 *sacrifice = decrease_ob_nr (*sacrifice, number);
336 } 336 }
337 else 337 else
338 *sacrifice = decrease_ob_nr (*sacrifice, NROF_SACRIFICE(altar)); 338 *sacrifice = decrease_ob_nr (*sacrifice, NROF_SACRIFICE(altar));
339 339
340 if (altar->msg) 340 if (altar->msg)
344 344
345void trigger_move (object *op, int state) /* 1 down and 0 up */ 345void trigger_move (object *op, int state) /* 1 down and 0 up */
346{ 346{
347 op->stats.wc = state; 347 op->stats.wc = state;
348 if (state) { 348 if (state) {
349 use_trigger(op); 349 use_trigger(op);
350 if (op->stats.exp > 0) /* check sanity */ 350 if (op->stats.exp > 0) /* check sanity */
351 op->speed = 1.0 / op->stats.exp; 351 op->speed = 1.0 / op->stats.exp;
352 else 352 else
353 op->speed = 1.0; 353 op->speed = 1.0;
354 update_ob_speed(op); 354 update_ob_speed(op);
355 op->speed_left = -1; 355 op->speed_left = -1;
356 } else { 356 } else {
357 use_trigger(op); 357 use_trigger(op);
358 op->speed = 0; 358 op->speed = 0;
359 update_ob_speed(op); 359 update_ob_speed(op);
360 } 360 }
361} 361}
362 362
363 363
364/* 364/*
378 object *tmp; 378 object *tmp;
379 int push = 0, tot = 0; 379 int push = 0, tot = 0;
380 int in_movement = op->stats.wc || op->speed; 380 int in_movement = op->stats.wc || op->speed;
381 381
382 switch (op->type) { 382 switch (op->type) {
383 case TRIGGER_BUTTON: 383 case TRIGGER_BUTTON:
384 if (op->weight > 0) { 384 if (op->weight > 0) {
385 if (cause) { 385 if (cause) {
386 for (tmp = op->above; tmp; tmp = tmp->above) 386 for (tmp = op->above; tmp; tmp = tmp->above)
387 /* Comment reproduced from update_buttons(): */ 387 /* Comment reproduced from update_buttons(): */
388 /* Basically, if the move_type matches that on what the 388 /* Basically, if the move_type matches that on what the
389 * button wants, we count it. The second check is so that 389 * button wants, we count it. The second check is so that
390 * objects that don't move (swords, etc) will count. Note that 390 * objects that don't move (swords, etc) will count. Note that
391 * this means that more work is needed to make buttons 391 * this means that more work is needed to make buttons
392 * that are only triggered by flying objects. 392 * that are only triggered by flying objects.
393 */ 393 */
394 394
395 if ((tmp->move_type & op->move_on) || tmp->move_type==0) { 395 if ((tmp->move_type & op->move_on) || tmp->move_type==0) {
396 tot += tmp->weight * (tmp->nrof ? tmp->nrof : 1) 396 tot += tmp->weight * (tmp->nrof ? tmp->nrof : 1)
397 + tmp->carrying; 397 + tmp->carrying;
398 } 398 }
399 if (tot >= op->weight) 399 if (tot >= op->weight)
400 push = 1; 400 push = 1;
401 if (op->stats.ac == push) 401 if (op->stats.ac == push)
402 return 0; 402 return 0;
403 op->stats.ac = push; 403 op->stats.ac = push;
404 if (NUM_ANIMATIONS(op) > 1) { 404 if (NUM_ANIMATIONS(op) > 1) {
405 SET_ANIMATION (op, push); 405 SET_ANIMATION (op, push);
406 update_object (op, UP_OBJ_FACE); 406 update_object (op, UP_OBJ_FACE);
407 } 407 }
408 if (in_movement || ! push) 408 if (in_movement || ! push)
409 return 0; 409 return 0;
410 } 410 }
411 trigger_move (op, push); 411 trigger_move (op, push);
412 } 412 }
413 return 0; 413 return 0;
414 414
415 case TRIGGER_PEDESTAL: 415 case TRIGGER_PEDESTAL:
416 if (cause) { 416 if (cause) {
417 for (tmp = op->above; tmp; tmp = tmp->above) { 417 for (tmp = op->above; tmp; tmp = tmp->above) {
418 object *head = tmp->head ? tmp->head : tmp; 418 object *head = tmp->head ? tmp->head : tmp;
419 419
420 /* See comment in TRIGGER_BUTTON about move_types */ 420 /* See comment in TRIGGER_BUTTON about move_types */
421 if (((head->move_type & op->move_on) || head->move_type==0) 421 if (((head->move_type & op->move_on) || head->move_type==0)
422 && (head->race==op->slaying || 422 && (head->race==op->slaying ||
423 (!strcmp (op->slaying, "player") && head->type == PLAYER))) { 423 (!strcmp (op->slaying, "player") && head->type == PLAYER))) {
424 push = 1; 424 push = 1;
425 break; 425 break;
426 } 426 }
427 } 427 }
428 if (op->stats.ac == push) 428 if (op->stats.ac == push)
429 return 0; 429 return 0;
430 op->stats.ac = push; 430 op->stats.ac = push;
431 if (NUM_ANIMATIONS(op) > 1) { 431 if (NUM_ANIMATIONS(op) > 1) {
432 SET_ANIMATION (op, push); 432 SET_ANIMATION (op, push);
433 update_object (op, UP_OBJ_FACE); 433 update_object (op, UP_OBJ_FACE);
434 } 434 }
435 update_object(op,UP_OBJ_FACE); 435 update_object(op,UP_OBJ_FACE);
436 if (in_movement || ! push) 436 if (in_movement || ! push)
437 return 0; 437 return 0;
438 } 438 }
439 trigger_move (op, push); 439 trigger_move (op, push);
440 return 0; 440 return 0;
441 441
442 case TRIGGER_ALTAR: 442 case TRIGGER_ALTAR:
443 if (cause) { 443 if (cause) {
444 if (in_movement) 444 if (in_movement)
445 return 0; 445 return 0;
446 if (operate_altar (op, &cause)) { 446 if (operate_altar (op, &cause)) {
447 if (NUM_ANIMATIONS(op) > 1) { 447 if (NUM_ANIMATIONS(op) > 1) {
448 SET_ANIMATION (op, 1); 448 SET_ANIMATION (op, 1);
449 update_object(op, UP_OBJ_FACE); 449 update_object(op, UP_OBJ_FACE);
450 } 450 }
451 if (op->last_sp >= 0) { 451 if (op->last_sp >= 0) {
452 trigger_move (op, 1); 452 trigger_move (op, 1);
453 if (op->last_sp > 0) 453 if (op->last_sp > 0)
454 op->last_sp = -op->last_sp; 454 op->last_sp = -op->last_sp;
455 } 455 }
456 else { 456 else {
457 /* for trigger altar with last_sp, the ON/OFF 457 /* for trigger altar with last_sp, the ON/OFF
458 * status (-> +/- value) is "simulated": 458 * status (-> +/- value) is "simulated":
459 */ 459 */
460 op->value = !op->value; 460 op->value = !op->value;
461 trigger_move (op, 1); 461 trigger_move (op, 1);
462 op->last_sp = -op->last_sp; 462 op->last_sp = -op->last_sp;
463 op->value = !op->value; 463 op->value = !op->value;
464 } 464 }
465 return cause == NULL; 465 return cause == NULL;
466 } else { 466 } else {
467 return 0; 467 return 0;
468 } 468 }
469 } else { 469 } else {
470 if (NUM_ANIMATIONS(op) > 1) { 470 if (NUM_ANIMATIONS(op) > 1) {
471 SET_ANIMATION (op, 0); 471 SET_ANIMATION (op, 0);
472 update_object(op, UP_OBJ_FACE); 472 update_object(op, UP_OBJ_FACE);
473 } 473 }
474 474
475 /* If trigger_altar has "last_sp > 0" set on the map, 475 /* If trigger_altar has "last_sp > 0" set on the map,
476 * it will push the connected value only once per sacrifice. 476 * it will push the connected value only once per sacrifice.
477 * Otherwise (default), the connected value will be 477 * Otherwise (default), the connected value will be
478 * pushed twice: First by sacrifice, second by reset! -AV 478 * pushed twice: First by sacrifice, second by reset! -AV
479 */ 479 */
480 if (!op->last_sp) 480 if (!op->last_sp)
481 trigger_move (op, 0); 481 trigger_move (op, 0);
482 else { 482 else {
483 op->stats.wc = 0; 483 op->stats.wc = 0;
484 op->value = !op->value; 484 op->value = !op->value;
485 op->speed = 0; 485 op->speed = 0;
486 update_ob_speed(op); 486 update_ob_speed(op);
487 } 487 }
488 } 488 }
489 return 0; 489 return 0;
490 490
491 case TRIGGER: 491 case TRIGGER:
492 if (cause) { 492 if (cause) {
493 if (in_movement) 493 if (in_movement)
494 return 0; 494 return 0;
495 push = 1; 495 push = 1;
496 } 496 }
497 if (NUM_ANIMATIONS(op) > 1) { 497 if (NUM_ANIMATIONS(op) > 1) {
498 SET_ANIMATION (op, push); 498 SET_ANIMATION (op, push);
499 update_object(op, UP_OBJ_FACE); 499 update_object(op, UP_OBJ_FACE);
500 } 500 }
501 trigger_move (op, push); 501 trigger_move (op, push);
502 return 1; 502 return 1;
503 503
504 default: 504 default:
505 LOG(llevDebug, "Unknown trigger type: %s (%d)\n", op->name, op->type); 505 LOG(llevDebug, "Unknown trigger type: %s (%d)\n", op->name, op->type);
506 return 0; 506 return 0;
507 } 507 }
508} 508}
509 509
510void add_button_link(object *button, mapstruct *map, int connected) { 510void add_button_link(object *button, mapstruct *map, int connected) {
511 oblinkpt *obp; 511 oblinkpt *obp;
514 if (!map) { 514 if (!map) {
515 LOG(llevError, "Tried to add button-link without map.\n"); 515 LOG(llevError, "Tried to add button-link without map.\n");
516 return; 516 return;
517 } 517 }
518 if (!editor) button->path_attuned = connected; /* peterm: I need this so I can rebuild 518 if (!editor) button->path_attuned = connected; /* peterm: I need this so I can rebuild
519 a connected map from a template map. */ 519 a connected map from a template map. */
520/* LOG(llevDebug,"adding button %s (%d)\n", button->name, connected);*/ 520/* LOG(llevDebug,"adding button %s (%d)\n", button->name, connected);*/
521 521
522 SET_FLAG(button,FLAG_IS_LINKED); 522 SET_FLAG(button,FLAG_IS_LINKED);
523 523
524 ol->ob = button; 524 ol->ob = button;
616void do_mood_floor(object *op, object *op2) { 616void do_mood_floor(object *op, object *op2) {
617 object *tmp; 617 object *tmp;
618 object *tmp2; 618 object *tmp2;
619 619
620 for (tmp = GET_MAP_OB(op->map, op->x, op->y); tmp; tmp=tmp->above) 620 for (tmp = GET_MAP_OB(op->map, op->x, op->y); tmp; tmp=tmp->above)
621 if (QUERY_FLAG(tmp, FLAG_MONSTER)) break; 621 if (QUERY_FLAG(tmp, FLAG_MONSTER)) break;
622 622
623 /* doesn't effect players, and if there is a player on this space, won't also 623 /* doesn't effect players, and if there is a player on this space, won't also
624 * be a monster here. 624 * be a monster here.
625 */ 625 */
626 if (!tmp || tmp->type == PLAYER) return; 626 if (!tmp || tmp->type == PLAYER) return;
627 627
628 switch(op->last_sp) { 628 switch(op->last_sp) {
629 case 0: /* furious--make all monsters mad */ 629 case 0: /* furious--make all monsters mad */
630 if(QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE)) 630 if(QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE))
631 CLEAR_FLAG(tmp, FLAG_UNAGGRESSIVE); 631 CLEAR_FLAG(tmp, FLAG_UNAGGRESSIVE);
632 if(QUERY_FLAG(tmp, FLAG_FRIENDLY)) { 632 if(QUERY_FLAG(tmp, FLAG_FRIENDLY)) {
633 CLEAR_FLAG(tmp, FLAG_FRIENDLY); 633 CLEAR_FLAG(tmp, FLAG_FRIENDLY);
634 remove_friendly_object(tmp); 634 remove_friendly_object(tmp);
635 tmp->attack_movement = 0; 635 tmp->attack_movement = 0;
636 /* lots of checks here, but want to make sure we don't 636 /* lots of checks here, but want to make sure we don't
637 * dereference a null value 637 * dereference a null value
638 */ 638 */
639 if (tmp->type == GOLEM && tmp->owner && tmp->owner->type==PLAYER && 639 if (tmp->type == GOLEM && tmp->owner && tmp->owner->type==PLAYER &&
640 tmp->owner->contr->ranges[range_golem]==tmp) { 640 tmp->owner->contr->ranges[range_golem]==tmp) {
641 tmp->owner->contr->ranges[range_golem]=NULL; 641 tmp->owner->contr->ranges[range_golem]=NULL;
642 tmp->owner->contr->golem_count = 0; 642 tmp->owner->contr->golem_count = 0;
643 } 643 }
644 tmp->owner = 0; 644 tmp->owner = 0;
645 } 645 }
646 break; 646 break;
647 case 1: /* angry -- get neutral monsters mad */ 647 case 1: /* angry -- get neutral monsters mad */
648 if(QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE)&& 648 if(QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE)&&
649 !QUERY_FLAG(tmp, FLAG_FRIENDLY)) 649 !QUERY_FLAG(tmp, FLAG_FRIENDLY))
650 CLEAR_FLAG(tmp, FLAG_UNAGGRESSIVE); 650 CLEAR_FLAG(tmp, FLAG_UNAGGRESSIVE);
651 break; 651 break;
652 case 2: /* calm -- pacify unfriendly monsters */ 652 case 2: /* calm -- pacify unfriendly monsters */
653 if(!QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE)) 653 if(!QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE))
654 SET_FLAG(tmp, FLAG_UNAGGRESSIVE); 654 SET_FLAG(tmp, FLAG_UNAGGRESSIVE);
655 break; 655 break;
656 case 3: /* make all monsters fall asleep */ 656 case 3: /* make all monsters fall asleep */
657 if(!QUERY_FLAG(tmp, FLAG_SLEEP)) 657 if(!QUERY_FLAG(tmp, FLAG_SLEEP))
658 SET_FLAG(tmp, FLAG_SLEEP); 658 SET_FLAG(tmp, FLAG_SLEEP);
659 break; 659 break;
660 case 4: /* charm all monsters */ 660 case 4: /* charm all monsters */
661 661
662 if(op == op2) break; /* only if 'connected' */ 662 if(op == op2) break; /* only if 'connected' */
663 663
664 for(tmp2=get_map_ob(op2->map,op2->x,op2->y); /* finding an owner */ 664 for(tmp2=get_map_ob(op2->map,op2->x,op2->y); /* finding an owner */
665 tmp2->type!=PLAYER;tmp2=tmp2->above) 665 tmp2->type!=PLAYER;tmp2=tmp2->above)
666 if(tmp2->above==NULL) break; 666 if(tmp2->above==NULL) break;
667 667
668 if (tmp2->type != PLAYER) 668 if (tmp2->type != PLAYER)
669 break; 669 break;
670 set_owner(tmp,tmp2); 670 set_owner(tmp,tmp2);
671 SET_FLAG(tmp,FLAG_MONSTER); 671 SET_FLAG(tmp,FLAG_MONSTER);
672 tmp->stats.exp = 0; 672 tmp->stats.exp = 0;
673 SET_FLAG(tmp, FLAG_FRIENDLY); 673 SET_FLAG(tmp, FLAG_FRIENDLY);
674 add_friendly_object (tmp); 674 add_friendly_object (tmp);
675 tmp->attack_movement = PETMOVE; 675 tmp->attack_movement = PETMOVE;
676 break; 676 break;
677 677
678 default: 678 default:
679 break; 679 break;
680 680
681 } 681 }
682} 682}
683 683
684/* this function returns the object it matches, or NULL if non. 684/* this function returns the object it matches, or NULL if non.
692{ 692{
693 object *tmp,*ret=NULL; 693 object *tmp,*ret=NULL;
694 694
695 /* First check the object itself. */ 695 /* First check the object itself. */
696 if((trig->stats.hp && (op->type == trig->stats.hp)) 696 if((trig->stats.hp && (op->type == trig->stats.hp))
697 || (trig->slaying && (op->slaying == trig->slaying)) 697 || (trig->slaying && (op->slaying == trig->slaying))
698 || (trig->race && (op->arch->name == trig->race))) 698 || (trig->race && (op->arch->name == trig->race)))
699 return op; 699 return op;
700 700
701 for(tmp=op->inv; tmp; tmp=tmp->below) { 701 for(tmp=op->inv; tmp; tmp=tmp->below) {
702 if (tmp->inv) { 702 if (tmp->inv) {
703 ret=check_inv_recursive(tmp, trig); 703 ret=check_inv_recursive(tmp, trig);
704 if (ret) return ret; 704 if (ret) return ret;
705 } 705 }
706 else if((trig->stats.hp && (tmp->type == trig->stats.hp)) 706 else if((trig->stats.hp && (tmp->type == trig->stats.hp))
707 || (trig->slaying && (tmp->slaying == trig->slaying)) 707 || (trig->slaying && (tmp->slaying == trig->slaying))
708 || (trig->race && (tmp->arch->name == trig->race))) 708 || (trig->race && (tmp->arch->name == trig->race)))
709 return tmp; 709 return tmp;
710 } 710 }
711 return NULL; 711 return NULL;
712} 712}
713 713
714/* check_inv(), a function to search the inventory, 714/* check_inv(), a function to search the inventory,
724object *match; 724object *match;
725 725
726 if(op->type != PLAYER) return; 726 if(op->type != PLAYER) return;
727 match = check_inv_recursive(op,trig); 727 match = check_inv_recursive(op,trig);
728 if (match && trig->last_sp) { 728 if (match && trig->last_sp) {
729 if(trig->last_heal) 729 if(trig->last_heal)
730 decrease_ob(match); 730 decrease_ob(match);
731 use_trigger(trig); 731 use_trigger(trig);
732 } 732 }
733 else if (!match && !trig->last_sp) 733 else if (!match && !trig->last_sp)
734 use_trigger(trig); 734 use_trigger(trig);
735} 735}
736 736
737 737
738/* This does a minimal check of the button link consistency for object 738/* This does a minimal check of the button link consistency for object
739 * map. All it really does it much sure the object id link that is set 739 * map. All it really does it much sure the object id link that is set
744 objectlink *ol; 744 objectlink *ol;
745 745
746 if (!map) return; 746 if (!map) return;
747 747
748 for (obp = map->buttons; obp; obp = obp->next) { 748 for (obp = map->buttons; obp; obp = obp->next) {
749 for (ol=obp->link; ol; ol=ol->next) { 749 for (ol=obp->link; ol; ol=ol->next) {
750 if (ol->id!=ol->ob->count) 750 if (ol->id!=ol->ob->count)
751 LOG(llevError,"verify_button_links: object %s on list is corrupt (%d!=%d)\n",ol->ob->name, ol->id, ol->ob->count); 751 LOG(llevError,"verify_button_links: object %s on list is corrupt (%d!=%d)\n",ol->ob->name, ol->id, ol->ob->count);
752 } 752 }
753 } 753 }
754} 754}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines