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.69 by root, Sat Sep 15 15:58:06 2007 UTC vs.
Revision 1.86 by elmex, Tue Jan 13 12:07:42 2009 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT 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 * Crossfire TRT 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
10 * the Free Software Foundation, either version 3 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,
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, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * 20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24/* 24/*
25 * 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
26 * collected in this file. 26 * collected in this file.
34 * so those will be removed shortly (in a cascade like fashion.) 34 * so those will be removed shortly (in a cascade like fashion.)
35 */ 35 */
36void 36void
37remove_door (object *op) 37remove_door (object *op)
38{ 38{
39 for (int i = 1; i < SIZEOFFREE1 + 1; i += 2)
40 {
41 object *tmp;
42 mapxy pos (op);
43 pos.move (i);
44 if (pos.normalise ()
45 && (tmp = present (DOOR, pos.m, pos.x, pos.y)))
46 {
47 tmp->set_speed (0.1f);
48 tmp->speed_left = -0.2f;
49 }
50 }
51
52 if (op->other_arch)
53 {
54 object *tmp = arch_to_object (op->other_arch);
55 tmp->x = op->x;
56 tmp->y = op->y;
57 tmp->map = op->map;
58 tmp->level = op->level;
59 insert_ob_in_map (tmp, op->map, op, 0);
60 }
61
62 op->drop_and_destroy ();
63}
64
65void
66remove_door2 (object *op)
67{
39 int i; 68 int i;
40 object *tmp; 69 object *tmp;
41 70
42 for (i = 1; i < 9; i += 2) 71 for (i = 1; i < 9; i += 2)
72 {
43 if ((tmp = present (DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i])) != NULL) 73 tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]);
44 { 74 if (tmp && tmp->slaying == op->slaying)
75 { /* same key both doors */
45 tmp->set_speed (0.1f); 76 tmp->set_speed (0.1f);
46 tmp->speed_left = -0.2f; 77 tmp->speed_left = -0.2f;
47 } 78 }
79 }
48 80
49 if (op->other_arch) 81 if (op->other_arch)
50 { 82 {
51 tmp = arch_to_object (op->other_arch); 83 tmp = arch_to_object (op->other_arch);
52 tmp->x = op->x; 84 tmp->x = op->x;
54 tmp->map = op->map; 86 tmp->map = op->map;
55 tmp->level = op->level; 87 tmp->level = op->level;
56 insert_ob_in_map (tmp, op->map, op, 0); 88 insert_ob_in_map (tmp, op->map, op, 0);
57 } 89 }
58 90
59 op->destroy (); 91 op->drop_and_destroy ();
60}
61
62void
63remove_door2 (object *op)
64{
65 int i;
66 object *tmp;
67
68 for (i = 1; i < 9; i += 2)
69 {
70 tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]);
71 if (tmp && tmp->slaying == op->slaying)
72 { /* same key both doors */
73 tmp->set_speed (0.1f);
74 tmp->speed_left = -0.2f;
75 }
76 }
77
78 if (op->other_arch)
79 {
80 tmp = arch_to_object (op->other_arch);
81 tmp->x = op->x;
82 tmp->y = op->y;
83 tmp->map = op->map;
84 tmp->level = op->level;
85 insert_ob_in_map (tmp, op->map, op, 0);
86 }
87
88 op->destroy ();
89} 92}
90 93
91void 94void
92generate_monster (object *gen) 95generate_monster (object *gen)
93{ 96{
94 if (!gen->map) 97 if (!gen->map)
95 return; 98 return;
96 99
97 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])
98 return; 106 return;
99 107
100 object *op; 108 object *op;
101 int dir; 109 int dir;
102 110
114 122
115 dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1); 123 dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1);
116 if (dir < 0) 124 if (dir < 0)
117 return; 125 return;
118 126
119 op = object_create_clone (op); 127 op = op->deep_clone ();
120 128
121 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); 129 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE);
122 unflag_inv (op, FLAG_IS_A_TEMPLATE); 130 unflag_inv (op, FLAG_IS_A_TEMPLATE);
123 } 131 }
124 else if (gen->other_arch) 132 else if (gen->other_arch)
434 if (op->stats.sp == 1) 442 if (op->stats.sp == 1)
435 { 443 {
436 if (detected && last == 0) 444 if (detected && last == 0)
437 { 445 {
438 op->value = 1; 446 op->value = 1;
439 push_button (op); 447 push_button (op, tmp);
440 } 448 }
441 449
442 if (!detected && last == 1) 450 if (!detected && last == 1)
443 { 451 {
444 op->value = 0; 452 op->value = 0;
445 push_button (op); 453 push_button (op, tmp);
446 } 454 }
447 } 455 }
448 else 456 else
449 { /* in this case, we unset buttons */ 457 { /* in this case, we unset buttons */
450 if (detected && last == 1) 458 if (detected && last == 1)
451 { 459 {
452 op->value = 0; 460 op->value = 0;
453 push_button (op); 461 push_button (op, tmp);
454 } 462 }
455 463
456 if (!detected && last == 0) 464 if (!detected && last == 0)
457 { 465 {
458 op->value = 1; 466 op->value = 1;
459 push_button (op); 467 push_button (op, tmp);
460 } 468 }
461 } 469 }
462} 470}
463 471
464void 472void
477} 485}
478 486
479void 487void
480move_hole (object *op) 488move_hole (object *op)
481{ /* 1 = opening, 0 = closing */ 489{ /* 1 = opening, 0 = closing */
482 object *next, *tmp;
483
484 if (op->value) 490 if (op->value)
485 { /* We're opening */ 491 { /* We're opening */
486 if (--op->stats.wc <= 0) 492 if (--op->stats.wc <= 0)
487 { /* Opened, let's stop */ 493 { /* Opened, let's stop */
488 op->stats.wc = 0; 494 op->stats.wc = 0;
489 op->set_speed (0); 495 op->set_speed (0);
490 496
491 /* Hard coding this makes sense for holes I suppose */ 497 /* Hard coding this makes sense for holes I suppose */
492 op->move_on = MOVE_WALK; 498 op->move_on = MOVE_WALK;
493 for (tmp = op->above; tmp != NULL; tmp = next) 499 for (object *next, *tmp = op->above; tmp; tmp = next)
494 { 500 {
495 next = tmp->above; 501 next = tmp->above;
496 move_apply (op, tmp, tmp); 502 move_apply (op, tmp, tmp);
497 } 503 }
498 } 504 }
540 { 546 {
541 object *payload = op->inv; 547 object *payload = op->inv;
542 548
543 if (payload == NULL) 549 if (payload == NULL)
544 return NULL; 550 return NULL;
551
545 payload->remove (); 552 payload->remove ();
546 op->destroy (); 553 op->destroy ();
547 return payload; 554 return payload;
548 } 555 }
549 556
629 if (INVOKE_OBJECT (STOP, op)) 636 if (INVOKE_OBJECT (STOP, op))
630 return; 637 return;
631 638
632 if (op->inv) 639 if (op->inv)
633 { 640 {
641 // replace this by straightforward drop to ground?
634 object *payload = op->inv; 642 object *payload = op->inv;
635 643
636 payload->remove ();
637 payload->owner = 0; 644 payload->owner = 0;
638 insert_ob_in_map (payload, op->map, payload, 0); 645 insert_ob_in_map (payload, op->map, payload, 0);
639 op->destroy (); 646 op->destroy ();
640 } 647 }
641 else 648 else
670 * is if the player throws a bomb - the bomb explodes on its own, 677 * is if the player throws a bomb - the bomb explodes on its own,
671 * but this object sticks around. We could handle the cleanup in the 678 * but this object sticks around. We could handle the cleanup in the
672 * 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,
673 * and it is easy enough to clean it up here. 680 * and it is easy enough to clean it up here.
674 */ 681 */
675 if (op->inv == NULL) 682 if (!op->inv)
676 { 683 {
677 op->destroy (); 684 op->destroy ();
678 return; 685 return;
679 } 686 }
680 687
850 op->remove (); 857 op->remove ();
851 for (i = 0; i < op->stats.food; i++) 858 for (i = 0; i < op->stats.food; i++)
852 { 859 {
853 object *tmp = arch_to_object (op->other_arch); 860 object *tmp = arch_to_object (op->other_arch);
854 861
855 if (op->type == LAMP)
856 tmp->stats.food = op->stats.food - 1;
857
858 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ 862 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */
863
859 if (env) 864 if (env)
860 {
861 tmp = env->insert (tmp); 865 env->insert (tmp);
862
863 /* If this object is the players inventory, we need to tell the
864 * client of the change. Insert_ob_in_map takes care of the
865 * updating the client, so we don't need to do that below.
866 */
867 if (object *pl = op->in_player ())
868 {
869 esrv_del_item (pl->contr, op->count);
870 esrv_send_item (pl, tmp);
871 }
872 }
873 else 866 else
874 { 867 {
875 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);
876 if (j < 0) /* No free spot */ 869 if (j < 0) /* No free spot */
877 tmp->destroy (); 870 tmp->destroy ();
944 else 937 else
945 { 938 {
946 /* Random teleporter */ 939 /* Random teleporter */
947 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) 940 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp)))
948 return; 941 return;
942
949 teleport (head, TELEPORTER, tmp); 943 teleport (head, TELEPORTER, tmp);
950 } 944 }
951} 945}
952 946
953/* This object will teleport someone to a different map 947/* This object will teleport someone to a different map
1173 { 1167 {
1174 creator->stats.hp = -1; 1168 creator->stats.hp = -1;
1175 return; 1169 return;
1176 } 1170 }
1177 1171
1178 if (creator->inv != NULL) 1172 if (creator->inv)
1179 { 1173 {
1180 object *ob; 1174 object *ob;
1181 int i; 1175 int i;
1182 object *ob_to_copy; 1176 object *ob_to_copy;
1183 1177
1188 if (rndm (0, i) == 0) 1182 if (rndm (0, i) == 0)
1189 { 1183 {
1190 ob_to_copy = ob; 1184 ob_to_copy = ob;
1191 } 1185 }
1192 } 1186 }
1193 new_ob = object_create_clone (ob_to_copy); 1187 new_ob = ob_to_copy->deep_clone ();
1194 CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE); 1188 CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE);
1195 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE); 1189 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE);
1196 } 1190 }
1197 else 1191 else
1198 { 1192 {
1199 if (creator->other_arch == NULL) 1193 if (!creator->other_arch)
1200 { 1194 {
1201 LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", 1195 LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n",
1202 &creator->name, &creator->map->path, creator->x, creator->y); 1196 &creator->name, &creator->map->path, creator->x, creator->y);
1203 return; 1197 return;
1204 } 1198 }
1221 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); 1215 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y);
1222 if (QUERY_FLAG (new_ob, FLAG_FREED)) 1216 if (QUERY_FLAG (new_ob, FLAG_FREED))
1223 return; 1217 return;
1224 1218
1225 if (creator->slaying) 1219 if (creator->slaying)
1226 {
1227 new_ob->name = new_ob->title = creator->slaying; 1220 new_ob->name = new_ob->title = creator->slaying;
1228 }
1229} 1221}
1230 1222
1231/* move_marker --peterm@soda.csua.berkeley.edu 1223/* move_marker --peterm@soda.csua.berkeley.edu
1232 when moved, a marker will search for a player sitting above 1224 when moved, a marker will search for a player sitting above
1233 it, and insert an invisible, weightless force into him 1225 it, and insert an invisible, weightless force into him
1265 } 1257 }
1266 } 1258 }
1267 } 1259 }
1268} 1260}
1269 1261
1262// mapscript objects activate themselves (only) then their timer fires
1263// TODO: maybe they should simply trigger the link like any other object?
1264void
1265move_mapscript (object *op)
1266{
1267 op->set_speed (0);
1268 cfperl_mapscript_activate (op, true, op, 0);
1269}
1270
1271void 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);
1304}
1305
1270void 1306void
1271process_object (object *op) 1307process_object (object *op)
1272{ 1308{
1273 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))) 1309 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)))
1274 return; 1310 return;
1307 { 1343 {
1308 if (QUERY_FLAG (op, FLAG_APPLIED)) 1344 if (QUERY_FLAG (op, FLAG_APPLIED))
1309 remove_force (op); 1345 remove_force (op);
1310 else 1346 else
1311 { 1347 {
1312 /* If necessary, delete the item from the players inventory */ 1348 op->remove (); // TODO: really necessary?
1313 if (object *pl = op->in_player ())
1314 esrv_del_item (pl->contr, op->count);
1315
1316 op->remove ();
1317 1349
1318 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1350 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))
1319 make_sure_not_seen (op); 1351 make_sure_not_seen (op);
1320 1352
1321 op->destroy (); 1353 op->drop_and_destroy ();
1322 } 1354 }
1323 1355
1324 return; 1356 return;
1325 } 1357 }
1326 } 1358 }
1450 1482
1451 case PLAYER: 1483 case PLAYER:
1452 // players have their own speed-management, so undo the --speed_left 1484 // players have their own speed-management, so undo the --speed_left
1453 ++op->speed_left; 1485 ++op->speed_left;
1454 break; 1486 break;
1455 }
1456}
1457 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines