1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
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 (); |
62 | op->drop_and_destroy (); |
63 | } |
63 | } |
64 | |
64 | |
65 | void |
65 | void |
66 | remove_door2 (object *op) |
66 | remove_door2 (object *op) |
67 | { |
67 | { |
… | |
… | |
86 | tmp->map = op->map; |
86 | tmp->map = op->map; |
87 | tmp->level = op->level; |
87 | tmp->level = op->level; |
88 | insert_ob_in_map (tmp, op->map, op, 0); |
88 | insert_ob_in_map (tmp, op->map, op, 0); |
89 | } |
89 | } |
90 | |
90 | |
91 | op->destroy (); |
91 | op->drop_and_destroy (); |
92 | } |
92 | } |
93 | |
93 | |
94 | void |
94 | void |
95 | generate_monster (object *gen) |
95 | generate_monster (object *gen) |
96 | { |
96 | { |
… | |
… | |
117 | |
117 | |
118 | dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1); |
118 | dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1); |
119 | if (dir < 0) |
119 | if (dir < 0) |
120 | return; |
120 | return; |
121 | |
121 | |
122 | op = object_create_clone (op); |
122 | op = op->deep_clone (); |
123 | |
123 | |
124 | CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); |
124 | CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); |
125 | unflag_inv (op, FLAG_IS_A_TEMPLATE); |
125 | unflag_inv (op, FLAG_IS_A_TEMPLATE); |
126 | } |
126 | } |
127 | else if (gen->other_arch) |
127 | else if (gen->other_arch) |
… | |
… | |
149 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty); |
149 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty); |
150 | |
150 | |
151 | return; |
151 | return; |
152 | } |
152 | } |
153 | |
153 | |
154 | op->destroy (); |
154 | op->destroy (true); |
155 | } |
155 | } |
156 | |
156 | |
157 | void |
157 | void |
158 | remove_force (object *op) |
158 | remove_force (object *op) |
159 | { |
159 | { |
… | |
… | |
171 | CLEAR_FLAG (op, FLAG_APPLIED); |
171 | CLEAR_FLAG (op, FLAG_APPLIED); |
172 | change_abil (op->env, op); |
172 | change_abil (op->env, op); |
173 | op->env->update_stats (); |
173 | op->env->update_stats (); |
174 | } |
174 | } |
175 | |
175 | |
176 | op->destroy (); |
176 | op->destroy (true); |
177 | } |
177 | } |
178 | |
178 | |
179 | void |
179 | void |
180 | remove_blindness (object *op) |
180 | remove_blindness (object *op) |
181 | { |
181 | { |
… | |
… | |
188 | { |
188 | { |
189 | change_abil (op->env, op); |
189 | change_abil (op->env, op); |
190 | op->env->update_stats (); |
190 | op->env->update_stats (); |
191 | } |
191 | } |
192 | |
192 | |
193 | op->destroy (); |
193 | op->destroy (true); |
194 | } |
194 | } |
195 | |
195 | |
196 | void |
196 | void |
197 | poison_more (object *op) |
197 | poison_more (object *op) |
198 | { |
198 | { |
199 | if (op->env == NULL || !QUERY_FLAG (op->env, FLAG_ALIVE) || op->env->stats.hp < 0) |
199 | if (op->env == NULL || !QUERY_FLAG (op->env, FLAG_ALIVE) || op->env->stats.hp < 0) |
200 | { |
200 | { |
201 | op->destroy (); |
201 | op->destroy (true); |
202 | return; |
202 | return; |
203 | } |
203 | } |
204 | |
204 | |
205 | if (op->stats.food == 1) |
205 | if (op->stats.food == 1) |
206 | { |
206 | { |
… | |
… | |
212 | CLEAR_FLAG (op, FLAG_APPLIED); |
212 | CLEAR_FLAG (op, FLAG_APPLIED); |
213 | op->env->update_stats (); |
213 | op->env->update_stats (); |
214 | new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now."); |
214 | new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now."); |
215 | } |
215 | } |
216 | |
216 | |
217 | op->destroy (); |
217 | op->destroy (true); |
218 | return; |
218 | return; |
219 | } |
219 | } |
220 | |
220 | |
221 | if (op->env->type == PLAYER) |
221 | if (op->env->type == PLAYER) |
222 | { |
222 | { |
… | |
… | |
480 | } |
480 | } |
481 | |
481 | |
482 | void |
482 | void |
483 | move_hole (object *op) |
483 | move_hole (object *op) |
484 | { /* 1 = opening, 0 = closing */ |
484 | { /* 1 = opening, 0 = closing */ |
485 | object *next, *tmp; |
|
|
486 | |
|
|
487 | if (op->value) |
485 | if (op->value) |
488 | { /* We're opening */ |
486 | { /* We're opening */ |
489 | if (--op->stats.wc <= 0) |
487 | if (--op->stats.wc <= 0) |
490 | { /* Opened, let's stop */ |
488 | { /* Opened, let's stop */ |
491 | op->stats.wc = 0; |
489 | op->stats.wc = 0; |
492 | op->set_speed (0); |
490 | op->set_speed (0); |
493 | |
491 | |
494 | /* Hard coding this makes sense for holes I suppose */ |
492 | /* Hard coding this makes sense for holes I suppose */ |
495 | op->move_on = MOVE_WALK; |
493 | op->move_on = MOVE_WALK; |
496 | for (tmp = op->above; tmp != NULL; tmp = next) |
494 | for (object *next, *tmp = op->above; tmp; tmp = next) |
497 | { |
495 | { |
498 | next = tmp->above; |
496 | next = tmp->above; |
499 | move_apply (op, tmp, tmp); |
497 | move_apply (op, tmp, tmp); |
500 | } |
498 | } |
501 | } |
499 | } |
… | |
… | |
543 | { |
541 | { |
544 | object *payload = op->inv; |
542 | object *payload = op->inv; |
545 | |
543 | |
546 | if (payload == NULL) |
544 | if (payload == NULL) |
547 | return NULL; |
545 | return NULL; |
|
|
546 | |
548 | payload->remove (); |
547 | payload->remove (); |
549 | op->destroy (); |
548 | op->destroy (true); |
550 | return payload; |
549 | return payload; |
551 | } |
550 | } |
552 | |
551 | |
553 | case ARROW: |
552 | case ARROW: |
554 | if (op->has_active_speed ()) |
553 | if (op->has_active_speed ()) |
… | |
… | |
581 | fix_stopped_arrow (object *op) |
580 | fix_stopped_arrow (object *op) |
582 | { |
581 | { |
583 | if (rndm (0, 99) < op->stats.food) |
582 | if (rndm (0, 99) < op->stats.food) |
584 | { |
583 | { |
585 | /* Small chance of breaking */ |
584 | /* Small chance of breaking */ |
586 | op->destroy (); |
585 | op->destroy (true); |
587 | return NULL; |
586 | return NULL; |
588 | } |
587 | } |
589 | |
588 | |
590 | op->set_speed (0); |
589 | op->set_speed (0); |
591 | op->direction = 0; |
590 | op->direction = 0; |
… | |
… | |
632 | if (INVOKE_OBJECT (STOP, op)) |
631 | if (INVOKE_OBJECT (STOP, op)) |
633 | return; |
632 | return; |
634 | |
633 | |
635 | if (op->inv) |
634 | if (op->inv) |
636 | { |
635 | { |
|
|
636 | // replace this by straightforward drop to ground? |
637 | object *payload = op->inv; |
637 | object *payload = op->inv; |
638 | |
638 | |
639 | payload->remove (); |
|
|
640 | payload->owner = 0; |
639 | payload->owner = 0; |
641 | insert_ob_in_map (payload, op->map, payload, 0); |
640 | insert_ob_in_map (payload, op->map, payload, 0); |
642 | op->destroy (); |
641 | op->destroy (true); |
643 | } |
642 | } |
644 | else |
643 | else |
645 | { |
644 | { |
646 | op = fix_stopped_arrow (op); |
645 | op = fix_stopped_arrow (op); |
647 | |
646 | |
… | |
… | |
658 | int was_reflected; |
657 | int was_reflected; |
659 | |
658 | |
660 | if (!op->map) |
659 | if (!op->map) |
661 | { |
660 | { |
662 | LOG (llevError, "BUG: Arrow had no map.\n"); |
661 | LOG (llevError, "BUG: Arrow had no map.\n"); |
663 | op->destroy (); |
662 | op->destroy (true); |
664 | return; |
663 | return; |
665 | } |
664 | } |
666 | |
665 | |
667 | /* we need to stop thrown objects at some point. Like here. */ |
666 | /* we need to stop thrown objects at some point. Like here. */ |
668 | if (op->type == THROWN_OBJ) |
667 | if (op->type == THROWN_OBJ) |
… | |
… | |
673 | * is if the player throws a bomb - the bomb explodes on its own, |
672 | * is if the player throws a bomb - the bomb explodes on its own, |
674 | * but this object sticks around. We could handle the cleanup in the |
673 | * but this object sticks around. We could handle the cleanup in the |
675 | * bomb code, but there are potential other cases where that could happen, |
674 | * bomb code, but there are potential other cases where that could happen, |
676 | * and it is easy enough to clean it up here. |
675 | * and it is easy enough to clean it up here. |
677 | */ |
676 | */ |
678 | if (op->inv == NULL) |
677 | if (!op->inv) |
679 | { |
678 | { |
680 | op->destroy (); |
679 | op->destroy (true); |
681 | return; |
680 | return; |
682 | } |
681 | } |
683 | |
682 | |
684 | if (op->last_sp-- < 0) |
683 | if (op->last_sp-- < 0) |
685 | { |
684 | { |
… | |
… | |
857 | |
856 | |
858 | if (op->type == LAMP) |
857 | if (op->type == LAMP) |
859 | tmp->stats.food = op->stats.food - 1; |
858 | tmp->stats.food = op->stats.food - 1; |
860 | |
859 | |
861 | tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ |
860 | tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ |
|
|
861 | |
862 | if (env) |
862 | if (env) |
863 | { |
|
|
864 | tmp = env->insert (tmp); |
863 | env->insert (tmp); |
865 | |
|
|
866 | /* If this object is the players inventory, we need to tell the |
|
|
867 | * client of the change. Insert_ob_in_map takes care of the |
|
|
868 | * updating the client, so we don't need to do that below. |
|
|
869 | */ |
|
|
870 | if (object *pl = op->in_player ()) |
|
|
871 | { |
|
|
872 | esrv_del_item (pl->contr, op->count); |
|
|
873 | esrv_send_item (pl, tmp); |
|
|
874 | } |
|
|
875 | } |
|
|
876 | else |
864 | else |
877 | { |
865 | { |
878 | j = find_first_free_spot (tmp, op->map, op->x, op->y); |
866 | j = find_first_free_spot (tmp, op->map, op->x, op->y); |
879 | if (j < 0) /* No free spot */ |
867 | if (j < 0) /* No free spot */ |
880 | tmp->destroy (); |
868 | tmp->destroy (true); |
881 | else |
869 | else |
882 | { |
870 | { |
883 | mapxy pos (op); pos.move (j); |
871 | mapxy pos (op); pos.move (j); |
884 | |
872 | |
885 | if (pos.normalise ()) |
873 | if (pos.normalise ()) |
886 | pos.insert (tmp, op); |
874 | pos.insert (tmp, op); |
887 | } |
875 | } |
888 | } |
876 | } |
889 | } |
877 | } |
890 | |
878 | |
891 | op->destroy (); |
879 | op->destroy (true); |
892 | } |
880 | } |
893 | |
881 | |
894 | void |
882 | void |
895 | move_teleporter (object *op) |
883 | move_teleporter (object *op) |
896 | { |
884 | { |
… | |
… | |
933 | else if (EXIT_X (head) || EXIT_Y (head)) |
921 | else if (EXIT_X (head) || EXIT_Y (head)) |
934 | { |
922 | { |
935 | if (out_of_map (head->map, EXIT_X (head), EXIT_Y (head))) |
923 | if (out_of_map (head->map, EXIT_X (head), EXIT_Y (head))) |
936 | { |
924 | { |
937 | LOG (llevError, "Removed illegal teleporter.\n"); |
925 | LOG (llevError, "Removed illegal teleporter.\n"); |
938 | head->destroy (); |
926 | head->destroy (true); |
939 | return; |
927 | return; |
940 | } |
928 | } |
941 | |
929 | |
942 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
930 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
943 | return; |
931 | return; |
… | |
… | |
947 | else |
935 | else |
948 | { |
936 | { |
949 | /* Random teleporter */ |
937 | /* Random teleporter */ |
950 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
938 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
951 | return; |
939 | return; |
|
|
940 | |
952 | teleport (head, TELEPORTER, tmp); |
941 | teleport (head, TELEPORTER, tmp); |
953 | } |
942 | } |
954 | } |
943 | } |
955 | |
944 | |
956 | /* This object will teleport someone to a different map |
945 | /* This object will teleport someone to a different map |
… | |
… | |
1136 | for (tmp = op->above; tmp; tmp = tmp->above) |
1125 | for (tmp = op->above; tmp; tmp = tmp->above) |
1137 | { |
1126 | { |
1138 | if (op->other_arch->archname == tmp->arch->archname) |
1127 | if (op->other_arch->archname == tmp->arch->archname) |
1139 | { |
1128 | { |
1140 | if (op->level <= 0) |
1129 | if (op->level <= 0) |
1141 | tmp->destroy (); |
1130 | tmp->destroy (true); |
1142 | else |
1131 | else |
1143 | { |
1132 | { |
1144 | uint64 new_nrof = (uint64) tmp->nrof * op->level; |
1133 | uint64 new_nrof = (uint64) tmp->nrof * op->level; |
1145 | |
1134 | |
1146 | if (new_nrof >= 1UL << 31) |
1135 | if (new_nrof >= 1UL << 31) |
… | |
… | |
1176 | { |
1165 | { |
1177 | creator->stats.hp = -1; |
1166 | creator->stats.hp = -1; |
1178 | return; |
1167 | return; |
1179 | } |
1168 | } |
1180 | |
1169 | |
1181 | if (creator->inv != NULL) |
1170 | if (creator->inv) |
1182 | { |
1171 | { |
1183 | object *ob; |
1172 | object *ob; |
1184 | int i; |
1173 | int i; |
1185 | object *ob_to_copy; |
1174 | object *ob_to_copy; |
1186 | |
1175 | |
… | |
… | |
1191 | if (rndm (0, i) == 0) |
1180 | if (rndm (0, i) == 0) |
1192 | { |
1181 | { |
1193 | ob_to_copy = ob; |
1182 | ob_to_copy = ob; |
1194 | } |
1183 | } |
1195 | } |
1184 | } |
1196 | new_ob = object_create_clone (ob_to_copy); |
1185 | new_ob = ob_to_copy->deep_clone (); |
1197 | CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE); |
1186 | CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE); |
1198 | unflag_inv (new_ob, FLAG_IS_A_TEMPLATE); |
1187 | unflag_inv (new_ob, FLAG_IS_A_TEMPLATE); |
1199 | } |
1188 | } |
1200 | else |
1189 | else |
1201 | { |
1190 | { |
1202 | if (creator->other_arch == NULL) |
1191 | if (!creator->other_arch) |
1203 | { |
1192 | { |
1204 | LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", |
1193 | LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", |
1205 | &creator->name, &creator->map->path, creator->x, creator->y); |
1194 | &creator->name, &creator->map->path, creator->x, creator->y); |
1206 | return; |
1195 | return; |
1207 | } |
1196 | } |
… | |
… | |
1224 | insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); |
1213 | insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); |
1225 | if (QUERY_FLAG (new_ob, FLAG_FREED)) |
1214 | if (QUERY_FLAG (new_ob, FLAG_FREED)) |
1226 | return; |
1215 | return; |
1227 | |
1216 | |
1228 | if (creator->slaying) |
1217 | if (creator->slaying) |
1229 | { |
|
|
1230 | new_ob->name = new_ob->title = creator->slaying; |
1218 | new_ob->name = new_ob->title = creator->slaying; |
1231 | } |
|
|
1232 | } |
1219 | } |
1233 | |
1220 | |
1234 | /* move_marker --peterm@soda.csua.berkeley.edu |
1221 | /* move_marker --peterm@soda.csua.berkeley.edu |
1235 | when moved, a marker will search for a player sitting above |
1222 | when moved, a marker will search for a player sitting above |
1236 | it, and insert an invisible, weightless force into him |
1223 | it, and insert an invisible, weightless force into him |
… | |
… | |
1244 | { |
1231 | { |
1245 | if (object *tmp = op->ms ().player ()) |
1232 | if (object *tmp = op->ms ().player ()) |
1246 | { |
1233 | { |
1247 | /* remove an old force with a slaying field == op->name */ |
1234 | /* remove an old force with a slaying field == op->name */ |
1248 | if (object *force = tmp->force_find (op->name)) |
1235 | if (object *force = tmp->force_find (op->name)) |
1249 | force->destroy (); |
1236 | force->destroy (true); |
1250 | |
1237 | |
1251 | if (!tmp->force_find (op->slaying)) |
1238 | if (!tmp->force_find (op->slaying)) |
1252 | { |
1239 | { |
1253 | tmp->force_add (op->slaying, op->stats.food); |
1240 | tmp->force_add (op->slaying, op->stats.food); |
1254 | |
1241 | |
… | |
… | |
1260 | op->stats.hp--; |
1247 | op->stats.hp--; |
1261 | |
1248 | |
1262 | if (op->stats.hp == 0) |
1249 | if (op->stats.hp == 0) |
1263 | { |
1250 | { |
1264 | /* marker expires--granted mark number limit */ |
1251 | /* marker expires--granted mark number limit */ |
1265 | op->destroy (); |
1252 | op->destroy (true); |
1266 | return; |
1253 | return; |
1267 | } |
1254 | } |
1268 | } |
1255 | } |
1269 | } |
1256 | } |
1270 | } |
1257 | } |
… | |
… | |
1310 | { |
1297 | { |
1311 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
1298 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
1312 | remove_force (op); |
1299 | remove_force (op); |
1313 | else |
1300 | else |
1314 | { |
1301 | { |
1315 | /* If necessary, delete the item from the players inventory */ |
1302 | op->remove (); // TODO: really necessary? |
1316 | if (object *pl = op->in_player ()) |
|
|
1317 | esrv_del_item (pl->contr, op->count); |
|
|
1318 | |
|
|
1319 | op->remove (); |
|
|
1320 | |
1303 | |
1321 | if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) |
1304 | if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) |
1322 | make_sure_not_seen (op); |
1305 | make_sure_not_seen (op); |
1323 | |
1306 | |
1324 | op->destroy (); |
1307 | op->drop_and_destroy (); |
1325 | } |
1308 | } |
1326 | |
1309 | |
1327 | return; |
1310 | return; |
1328 | } |
1311 | } |
1329 | } |
1312 | } |