… | |
… | |
57 | tmp->map = op->map; |
57 | tmp->map = op->map; |
58 | tmp->level = op->level; |
58 | tmp->level = op->level; |
59 | insert_ob_in_map (tmp, op->map, op, 0); |
59 | insert_ob_in_map (tmp, op->map, op, 0); |
60 | } |
60 | } |
61 | |
61 | |
62 | op->destroy_inv (true); // be explicit about dropping |
62 | op->drop_and_destroy (); |
63 | op->destroy (true); |
|
|
64 | } |
63 | } |
65 | |
64 | |
66 | void |
65 | void |
67 | remove_door2 (object *op) |
66 | remove_door2 (object *op) |
68 | { |
67 | { |
… | |
… | |
87 | tmp->map = op->map; |
86 | tmp->map = op->map; |
88 | tmp->level = op->level; |
87 | tmp->level = op->level; |
89 | insert_ob_in_map (tmp, op->map, op, 0); |
88 | insert_ob_in_map (tmp, op->map, op, 0); |
90 | } |
89 | } |
91 | |
90 | |
92 | op->destroy_inv (true); // be explicit about dropping |
91 | op->drop_and_destroy (); |
93 | op->destroy (true); |
|
|
94 | } |
92 | } |
95 | |
93 | |
96 | void |
94 | void |
97 | generate_monster (object *gen) |
95 | generate_monster (object *gen) |
98 | { |
96 | { |
99 | if (!gen->map) |
97 | if (!gen->map) |
100 | return; |
98 | return; |
101 | |
99 | |
102 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
100 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
|
|
101 | return; |
|
|
102 | |
|
|
103 | // sleeping generators won't generate, this will make monsters like |
|
|
104 | // centipedes not generate more centipedes when being asleep. |
|
|
105 | if (gen->flag [FLAG_SLEEP]) |
103 | return; |
106 | return; |
104 | |
107 | |
105 | object *op; |
108 | object *op; |
106 | int dir; |
109 | int dir; |
107 | |
110 | |
… | |
… | |
151 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty); |
154 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty); |
152 | |
155 | |
153 | return; |
156 | return; |
154 | } |
157 | } |
155 | |
158 | |
156 | op->destroy (true); |
159 | op->destroy (); |
157 | } |
160 | } |
158 | |
161 | |
159 | void |
162 | void |
160 | remove_force (object *op) |
163 | remove_force (object *op) |
161 | { |
164 | { |
… | |
… | |
173 | CLEAR_FLAG (op, FLAG_APPLIED); |
176 | CLEAR_FLAG (op, FLAG_APPLIED); |
174 | change_abil (op->env, op); |
177 | change_abil (op->env, op); |
175 | op->env->update_stats (); |
178 | op->env->update_stats (); |
176 | } |
179 | } |
177 | |
180 | |
178 | op->destroy (true); |
181 | op->destroy (); |
179 | } |
182 | } |
180 | |
183 | |
181 | void |
184 | void |
182 | remove_blindness (object *op) |
185 | remove_blindness (object *op) |
183 | { |
186 | { |
… | |
… | |
190 | { |
193 | { |
191 | change_abil (op->env, op); |
194 | change_abil (op->env, op); |
192 | op->env->update_stats (); |
195 | op->env->update_stats (); |
193 | } |
196 | } |
194 | |
197 | |
195 | op->destroy (true); |
198 | op->destroy (); |
196 | } |
199 | } |
197 | |
200 | |
198 | void |
201 | void |
199 | poison_more (object *op) |
202 | poison_more (object *op) |
200 | { |
203 | { |
201 | if (op->env == NULL || !QUERY_FLAG (op->env, FLAG_ALIVE) || op->env->stats.hp < 0) |
204 | if (op->env == NULL || !QUERY_FLAG (op->env, FLAG_ALIVE) || op->env->stats.hp < 0) |
202 | { |
205 | { |
203 | op->destroy (true); |
206 | op->destroy (); |
204 | return; |
207 | return; |
205 | } |
208 | } |
206 | |
209 | |
207 | if (op->stats.food == 1) |
210 | if (op->stats.food == 1) |
208 | { |
211 | { |
… | |
… | |
214 | CLEAR_FLAG (op, FLAG_APPLIED); |
217 | CLEAR_FLAG (op, FLAG_APPLIED); |
215 | op->env->update_stats (); |
218 | op->env->update_stats (); |
216 | new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now."); |
219 | new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now."); |
217 | } |
220 | } |
218 | |
221 | |
219 | op->destroy (true); |
222 | op->destroy (); |
220 | return; |
223 | return; |
221 | } |
224 | } |
222 | |
225 | |
223 | if (op->env->type == PLAYER) |
226 | if (op->env->type == PLAYER) |
224 | { |
227 | { |
… | |
… | |
439 | if (op->stats.sp == 1) |
442 | if (op->stats.sp == 1) |
440 | { |
443 | { |
441 | if (detected && last == 0) |
444 | if (detected && last == 0) |
442 | { |
445 | { |
443 | op->value = 1; |
446 | op->value = 1; |
444 | push_button (op); |
447 | push_button (op, tmp); |
445 | } |
448 | } |
446 | |
449 | |
447 | if (!detected && last == 1) |
450 | if (!detected && last == 1) |
448 | { |
451 | { |
449 | op->value = 0; |
452 | op->value = 0; |
450 | push_button (op); |
453 | push_button (op, tmp); |
451 | } |
454 | } |
452 | } |
455 | } |
453 | else |
456 | else |
454 | { /* in this case, we unset buttons */ |
457 | { /* in this case, we unset buttons */ |
455 | if (detected && last == 1) |
458 | if (detected && last == 1) |
456 | { |
459 | { |
457 | op->value = 0; |
460 | op->value = 0; |
458 | push_button (op); |
461 | push_button (op, tmp); |
459 | } |
462 | } |
460 | |
463 | |
461 | if (!detected && last == 0) |
464 | if (!detected && last == 0) |
462 | { |
465 | { |
463 | op->value = 1; |
466 | op->value = 1; |
464 | push_button (op); |
467 | push_button (op, tmp); |
465 | } |
468 | } |
466 | } |
469 | } |
467 | } |
470 | } |
468 | |
471 | |
469 | void |
472 | void |
… | |
… | |
545 | |
548 | |
546 | if (payload == NULL) |
549 | if (payload == NULL) |
547 | return NULL; |
550 | return NULL; |
548 | |
551 | |
549 | payload->remove (); |
552 | payload->remove (); |
550 | op->destroy (true); |
553 | op->destroy (); |
551 | return payload; |
554 | return payload; |
552 | } |
555 | } |
553 | |
556 | |
554 | case ARROW: |
557 | case ARROW: |
555 | if (op->has_active_speed ()) |
558 | if (op->has_active_speed ()) |
… | |
… | |
582 | fix_stopped_arrow (object *op) |
585 | fix_stopped_arrow (object *op) |
583 | { |
586 | { |
584 | if (rndm (0, 99) < op->stats.food) |
587 | if (rndm (0, 99) < op->stats.food) |
585 | { |
588 | { |
586 | /* Small chance of breaking */ |
589 | /* Small chance of breaking */ |
587 | op->destroy (true); |
590 | op->destroy (); |
588 | return NULL; |
591 | return NULL; |
589 | } |
592 | } |
590 | |
593 | |
591 | op->set_speed (0); |
594 | op->set_speed (0); |
592 | op->direction = 0; |
595 | op->direction = 0; |
… | |
… | |
638 | // replace this by straightforward drop to ground? |
641 | // replace this by straightforward drop to ground? |
639 | object *payload = op->inv; |
642 | object *payload = op->inv; |
640 | |
643 | |
641 | payload->owner = 0; |
644 | payload->owner = 0; |
642 | insert_ob_in_map (payload, op->map, payload, 0); |
645 | insert_ob_in_map (payload, op->map, payload, 0); |
643 | op->destroy (true); |
646 | op->destroy (); |
644 | } |
647 | } |
645 | else |
648 | else |
646 | { |
649 | { |
647 | op = fix_stopped_arrow (op); |
650 | op = fix_stopped_arrow (op); |
648 | |
651 | |
… | |
… | |
659 | int was_reflected; |
662 | int was_reflected; |
660 | |
663 | |
661 | if (!op->map) |
664 | if (!op->map) |
662 | { |
665 | { |
663 | LOG (llevError, "BUG: Arrow had no map.\n"); |
666 | LOG (llevError, "BUG: Arrow had no map.\n"); |
664 | op->destroy (true); |
667 | op->destroy (); |
665 | return; |
668 | return; |
666 | } |
669 | } |
667 | |
670 | |
668 | /* we need to stop thrown objects at some point. Like here. */ |
671 | /* we need to stop thrown objects at some point. Like here. */ |
669 | if (op->type == THROWN_OBJ) |
672 | if (op->type == THROWN_OBJ) |
… | |
… | |
676 | * bomb code, but there are potential other cases where that could happen, |
679 | * bomb code, but there are potential other cases where that could happen, |
677 | * and it is easy enough to clean it up here. |
680 | * and it is easy enough to clean it up here. |
678 | */ |
681 | */ |
679 | if (!op->inv) |
682 | if (!op->inv) |
680 | { |
683 | { |
681 | op->destroy (true); |
684 | op->destroy (); |
682 | return; |
685 | return; |
683 | } |
686 | } |
684 | |
687 | |
685 | if (op->last_sp-- < 0) |
688 | if (op->last_sp-- < 0) |
686 | { |
689 | { |
… | |
… | |
854 | op->remove (); |
857 | op->remove (); |
855 | for (i = 0; i < op->stats.food; i++) |
858 | for (i = 0; i < op->stats.food; i++) |
856 | { |
859 | { |
857 | object *tmp = arch_to_object (op->other_arch); |
860 | object *tmp = arch_to_object (op->other_arch); |
858 | |
861 | |
859 | if (op->type == LAMP) |
|
|
860 | tmp->stats.food = op->stats.food - 1; |
|
|
861 | |
|
|
862 | tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ |
862 | tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ |
863 | |
863 | |
864 | if (env) |
864 | if (env) |
865 | env->insert (tmp); |
865 | env->insert (tmp); |
866 | else |
866 | else |
867 | { |
867 | { |
868 | j = find_first_free_spot (tmp, op->map, op->x, op->y); |
868 | j = find_first_free_spot (tmp, op->map, op->x, op->y); |
869 | if (j < 0) /* No free spot */ |
869 | if (j < 0) /* No free spot */ |
870 | tmp->destroy (true); |
870 | tmp->destroy (); |
871 | else |
871 | else |
872 | { |
872 | { |
873 | mapxy pos (op); pos.move (j); |
873 | mapxy pos (op); pos.move (j); |
874 | |
874 | |
875 | if (pos.normalise ()) |
875 | if (pos.normalise ()) |
876 | pos.insert (tmp, op); |
876 | pos.insert (tmp, op); |
877 | } |
877 | } |
878 | } |
878 | } |
879 | } |
879 | } |
880 | |
880 | |
881 | op->destroy (true); |
881 | op->destroy (); |
882 | } |
882 | } |
883 | |
883 | |
884 | void |
884 | void |
885 | move_teleporter (object *op) |
885 | move_teleporter (object *op) |
886 | { |
886 | { |
… | |
… | |
923 | else if (EXIT_X (head) || EXIT_Y (head)) |
923 | else if (EXIT_X (head) || EXIT_Y (head)) |
924 | { |
924 | { |
925 | if (out_of_map (head->map, EXIT_X (head), EXIT_Y (head))) |
925 | if (out_of_map (head->map, EXIT_X (head), EXIT_Y (head))) |
926 | { |
926 | { |
927 | LOG (llevError, "Removed illegal teleporter.\n"); |
927 | LOG (llevError, "Removed illegal teleporter.\n"); |
928 | head->destroy (true); |
928 | head->destroy (); |
929 | return; |
929 | return; |
930 | } |
930 | } |
931 | |
931 | |
932 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
932 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
933 | return; |
933 | return; |
… | |
… | |
1127 | for (tmp = op->above; tmp; tmp = tmp->above) |
1127 | for (tmp = op->above; tmp; tmp = tmp->above) |
1128 | { |
1128 | { |
1129 | if (op->other_arch->archname == tmp->arch->archname) |
1129 | if (op->other_arch->archname == tmp->arch->archname) |
1130 | { |
1130 | { |
1131 | if (op->level <= 0) |
1131 | if (op->level <= 0) |
1132 | tmp->destroy (true); |
1132 | tmp->destroy (); |
1133 | else |
1133 | else |
1134 | { |
1134 | { |
1135 | uint64 new_nrof = (uint64) tmp->nrof * op->level; |
1135 | uint64 new_nrof = (uint64) tmp->nrof * op->level; |
1136 | |
1136 | |
1137 | if (new_nrof >= 1UL << 31) |
1137 | if (new_nrof >= 1UL << 31) |
… | |
… | |
1167 | { |
1167 | { |
1168 | creator->stats.hp = -1; |
1168 | creator->stats.hp = -1; |
1169 | return; |
1169 | return; |
1170 | } |
1170 | } |
1171 | |
1171 | |
1172 | if (creator->inv != NULL) |
1172 | if (creator->inv) |
1173 | { |
1173 | { |
1174 | object *ob; |
1174 | object *ob; |
1175 | int i; |
1175 | int i; |
1176 | object *ob_to_copy; |
1176 | object *ob_to_copy; |
1177 | |
1177 | |
… | |
… | |
1202 | } |
1202 | } |
1203 | |
1203 | |
1204 | /* Make sure this multipart object fits */ |
1204 | /* Make sure this multipart object fits */ |
1205 | if (new_ob->arch->more && new_ob->blocked (creator->map, creator->x, creator->y)) |
1205 | if (new_ob->arch->more && new_ob->blocked (creator->map, creator->x, creator->y)) |
1206 | { |
1206 | { |
1207 | op->destroy_inv (false); // remove when desttroy does this |
|
|
1208 | new_ob->destroy (true); |
1207 | new_ob->destroy (); |
1209 | return; |
1208 | return; |
1210 | } |
1209 | } |
1211 | |
1210 | |
1212 | // for now lets try to identify everything generated here, it mostly |
1211 | // for now lets try to identify everything generated here, it mostly |
1213 | // happens automated, so this will at least fix many identify-experience holes |
1212 | // happens automated, so this will at least fix many identify-experience holes |
… | |
… | |
1234 | { |
1233 | { |
1235 | if (object *tmp = op->ms ().player ()) |
1234 | if (object *tmp = op->ms ().player ()) |
1236 | { |
1235 | { |
1237 | /* remove an old force with a slaying field == op->name */ |
1236 | /* remove an old force with a slaying field == op->name */ |
1238 | if (object *force = tmp->force_find (op->name)) |
1237 | if (object *force = tmp->force_find (op->name)) |
1239 | force->destroy (true); |
1238 | force->destroy (); |
1240 | |
1239 | |
1241 | if (!tmp->force_find (op->slaying)) |
1240 | if (!tmp->force_find (op->slaying)) |
1242 | { |
1241 | { |
1243 | tmp->force_add (op->slaying, op->stats.food); |
1242 | tmp->force_add (op->slaying, op->stats.food); |
1244 | |
1243 | |
… | |
… | |
1250 | op->stats.hp--; |
1249 | op->stats.hp--; |
1251 | |
1250 | |
1252 | if (op->stats.hp == 0) |
1251 | if (op->stats.hp == 0) |
1253 | { |
1252 | { |
1254 | /* marker expires--granted mark number limit */ |
1253 | /* marker expires--granted mark number limit */ |
1255 | op->destroy (true); |
1254 | op->destroy (); |
1256 | return; |
1255 | return; |
1257 | } |
1256 | } |
1258 | } |
1257 | } |
1259 | } |
1258 | } |
1260 | } |
1259 | } |
|
|
1260 | } |
|
|
1261 | |
|
|
1262 | // mapscript objects activate themselves (only) then their timer fires |
|
|
1263 | // TODO: maybe they should simply trigger the link like any other object? |
|
|
1264 | void |
|
|
1265 | move_mapscript (object *op) |
|
|
1266 | { |
|
|
1267 | op->set_speed (0); |
|
|
1268 | cfperl_mapscript_activate (op, true, op, 0); |
|
|
1269 | } |
|
|
1270 | |
|
|
1271 | void move_lamp (object *op) |
|
|
1272 | { |
|
|
1273 | // if the lamp/torch is off, we should disable it. |
|
|
1274 | if (!op->glow_radius) |
|
|
1275 | { |
|
|
1276 | op->set_speed (0); |
|
|
1277 | return; |
|
|
1278 | } |
|
|
1279 | else |
|
|
1280 | { |
|
|
1281 | // check whether the face might needs to be updated |
|
|
1282 | // (currently this is needed to have already switched on torches |
|
|
1283 | // on maps, as they just set the glow_radius in the archetype) |
|
|
1284 | if (op->other_arch |
|
|
1285 | && ( |
|
|
1286 | op->flag [FLAG_ANIMATE] |
|
|
1287 | ? (op->animation_id != op->other_arch->animation_id) |
|
|
1288 | : (op->face != op->other_arch->face) |
|
|
1289 | )) |
|
|
1290 | get_animation_from_arch (op, op->other_arch); |
|
|
1291 | } |
|
|
1292 | |
|
|
1293 | // lamps and torches auf maps don't use up their fuel |
|
|
1294 | if (op->is_on_map ()) |
|
|
1295 | return; |
|
|
1296 | |
|
|
1297 | if (op->stats.food > 0) |
|
|
1298 | { |
|
|
1299 | op->stats.food--; |
|
|
1300 | return; |
|
|
1301 | } |
|
|
1302 | |
|
|
1303 | apply_lamp (op, false); |
1261 | } |
1304 | } |
1262 | |
1305 | |
1263 | void |
1306 | void |
1264 | process_object (object *op) |
1307 | process_object (object *op) |
1265 | { |
1308 | { |
… | |
… | |
1305 | op->remove (); // TODO: really necessary? |
1348 | op->remove (); // TODO: really necessary? |
1306 | |
1349 | |
1307 | if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) |
1350 | if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) |
1308 | make_sure_not_seen (op); |
1351 | make_sure_not_seen (op); |
1309 | |
1352 | |
1310 | op->destroy_inv (false); // be explicit about dropping |
|
|
1311 | op->destroy (true); |
1353 | op->drop_and_destroy (); |
1312 | } |
1354 | } |
1313 | |
1355 | |
1314 | return; |
1356 | return; |
1315 | } |
1357 | } |
1316 | } |
1358 | } |
… | |
… | |
1440 | |
1482 | |
1441 | case PLAYER: |
1483 | case PLAYER: |
1442 | // players have their own speed-management, so undo the --speed_left |
1484 | // players have their own speed-management, so undo the --speed_left |
1443 | ++op->speed_left; |
1485 | ++op->speed_left; |
1444 | break; |
1486 | break; |
1445 | } |
|
|
1446 | } |
|
|
1447 | |
1487 | |
|
|
1488 | case MAPSCRIPT: |
|
|
1489 | move_mapscript (op); |
|
|
1490 | break; |
|
|
1491 | |
|
|
1492 | case LAMP: |
|
|
1493 | case TORCH: |
|
|
1494 | move_lamp (op); |
|
|
1495 | break; |
|
|
1496 | } |
|
|
1497 | } |
|
|
1498 | |