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.72 by root, Thu Nov 8 19:43:29 2007 UTC vs.
Revision 1.94 by root, Mon Oct 12 14:00:59 2009 UTC

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 it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * 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 Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24/* 25/*
57 tmp->map = op->map; 58 tmp->map = op->map;
58 tmp->level = op->level; 59 tmp->level = op->level;
59 insert_ob_in_map (tmp, op->map, op, 0); 60 insert_ob_in_map (tmp, op->map, op, 0);
60 } 61 }
61 62
62 op->destroy (); 63 op->drop_and_destroy ();
63} 64}
64 65
65void 66void
66remove_door2 (object *op) 67remove_door2 (object *op)
67{ 68{
86 tmp->map = op->map; 87 tmp->map = op->map;
87 tmp->level = op->level; 88 tmp->level = op->level;
88 insert_ob_in_map (tmp, op->map, op, 0); 89 insert_ob_in_map (tmp, op->map, op, 0);
89 } 90 }
90 91
91 op->destroy (); 92 op->drop_and_destroy ();
92} 93}
93 94
94void 95void
95generate_monster (object *gen) 96generate_monster (object *gen)
96{ 97{
97 if (!gen->map) 98 if (!gen->map)
98 return; 99 return;
99 100
100 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) 101 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1))
102 return;
103
104 // sleeping generators won't generate, this will make monsters like
105 // centipedes not generate more centipedes when being asleep.
106 if (gen->flag [FLAG_SLEEP])
101 return; 107 return;
102 108
103 object *op; 109 object *op;
104 int dir; 110 int dir;
105 111
117 123
118 dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1); 124 dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1);
119 if (dir < 0) 125 if (dir < 0)
120 return; 126 return;
121 127
122 op = object_create_clone (op); 128 op = op->deep_clone ();
123 129
124 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); 130 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE);
125 unflag_inv (op, FLAG_IS_A_TEMPLATE); 131 unflag_inv (op, FLAG_IS_A_TEMPLATE);
126 } 132 }
127 else if (gen->other_arch) 133 else if (gen->other_arch)
437 if (op->stats.sp == 1) 443 if (op->stats.sp == 1)
438 { 444 {
439 if (detected && last == 0) 445 if (detected && last == 0)
440 { 446 {
441 op->value = 1; 447 op->value = 1;
442 push_button (op); 448 push_button (op, tmp);
443 } 449 }
444 450
445 if (!detected && last == 1) 451 if (!detected && last == 1)
446 { 452 {
447 op->value = 0; 453 op->value = 0;
448 push_button (op); 454 push_button (op, tmp);
449 } 455 }
450 } 456 }
451 else 457 else
452 { /* in this case, we unset buttons */ 458 { /* in this case, we unset buttons */
453 if (detected && last == 1) 459 if (detected && last == 1)
454 { 460 {
455 op->value = 0; 461 op->value = 0;
456 push_button (op); 462 push_button (op, tmp);
457 } 463 }
458 464
459 if (!detected && last == 0) 465 if (!detected && last == 0)
460 { 466 {
461 op->value = 1; 467 op->value = 1;
462 push_button (op); 468 push_button (op, tmp);
463 } 469 }
464 } 470 }
465} 471}
466 472
467void 473void
480} 486}
481 487
482void 488void
483move_hole (object *op) 489move_hole (object *op)
484{ /* 1 = opening, 0 = closing */ 490{ /* 1 = opening, 0 = closing */
485 object *next, *tmp;
486
487 if (op->value) 491 if (op->value)
488 { /* We're opening */ 492 { /* We're opening */
489 if (--op->stats.wc <= 0) 493 if (--op->stats.wc <= 0)
490 { /* Opened, let's stop */ 494 { /* Opened, let's stop */
491 op->stats.wc = 0; 495 op->stats.wc = 0;
492 op->set_speed (0); 496 op->set_speed (0);
493 497
494 /* Hard coding this makes sense for holes I suppose */ 498 /* Hard coding this makes sense for holes I suppose */
495 op->move_on = MOVE_WALK; 499 op->move_on = MOVE_WALK;
496 for (tmp = op->above; tmp != NULL; tmp = next) 500 for (object *next, *tmp = op->above; tmp; tmp = next)
497 { 501 {
498 next = tmp->above; 502 next = tmp->above;
499 move_apply (op, tmp, tmp); 503 move_apply (op, tmp, tmp);
500 } 504 }
501 } 505 }
543 { 547 {
544 object *payload = op->inv; 548 object *payload = op->inv;
545 549
546 if (payload == NULL) 550 if (payload == NULL)
547 return NULL; 551 return NULL;
552
548 payload->remove (); 553 payload->remove ();
549 op->destroy (); 554 op->destroy ();
550 return payload; 555 return payload;
551 } 556 }
552 557
595 600
596 // restore original wc, dam, attacktype and slaying 601 // restore original wc, dam, attacktype and slaying
597 op->stats.wc = op->stats.sp; 602 op->stats.wc = op->stats.sp;
598 op->stats.dam = op->stats.hp; 603 op->stats.dam = op->stats.hp;
599 op->attacktype = op->stats.grace; 604 op->attacktype = op->stats.grace;
605 op->slaying = op->custom_name;
600 606
601 if (op->spellarg)
602 {
603 op->slaying = op->spellarg;
604 free (op->spellarg);
605 op->spellarg = 0;
606 }
607 else
608 op->slaying = 0;
609
610 /* Reset these to zero, so that object::can_merge will work properly */ 607 /* Reset these to defaults, so that object::can_merge will work properly */
611 op->spellarg = NULL; 608 op->custom_name = 0;
612 op->stats.sp = 0; 609 op->stats.sp = 0;
613 op->stats.hp = 0; 610 op->stats.hp = 0;
614 op->stats.grace = 0; 611 op->stats.grace = 0;
615 op->level = 0; 612 op->level = 0;
616 op->face = op->arch->face; 613 op->face = op->arch->face;
617 op->owner = NULL; /* So that stopped arrows will be saved */ 614 op->owner = 0;
615
618 update_object (op, UP_OBJ_CHANGE); 616 update_object (op, UP_OBJ_CHANGE);
617
619 return op; 618 return op;
620} 619}
621 620
622/* stop_arrow() - what to do when a non-living flying object 621/* stop_arrow() - what to do when a non-living flying object
623 * has to stop. Sept 96 - I added in thrown object code in 622 * has to stop. Sept 96 - I added in thrown object code in
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 ();
643 } 642 }
644 else 643 else
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 ();
681 return; 680 return;
682 } 681 }
683 682
812 return; 811 return;
813 } 812 }
814 813
815 /* update object image for new facing */ 814 /* update object image for new facing */
816 /* many thrown objects *don't* have more than one face */ 815 /* many thrown objects *don't* have more than one face */
817 if (GET_ANIM_ID (op)) 816 if (op->has_anim ())
818 SET_ANIMATION (op, op->direction); 817 op->set_anim_frame (op->direction);
819 } /* object is reflected */ 818 } /* object is reflected */
820 } /* object ran into a wall */ 819 } /* object ran into a wall */
821 820
822 /* decrease the speed as it flies. 0.05 means a standard bow will shoot 821 /* decrease the speed as it flies. 0.05 means a standard bow will shoot
823 * about 17 squares. Tune as needed. 822 * about 17 squares. Tune as needed.
853 op->remove (); 852 op->remove ();
854 for (i = 0; i < op->stats.food; i++) 853 for (i = 0; i < op->stats.food; i++)
855 { 854 {
856 object *tmp = arch_to_object (op->other_arch); 855 object *tmp = arch_to_object (op->other_arch);
857 856
858 if (op->type == LAMP)
859 tmp->stats.food = op->stats.food - 1;
860
861 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ 857 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */
858
862 if (env) 859 if (env)
863 {
864 tmp = env->insert (tmp); 860 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 861 else
877 { 862 {
878 j = find_first_free_spot (tmp, op->map, op->x, op->y); 863 j = find_first_free_spot (tmp, op->map, op->x, op->y);
879 if (j < 0) /* No free spot */ 864 if (j < 0) /* No free spot */
880 tmp->destroy (); 865 tmp->destroy ();
947 else 932 else
948 { 933 {
949 /* Random teleporter */ 934 /* Random teleporter */
950 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) 935 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp)))
951 return; 936 return;
937
952 teleport (head, TELEPORTER, tmp); 938 teleport (head, TELEPORTER, tmp);
953 } 939 }
954} 940}
955 941
956/* This object will teleport someone to a different map 942/* This object will teleport someone to a different map
1176 { 1162 {
1177 creator->stats.hp = -1; 1163 creator->stats.hp = -1;
1178 return; 1164 return;
1179 } 1165 }
1180 1166
1181 if (creator->inv != NULL) 1167 if (creator->inv)
1182 { 1168 {
1183 object *ob; 1169 object *ob;
1184 int i; 1170 int i;
1185 object *ob_to_copy; 1171 object *ob_to_copy;
1186 1172
1191 if (rndm (0, i) == 0) 1177 if (rndm (0, i) == 0)
1192 { 1178 {
1193 ob_to_copy = ob; 1179 ob_to_copy = ob;
1194 } 1180 }
1195 } 1181 }
1196 new_ob = object_create_clone (ob_to_copy); 1182 new_ob = ob_to_copy->deep_clone ();
1197 CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE); 1183 CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE);
1198 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE); 1184 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE);
1199 } 1185 }
1200 else 1186 else
1201 { 1187 {
1202 if (creator->other_arch == NULL) 1188 if (!creator->other_arch)
1203 { 1189 {
1204 LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", 1190 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); 1191 &creator->name, &creator->map->path, creator->x, creator->y);
1206 return; 1192 return;
1207 } 1193 }
1224 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); 1210 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y);
1225 if (QUERY_FLAG (new_ob, FLAG_FREED)) 1211 if (QUERY_FLAG (new_ob, FLAG_FREED))
1226 return; 1212 return;
1227 1213
1228 if (creator->slaying) 1214 if (creator->slaying)
1229 {
1230 new_ob->name = new_ob->title = creator->slaying; 1215 new_ob->name = new_ob->title = creator->slaying;
1231 }
1232} 1216}
1233 1217
1234/* move_marker --peterm@soda.csua.berkeley.edu 1218/* move_marker --peterm@soda.csua.berkeley.edu
1235 when moved, a marker will search for a player sitting above 1219 when moved, a marker will search for a player sitting above
1236 it, and insert an invisible, weightless force into him 1220 it, and insert an invisible, weightless force into him
1268 } 1252 }
1269 } 1253 }
1270 } 1254 }
1271} 1255}
1272 1256
1257// mapscript objects activate themselves (only) then their timer fires
1258// TODO: maybe they should simply trigger the link like any other object?
1259void
1260move_mapscript (object *op)
1261{
1262 op->set_speed (0);
1263 cfperl_mapscript_activate (op, true, op, 0);
1264}
1265
1266void move_lamp (object *op)
1267{
1268 // if the lamp/torch is off, we should disable it.
1269 if (!op->glow_radius)
1270 {
1271 op->set_speed (0);
1272 return;
1273 }
1274 else
1275 {
1276 // check whether the face might need to be updated
1277 // (currently this is needed to have already switched on torches
1278 // on maps, as they just set the glow_radius in the archetype)
1279 if (op->other_arch
1280 && (
1281 (op->flag [FLAG_ANIMATE] != op->other_arch->flag [FLAG_ANIMATE])
1282 || (op->flag [FLAG_ANIMATE]
1283 ? (op->animation_id != op->other_arch->animation_id)
1284 : (op->face != op->other_arch->face))
1285 ))
1286 get_animation_from_arch (op, op->other_arch);
1287 }
1288
1289 // lamps and torches on maps don't use up their fuel
1290 if (op->is_on_map ())
1291 return;
1292
1293 if (op->stats.food > 0)
1294 {
1295 op->stats.food--;
1296 return;
1297 }
1298
1299 apply_lamp (op, false);
1300}
1301
1273void 1302void
1274process_object (object *op) 1303process_object (object *op)
1275{ 1304{
1276 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))) 1305 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)))
1277 return; 1306 return;
1310 { 1339 {
1311 if (QUERY_FLAG (op, FLAG_APPLIED)) 1340 if (QUERY_FLAG (op, FLAG_APPLIED))
1312 remove_force (op); 1341 remove_force (op);
1313 else 1342 else
1314 { 1343 {
1315 /* If necessary, delete the item from the players inventory */ 1344 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 1345
1321 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1346 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))
1322 make_sure_not_seen (op); 1347 make_sure_not_seen (op);
1323 1348
1324 op->destroy (); 1349 op->drop_and_destroy ();
1325 } 1350 }
1326 1351
1327 return; 1352 return;
1328 } 1353 }
1329 } 1354 }
1453 1478
1454 case PLAYER: 1479 case PLAYER:
1455 // players have their own speed-management, so undo the --speed_left 1480 // players have their own speed-management, so undo the --speed_left
1456 ++op->speed_left; 1481 ++op->speed_left;
1457 break; 1482 break;
1458 }
1459}
1460 1483
1484 case MAPSCRIPT:
1485 move_mapscript (op);
1486 break;
1487
1488 case LAMP:
1489 case TORCH:
1490 move_lamp (op);
1491 break;
1492 }
1493}
1494

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines