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.74 by root, Tue Apr 22 07:01:47 2008 UTC vs.
Revision 1.95 by root, Mon Oct 26 11:31:39 2009 UTC

3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 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.
852 851
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
858 if (op->type == LAMP)
859 tmp->stats.food = op->stats.food - 1;
860 856
861 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ 857 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */
862 858
863 if (env) 859 if (env)
864 env->insert (tmp); 860 env->insert (tmp);
936 else 932 else
937 { 933 {
938 /* Random teleporter */ 934 /* Random teleporter */
939 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) 935 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp)))
940 return; 936 return;
937
941 teleport (head, TELEPORTER, tmp); 938 teleport (head, TELEPORTER, tmp);
942 } 939 }
943} 940}
944 941
945/* This object will teleport someone to a different map 942/* This object will teleport someone to a different map
1165 { 1162 {
1166 creator->stats.hp = -1; 1163 creator->stats.hp = -1;
1167 return; 1164 return;
1168 } 1165 }
1169 1166
1170 if (creator->inv != NULL) 1167 if (creator->inv)
1171 { 1168 {
1172 object *ob; 1169 object *ob;
1173 int i; 1170 int i;
1174 object *ob_to_copy; 1171 object *ob_to_copy;
1175 1172
1180 if (rndm (0, i) == 0) 1177 if (rndm (0, i) == 0)
1181 { 1178 {
1182 ob_to_copy = ob; 1179 ob_to_copy = ob;
1183 } 1180 }
1184 } 1181 }
1185 new_ob = object_create_clone (ob_to_copy); 1182 new_ob = ob_to_copy->deep_clone ();
1186 CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE); 1183 CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE);
1187 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE); 1184 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE);
1188 } 1185 }
1189 else 1186 else
1190 { 1187 {
1191 if (creator->other_arch == NULL) 1188 if (!creator->other_arch)
1192 { 1189 {
1193 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",
1194 &creator->name, &creator->map->path, creator->x, creator->y); 1191 &creator->name, &creator->map->path, creator->x, creator->y);
1195 return; 1192 return;
1196 } 1193 }
1213 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);
1214 if (QUERY_FLAG (new_ob, FLAG_FREED)) 1211 if (QUERY_FLAG (new_ob, FLAG_FREED))
1215 return; 1212 return;
1216 1213
1217 if (creator->slaying) 1214 if (creator->slaying)
1218 {
1219 new_ob->name = new_ob->title = creator->slaying; 1215 new_ob->name = new_ob->title = creator->slaying;
1220 }
1221} 1216}
1222 1217
1223/* move_marker --peterm@soda.csua.berkeley.edu 1218/* move_marker --peterm@soda.csua.berkeley.edu
1224 when moved, a marker will search for a player sitting above 1219 when moved, a marker will search for a player sitting above
1225 it, and insert an invisible, weightless force into him 1220 it, and insert an invisible, weightless force into him
1235 { 1230 {
1236 /* remove an old force with a slaying field == op->name */ 1231 /* remove an old force with a slaying field == op->name */
1237 if (object *force = tmp->force_find (op->name)) 1232 if (object *force = tmp->force_find (op->name))
1238 force->destroy (); 1233 force->destroy ();
1239 1234
1240 if (!tmp->force_find (op->slaying)) 1235 if (op->slaying && !tmp->force_find (op->slaying))
1241 { 1236 {
1242 tmp->force_add (op->slaying, op->stats.food); 1237 tmp->force_add (op->slaying, op->stats.food);
1243 1238
1244 if (op->msg) 1239 if (op->msg)
1245 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); 1240 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg);
1257 } 1252 }
1258 } 1253 }
1259 } 1254 }
1260} 1255}
1261 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
1262void 1302void
1263process_object (object *op) 1303process_object (object *op)
1264{ 1304{
1265 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))) 1305 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)))
1266 return; 1306 return;
1299 { 1339 {
1300 if (QUERY_FLAG (op, FLAG_APPLIED)) 1340 if (QUERY_FLAG (op, FLAG_APPLIED))
1301 remove_force (op); 1341 remove_force (op);
1302 else 1342 else
1303 { 1343 {
1304 op->remove (); 1344 op->remove (); // TODO: really necessary?
1305 1345
1306 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1346 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))
1307 make_sure_not_seen (op); 1347 make_sure_not_seen (op);
1308 1348
1309 op->destroy (); 1349 op->drop_and_destroy ();
1310 } 1350 }
1311 1351
1312 return; 1352 return;
1313 } 1353 }
1314 } 1354 }
1438 1478
1439 case PLAYER: 1479 case PLAYER:
1440 // players have their own speed-management, so undo the --speed_left 1480 // players have their own speed-management, so undo the --speed_left
1441 ++op->speed_left; 1481 ++op->speed_left;
1442 break; 1482 break;
1443 }
1444}
1445 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