1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | * |
20 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | /* |
24 | /* |
26 | * Routines that is executed from objects based on their speed have been |
25 | * Routines that is executed from objects based on their speed have been |
27 | * collected in this file. |
26 | * collected in this file. |
… | |
… | |
97 | |
96 | |
98 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
97 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
99 | return; |
98 | return; |
100 | |
99 | |
101 | object *op; |
100 | object *op; |
|
|
101 | int i; |
102 | |
102 | |
103 | if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
103 | if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
104 | { |
104 | { |
105 | // either copy one item form the inventory... |
105 | // either copy one item from the inventory... |
106 | if (!gen->inv) |
106 | if (!gen->inv) |
107 | return; |
107 | return; |
108 | |
108 | |
109 | // first select one item from the inventory |
109 | // first select one item from the inventory |
110 | int index = 0; |
110 | int index = 0; |
111 | for (object *tmp = gen->inv; tmp; tmp = tmp->below) |
111 | for (object *tmp = gen->inv; tmp; tmp = tmp->below) |
112 | if (!rndm (++index)) |
112 | if (!rndm (++index)) |
113 | op = tmp; |
113 | op = tmp; |
114 | |
114 | |
|
|
115 | i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9); |
|
|
116 | if (i < 0) |
|
|
117 | return; |
|
|
118 | |
115 | op = object_create_clone (op); |
119 | op = object_create_clone (op); |
116 | |
120 | |
117 | CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); |
121 | CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); |
118 | unflag_inv (op, FLAG_IS_A_TEMPLATE); |
122 | unflag_inv (op, FLAG_IS_A_TEMPLATE); |
119 | } |
123 | } |
|
|
124 | else if (gen->other_arch) |
|
|
125 | { |
|
|
126 | // ...or use other_arch |
|
|
127 | i = find_free_spot (gen->other_arch, gen->map, gen->x, gen->y, 1, 9); |
|
|
128 | if (i < 0) |
|
|
129 | return; |
|
|
130 | |
|
|
131 | op = arch_to_object (gen->other_arch); |
|
|
132 | } |
120 | else |
133 | else |
121 | { |
|
|
122 | // ...or use other_arch |
|
|
123 | if (archetype *at = gen->other_arch) |
|
|
124 | op = arch_to_object (at); |
|
|
125 | else |
|
|
126 | return; |
134 | return; |
127 | } |
|
|
128 | |
135 | |
129 | op->expand_tail (); |
136 | op->expand_tail (); |
130 | |
137 | |
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])) |
138 | if (insert_ob_in_map_at (op, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i])) |
135 | { |
139 | { |
136 | if (rndm (0, 9)) |
140 | if (rndm (0, 9)) |
137 | generate_artifact (op, gen->map->difficulty); |
141 | generate_artifact (op, gen->map->difficulty); |
138 | |
142 | |
139 | if (op->has_random_items ()) |
143 | if (op->has_random_items ()) |
140 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty); |
144 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty); |
141 | |
145 | |
142 | return; |
146 | return; |
143 | } |
|
|
144 | } |
147 | } |
145 | |
148 | |
146 | op->destroy (); |
149 | op->destroy (); |
147 | } |
150 | } |
148 | |
151 | |
… | |
… | |
235 | if (op->value) |
238 | if (op->value) |
236 | { |
239 | { |
237 | if (--op->stats.wc <= 0) |
240 | if (--op->stats.wc <= 0) |
238 | { /* Reached bottom, let's stop */ |
241 | { /* Reached bottom, let's stop */ |
239 | op->stats.wc = 0; |
242 | op->stats.wc = 0; |
240 | if (op->arch->clone.speed) |
243 | if (op->arch->speed) |
241 | op->value = 0; |
244 | op->value = 0; |
242 | else |
245 | else |
243 | op->set_speed (0); |
246 | op->set_speed (0); |
244 | } |
247 | } |
245 | |
248 | |
… | |
… | |
271 | if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE)) |
274 | if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE)) |
272 | break; |
275 | break; |
273 | |
276 | |
274 | if (tmp == NULL) |
277 | if (tmp == NULL) |
275 | { |
278 | { |
276 | if (op->arch->clone.speed) |
279 | if (op->arch->speed) |
277 | op->value = 1; |
280 | op->value = 1; |
278 | else |
281 | else |
279 | op->set_speed (0); |
282 | op->set_speed (0); |
280 | |
283 | |
281 | return; |
284 | return; |
… | |
… | |
347 | op->stats.food = 1; |
350 | op->stats.food = 1; |
348 | } |
351 | } |
349 | else |
352 | else |
350 | { |
353 | { |
351 | op->move_block = MOVE_ALL; |
354 | op->move_block = MOVE_ALL; |
352 | if (!op->arch->clone.stats.ac) |
355 | if (!op->arch->stats.ac) |
353 | SET_FLAG (op, FLAG_BLOCKSVIEW); |
356 | SET_FLAG (op, FLAG_BLOCKSVIEW); |
354 | update_all_los (op->map, op->x, op->y); |
357 | update_all_los (op->map, op->x, op->y); |
355 | } |
358 | } |
356 | } /* gate is halfway up */ |
359 | } /* gate is halfway up */ |
357 | |
360 | |
… | |
… | |
598 | op->spellarg = NULL; |
601 | op->spellarg = NULL; |
599 | op->stats.sp = 0; |
602 | op->stats.sp = 0; |
600 | op->stats.hp = 0; |
603 | op->stats.hp = 0; |
601 | op->stats.grace = 0; |
604 | op->stats.grace = 0; |
602 | op->level = 0; |
605 | op->level = 0; |
603 | op->face = op->arch->clone.face; |
606 | op->face = op->arch->face; |
604 | op->owner = NULL; /* So that stopped arrows will be saved */ |
607 | op->owner = NULL; /* So that stopped arrows will be saved */ |
605 | update_object (op, UP_OBJ_CHANGE); |
608 | update_object (op, UP_OBJ_CHANGE); |
606 | return op; |
609 | return op; |
607 | } |
610 | } |
608 | |
611 | |
… | |
… | |
910 | move_teleporter (op->more); |
913 | move_teleporter (op->more); |
911 | |
914 | |
912 | if (op->head) |
915 | if (op->head) |
913 | head = op->head; |
916 | head = op->head; |
914 | |
917 | |
915 | for (tmp = op->above; tmp != NULL; tmp = tmp->above) |
918 | for (tmp = op->above; tmp; tmp = tmp->above) |
916 | if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
919 | if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
917 | break; |
920 | break; |
918 | |
921 | |
919 | /* If nothing above us to move, nothing to do */ |
922 | /* If nothing above us to move, nothing to do */ |
920 | if (!tmp || QUERY_FLAG (tmp, FLAG_WIZPASS)) |
923 | if (!tmp || QUERY_FLAG (tmp, FLAG_WIZPASS)) |
… | |
… | |
1015 | return; /* dm has created a firewall in his inventory */ |
1018 | return; /* dm has created a firewall in his inventory */ |
1016 | |
1019 | |
1017 | spell = op->inv; |
1020 | spell = op->inv; |
1018 | |
1021 | |
1019 | if (!spell || spell->type != SPELL) |
1022 | if (!spell || spell->type != SPELL) |
1020 | spell = &op->other_arch->clone; |
1023 | spell = op->other_arch; |
1021 | |
1024 | |
1022 | if (!spell) |
1025 | if (!spell) |
1023 | { |
1026 | { |
1024 | LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, &op->map->name, op->x, op->y); |
1027 | LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, &op->map->name, op->x, op->y); |
1025 | return; |
1028 | return; |
… | |
… | |
1136 | if (op->above == NULL) |
1139 | if (op->above == NULL) |
1137 | return; |
1140 | return; |
1138 | |
1141 | |
1139 | for (tmp = op->above; tmp; tmp = tmp->above) |
1142 | for (tmp = op->above; tmp; tmp = tmp->above) |
1140 | { |
1143 | { |
1141 | if (op->other_arch->name == tmp->arch->name) |
1144 | if (op->other_arch->archname == tmp->arch->archname) |
1142 | { |
1145 | { |
1143 | if (op->level <= 0) |
1146 | if (op->level <= 0) |
1144 | tmp->destroy (); |
1147 | tmp->destroy (); |
1145 | else |
1148 | else |
1146 | { |
1149 | { |
… | |
… | |
1168 | * has to make sure that there is in fact space for the object. |
1171 | * has to make sure that there is in fact space for the object. |
1169 | * It should really do this for small objects also, but there is |
1172 | * It should really do this for small objects also, but there is |
1170 | * more concern with large objects, most notably a part being placed |
1173 | * more concern with large objects, most notably a part being placed |
1171 | * outside of the map which would cause the server to crash |
1174 | * outside of the map which would cause the server to crash |
1172 | */ |
1175 | */ |
1173 | |
|
|
1174 | void |
1176 | void |
1175 | move_creator (object *creator) |
1177 | move_creator (object *creator) |
1176 | { |
1178 | { |
1177 | object *new_ob; |
1179 | object *new_ob; |
1178 | |
1180 | |
… | |
… | |
1218 | if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y)) |
1220 | if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y)) |
1219 | { |
1221 | { |
1220 | new_ob->destroy (); |
1222 | new_ob->destroy (); |
1221 | return; |
1223 | return; |
1222 | } |
1224 | } |
|
|
1225 | |
|
|
1226 | // for now lets try to identify everything generated here, it mostly |
|
|
1227 | // happens automated, so this will at least fix many identify-experience holes |
|
|
1228 | SET_FLAG (new_ob, FLAG_IDENTIFIED); |
1223 | |
1229 | |
1224 | insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); |
1230 | insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); |
1225 | if (QUERY_FLAG (new_ob, FLAG_FREED)) |
1231 | if (QUERY_FLAG (new_ob, FLAG_FREED)) |
1226 | return; |
1232 | return; |
1227 | |
1233 | |
… | |
… | |
1242 | void |
1248 | void |
1243 | move_marker (object *op) |
1249 | move_marker (object *op) |
1244 | { |
1250 | { |
1245 | if (object *tmp = op->ms ().player ()) |
1251 | if (object *tmp = op->ms ().player ()) |
1246 | { |
1252 | { |
1247 | object *tmp2; |
|
|
1248 | |
|
|
1249 | /* remove an old force with a slaying field == op->name */ |
1253 | /* remove an old force with a slaying field == op->name */ |
1250 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
1254 | if (object *force = tmp->force_find (op->name)) |
1251 | if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->name) |
1255 | force->destroy (); |
|
|
1256 | |
|
|
1257 | if (!tmp->force_find (op->slaying)) |
1252 | { |
1258 | { |
1253 | tmp2->destroy (); |
1259 | tmp->force_add (op->slaying, op->stats.food); |
1254 | break; |
|
|
1255 | } |
|
|
1256 | |
1260 | |
1257 | /* cycle through his inventory to look for the MARK we want to |
|
|
1258 | * place |
|
|
1259 | */ |
|
|
1260 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
|
|
1261 | if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying) |
|
|
1262 | break; |
|
|
1263 | |
|
|
1264 | /* if we didn't find our own MARK */ |
|
|
1265 | if (!tmp2) |
|
|
1266 | { |
|
|
1267 | object *force = get_archetype (FORCE_NAME); |
|
|
1268 | |
|
|
1269 | if (op->stats.food) |
|
|
1270 | { |
|
|
1271 | force->set_speed (0.01); |
|
|
1272 | force->speed_left = -op->stats.food; |
|
|
1273 | } |
|
|
1274 | else |
|
|
1275 | force->set_speed (0); |
|
|
1276 | |
|
|
1277 | /* put in the lock code */ |
|
|
1278 | force->slaying = op->slaying; |
|
|
1279 | |
|
|
1280 | if (op->lore) |
|
|
1281 | force->lore = op->lore; |
|
|
1282 | |
|
|
1283 | insert_ob_in_ob (force, tmp); |
|
|
1284 | if (op->msg) |
1261 | if (op->msg) |
1285 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); |
1262 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); |
1286 | |
1263 | |
1287 | if (op->stats.hp > 0) |
1264 | if (op->stats.hp > 0) |
1288 | { |
1265 | { |
1289 | op->stats.hp--; |
1266 | op->stats.hp--; |
|
|
1267 | |
1290 | if (op->stats.hp == 0) |
1268 | if (op->stats.hp == 0) |
1291 | { |
1269 | { |
1292 | /* marker expires--granted mark number limit */ |
1270 | /* marker expires--granted mark number limit */ |
1293 | op->destroy (); |
1271 | op->destroy (); |
1294 | return; |
1272 | return; |
… | |
… | |
1299 | } |
1277 | } |
1300 | |
1278 | |
1301 | void |
1279 | void |
1302 | process_object (object *op) |
1280 | process_object (object *op) |
1303 | { |
1281 | { |
1304 | if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) |
1282 | if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))) |
1305 | return; |
1283 | return; |
1306 | |
1284 | |
1307 | if (INVOKE_OBJECT (TICK, op)) |
1285 | if (expect_false (INVOKE_OBJECT (TICK, op))) |
1308 | return; |
1286 | return; |
1309 | |
1287 | |
1310 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1288 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1311 | if (move_monster (op) || QUERY_FLAG (op, FLAG_FREED)) |
1289 | if (move_monster (op) || QUERY_FLAG (op, FLAG_FREED)) |
1312 | return; |
1290 | return; |
… | |
… | |
1317 | |
1295 | |
1318 | if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) |
1296 | if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) |
1319 | make_sure_seen (op); |
1297 | make_sure_seen (op); |
1320 | } |
1298 | } |
1321 | |
1299 | |
|
|
1300 | if (expect_false ( |
1322 | if (op->flag [FLAG_GENERATOR] |
1301 | op->flag [FLAG_GENERATOR] |
1323 | || op->flag [FLAG_CHANGING] |
1302 | || op->flag [FLAG_CHANGING] |
1324 | || op->flag [FLAG_IS_USED_UP]) |
1303 | || op->flag [FLAG_IS_USED_UP] |
|
|
1304 | )) |
1325 | { |
1305 | { |
1326 | if (QUERY_FLAG (op, FLAG_CHANGING) && !op->state) |
1306 | if (QUERY_FLAG (op, FLAG_CHANGING) && !op->state) |
1327 | { |
1307 | { |
1328 | change_object (op); |
1308 | change_object (op); |
1329 | return; |
1309 | return; |