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.51 by root, Fri May 18 20:45:37 2007 UTC vs.
Revision 1.65 by root, Mon Aug 27 05:40:57 2007 UTC

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
265 * objects are above the gate. If so, we finish closing the gate, 268 * objects are above the gate. If so, we finish closing the gate,
266 * otherwise, we fall through to the code below which should lower 269 * otherwise, we fall through to the code below which should lower
267 * the gate slightly. 270 * the gate slightly.
268 */ 271 */
269 272
270 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 273 for (tmp = op->above; tmp; tmp = tmp->above)
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)
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;
310 if (tmp) 313 if (tmp)
311 { 314 {
312 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 315 if (QUERY_FLAG (tmp, FLAG_ALIVE))
313 { 316 {
314 hit_player (tmp, random_roll (0, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1); 317 hit_player (tmp, random_roll (0, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1);
318 op->play_sound (sound_find ("blocked_gate"));
315 319
316 if (tmp->type == PLAYER) 320 if (tmp->type == PLAYER)
317 new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name); 321 new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name);
318 } 322 }
319 else
320 /* If the object is not alive, and the object either can 323 /* If the object is not alive, and the object either can
321 * be picked up or the object rolls, move the object 324 * be picked up or the object rolls, move the object
322 * off the gate. 325 * off the gate.
323 */ 326 */
324 if (!QUERY_FLAG (tmp, FLAG_ALIVE) && (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL))) 327 else if (!QUERY_FLAG (tmp, FLAG_ALIVE) && (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL)))
325 { 328 {
326 /* If it has speed, it should move itself, otherwise: */ 329 /* If it has speed, it should move itself, otherwise: */
327 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); 330 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9);
328 331
329 /* If there is a free spot, move the object someplace */ 332 /* If there is a free spot, move the object someplace */
335 } 338 }
336 } 339 }
337 } 340 }
338 341
339 /* See if there is still anything blocking the gate */ 342 /* See if there is still anything blocking the gate */
340 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 343 for (tmp = op->above; tmp; tmp = tmp->above)
341 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE)) 344 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE))
342 break; 345 break;
343 346
344 /* IF there is, start putting the gate down */ 347 /* IF there is, start putting the gate down */
345 if (tmp) 348 if (tmp)
346 {
347 op->stats.food = 1; 349 op->stats.food = 1;
348 }
349 else 350 else
350 { 351 {
351 op->move_block = MOVE_ALL; 352 op->move_block = MOVE_ALL;
353
352 if (!op->arch->clone.stats.ac) 354 if (!op->arch->stats.ac)
353 SET_FLAG (op, FLAG_BLOCKSVIEW); 355 SET_FLAG (op, FLAG_BLOCKSVIEW);
354 update_all_los (op->map, op->x, op->y); 356 update_all_los (op->map, op->x, op->y);
355 } 357 }
356 } /* gate is halfway up */ 358 } /* gate is halfway up */
357 359
370 int v = op->value; 372 int v = op->value;
371 373
372 if (op->stats.sp) 374 if (op->stats.sp)
373 { 375 {
374 move_gate (op); 376 move_gate (op);
377
375 if (op->value != v) /* change direction ? */ 378 if (op->value != v) /* change direction ? */
376 op->stats.sp = 0; 379 op->stats.sp = 0;
377 return; 380 return;
378 } 381 }
382
379 if (--op->stats.hp <= 0) 383 if (--op->stats.hp <= 0)
380 { /* keep gate down */ 384 { /* keep gate down */
381 move_gate (op); 385 move_gate (op);
386
382 if (op->value != v) 387 if (op->value != v)
383 op->set_speed (0); 388 op->set_speed (0);
384 } 389 }
385} 390}
386 391
398 int last = op->value; 403 int last = op->value;
399 int detected; 404 int detected;
400 405
401 detected = 0; 406 detected = 0;
402 407
403 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL && !detected; tmp = tmp->above) 408 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp && !detected; tmp = tmp->above)
404 { 409 {
405 object *tmp2; 410 object *tmp2;
406 411
407 if (op->stats.hp) 412 if (op->stats.hp)
408 { 413 {
428 if (detected && last == 0) 433 if (detected && last == 0)
429 { 434 {
430 op->value = 1; 435 op->value = 1;
431 push_button (op); 436 push_button (op);
432 } 437 }
438
433 if (!detected && last == 1) 439 if (!detected && last == 1)
434 { 440 {
435 op->value = 0; 441 op->value = 0;
436 push_button (op); 442 push_button (op);
437 } 443 }
441 if (detected && last == 1) 447 if (detected && last == 1)
442 { 448 {
443 op->value = 0; 449 op->value = 0;
444 push_button (op); 450 push_button (op);
445 } 451 }
452
446 if (!detected && last == 0) 453 if (!detected && last == 0)
447 { 454 {
448 op->value = 1; 455 op->value = 1;
449 push_button (op); 456 push_button (op);
450 } 457 }
598 op->spellarg = NULL; 605 op->spellarg = NULL;
599 op->stats.sp = 0; 606 op->stats.sp = 0;
600 op->stats.hp = 0; 607 op->stats.hp = 0;
601 op->stats.grace = 0; 608 op->stats.grace = 0;
602 op->level = 0; 609 op->level = 0;
603 op->face = op->arch->clone.face; 610 op->face = op->arch->face;
604 op->owner = NULL; /* So that stopped arrows will be saved */ 611 op->owner = NULL; /* So that stopped arrows will be saved */
605 update_object (op, UP_OBJ_CHANGE); 612 update_object (op, UP_OBJ_CHANGE);
606 return op; 613 return op;
607} 614}
608 615
910 move_teleporter (op->more); 917 move_teleporter (op->more);
911 918
912 if (op->head) 919 if (op->head)
913 head = op->head; 920 head = op->head;
914 921
915 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 922 for (tmp = op->above; tmp; tmp = tmp->above)
916 if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 923 if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR))
917 break; 924 break;
918 925
919 /* If nothing above us to move, nothing to do */ 926 /* If nothing above us to move, nothing to do */
920 if (!tmp || QUERY_FLAG (tmp, FLAG_WIZPASS)) 927 if (!tmp || QUERY_FLAG (tmp, FLAG_WIZPASS))
953 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) 960 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp)))
954 return; 961 return;
955 teleport (head, TELEPORTER, tmp); 962 teleport (head, TELEPORTER, tmp);
956 } 963 }
957} 964}
958
959 965
960/* This object will teleport someone to a different map 966/* This object will teleport someone to a different map
961 and will also apply changes to the player from its inventory. 967 and will also apply changes to the player from its inventory.
962 This was invented for giving classes, but there's no reason it 968 This was invented for giving classes, but there's no reason it
963 can't be generalized. 969 can't be generalized.
1016 return; /* dm has created a firewall in his inventory */ 1022 return; /* dm has created a firewall in his inventory */
1017 1023
1018 spell = op->inv; 1024 spell = op->inv;
1019 1025
1020 if (!spell || spell->type != SPELL) 1026 if (!spell || spell->type != SPELL)
1021 spell = &op->other_arch->clone; 1027 spell = op->other_arch;
1022 1028
1023 if (!spell) 1029 if (!spell)
1024 { 1030 {
1025 LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, &op->map->name, op->x, op->y); 1031 LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, &op->map->name, op->x, op->y);
1026 return; 1032 return;
1094 * is cleared, otherwise the player will get stuck in 1100 * is cleared, otherwise the player will get stuck in
1095 * place. This can happen if the player used a spell to 1101 * place. This can happen if the player used a spell to
1096 * get to this space. 1102 * get to this space.
1097 */ 1103 */
1098 victim->contr->fire_on = 0; 1104 victim->contr->fire_on = 0;
1099 victim->speed_left = 0.f; 1105 victim->speed_left = 1.f;
1100 move_player (victim, dir); 1106 move_player (victim, dir);
1101 } 1107 }
1102 else 1108 else
1103 return; 1109 return;
1104 } 1110 }
1137 if (op->above == NULL) 1143 if (op->above == NULL)
1138 return; 1144 return;
1139 1145
1140 for (tmp = op->above; tmp; tmp = tmp->above) 1146 for (tmp = op->above; tmp; tmp = tmp->above)
1141 { 1147 {
1142 if (op->other_arch->name == tmp->arch->name) 1148 if (op->other_arch->archname == tmp->arch->archname)
1143 { 1149 {
1144 if (op->level <= 0) 1150 if (op->level <= 0)
1145 tmp->destroy (); 1151 tmp->destroy ();
1146 else 1152 else
1147 { 1153 {
1169 * has to make sure that there is in fact space for the object. 1175 * has to make sure that there is in fact space for the object.
1170 * It should really do this for small objects also, but there is 1176 * It should really do this for small objects also, but there is
1171 * more concern with large objects, most notably a part being placed 1177 * more concern with large objects, most notably a part being placed
1172 * outside of the map which would cause the server to crash 1178 * outside of the map which would cause the server to crash
1173*/ 1179*/
1174
1175void 1180void
1176move_creator (object *creator) 1181move_creator (object *creator)
1177{ 1182{
1178 object *new_ob; 1183 object *new_ob;
1179 1184
1219 if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y)) 1224 if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y))
1220 { 1225 {
1221 new_ob->destroy (); 1226 new_ob->destroy ();
1222 return; 1227 return;
1223 } 1228 }
1229
1230 // for now lets try to identify everything generated here, it mostly
1231 // happens automated, so this will at least fix many identify-experience holes
1232 SET_FLAG (new_ob, FLAG_IDENTIFIED);
1224 1233
1225 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); 1234 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y);
1226 if (QUERY_FLAG (new_ob, FLAG_FREED)) 1235 if (QUERY_FLAG (new_ob, FLAG_FREED))
1227 return; 1236 return;
1228 1237
1243void 1252void
1244move_marker (object *op) 1253move_marker (object *op)
1245{ 1254{
1246 if (object *tmp = op->ms ().player ()) 1255 if (object *tmp = op->ms ().player ())
1247 { 1256 {
1248 object *tmp2;
1249
1250 /* remove an old force with a slaying field == op->name */ 1257 /* remove an old force with a slaying field == op->name */
1251 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) 1258 if (object *force = tmp->force_find (op->name))
1252 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->name) 1259 force->destroy ();
1260
1261 if (!tmp->force_find (op->slaying))
1253 { 1262 {
1254 tmp2->destroy (); 1263 tmp->force_add (op->slaying, op->stats.food);
1255 break;
1256 }
1257 1264
1258 /* cycle through his inventory to look for the MARK we want to
1259 * place
1260 */
1261 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1262 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying)
1263 break;
1264
1265 /* if we didn't find our own MARK */
1266 if (!tmp2)
1267 {
1268 object *force = get_archetype (FORCE_NAME);
1269
1270 if (op->stats.food)
1271 {
1272 force->set_speed (0.01);
1273 force->speed_left = -op->stats.food;
1274 }
1275 else
1276 force->set_speed (0);
1277
1278 /* put in the lock code */
1279 force->slaying = op->slaying;
1280
1281 if (op->lore)
1282 force->lore = op->lore;
1283
1284 insert_ob_in_ob (force, tmp);
1285 if (op->msg) 1265 if (op->msg)
1286 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); 1266 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg);
1287 1267
1288 if (op->stats.hp > 0) 1268 if (op->stats.hp > 0)
1289 { 1269 {
1290 op->stats.hp--; 1270 op->stats.hp--;
1271
1291 if (op->stats.hp == 0) 1272 if (op->stats.hp == 0)
1292 { 1273 {
1293 /* marker expires--granted mark number limit */ 1274 /* marker expires--granted mark number limit */
1294 op->destroy (); 1275 op->destroy ();
1295 return; 1276 return;
1300} 1281}
1301 1282
1302void 1283void
1303process_object (object *op) 1284process_object (object *op)
1304{ 1285{
1305 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) 1286 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)))
1306 return; 1287 return;
1307 1288
1308 if (INVOKE_OBJECT (TICK, op)) 1289 if (expect_false (INVOKE_OBJECT (TICK, op)))
1309 return; 1290 return;
1310 1291
1311 if (QUERY_FLAG (op, FLAG_MONSTER)) 1292 if (QUERY_FLAG (op, FLAG_MONSTER))
1312 if (move_monster (op) || QUERY_FLAG (op, FLAG_FREED)) 1293 if (move_monster (op) || QUERY_FLAG (op, FLAG_FREED))
1313 return; 1294 return;
1318 1299
1319 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1300 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))
1320 make_sure_seen (op); 1301 make_sure_seen (op);
1321 } 1302 }
1322 1303
1304 if (expect_false (
1323 if (op->flag [FLAG_GENERATOR] 1305 op->flag [FLAG_GENERATOR]
1324 || op->flag [FLAG_CHANGING] 1306 || op->flag [FLAG_CHANGING]
1325 || op->flag [FLAG_IS_USED_UP]) 1307 || op->flag [FLAG_IS_USED_UP]
1308 ))
1326 { 1309 {
1327 if (QUERY_FLAG (op, FLAG_CHANGING) && !op->state) 1310 if (QUERY_FLAG (op, FLAG_CHANGING) && !op->state)
1328 { 1311 {
1329 change_object (op); 1312 change_object (op);
1330 return; 1313 return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines