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.77 by root, Tue Aug 26 02:35:05 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
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
541 { 547 {
542 object *payload = op->inv; 548 object *payload = op->inv;
543 549
544 if (payload == NULL) 550 if (payload == NULL)
545 return NULL; 551 return NULL;
552
546 payload->remove (); 553 payload->remove ();
547 op->destroy (); 554 op->destroy ();
548 return payload; 555 return payload;
549 } 556 }
550 557
593 600
594 // restore original wc, dam, attacktype and slaying 601 // restore original wc, dam, attacktype and slaying
595 op->stats.wc = op->stats.sp; 602 op->stats.wc = op->stats.sp;
596 op->stats.dam = op->stats.hp; 603 op->stats.dam = op->stats.hp;
597 op->attacktype = op->stats.grace; 604 op->attacktype = op->stats.grace;
605 op->slaying = op->custom_name;
598 606
599 if (op->spellarg)
600 {
601 op->slaying = op->spellarg;
602 free (op->spellarg);
603 op->spellarg = 0;
604 }
605 else
606 op->slaying = 0;
607
608 /* 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 */
609 op->spellarg = NULL; 608 op->custom_name = 0;
610 op->stats.sp = 0; 609 op->stats.sp = 0;
611 op->stats.hp = 0; 610 op->stats.hp = 0;
612 op->stats.grace = 0; 611 op->stats.grace = 0;
613 op->level = 0; 612 op->level = 0;
614 op->face = op->arch->face; 613 op->face = op->arch->face;
615 op->owner = NULL; /* So that stopped arrows will be saved */ 614 op->owner = 0;
615
616 update_object (op, UP_OBJ_CHANGE); 616 update_object (op, UP_OBJ_CHANGE);
617
617 return op; 618 return op;
618} 619}
619 620
620/* stop_arrow() - what to do when a non-living flying object 621/* stop_arrow() - what to do when a non-living flying object
621 * 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
630 if (INVOKE_OBJECT (STOP, op)) 631 if (INVOKE_OBJECT (STOP, op))
631 return; 632 return;
632 633
633 if (op->inv) 634 if (op->inv)
634 { 635 {
636 // replace this by straightforward drop to ground?
635 object *payload = op->inv; 637 object *payload = op->inv;
636 638
637 payload->remove ();
638 payload->owner = 0; 639 payload->owner = 0;
639 insert_ob_in_map (payload, op->map, payload, 0); 640 insert_ob_in_map (payload, op->map, payload, 0);
640 op->destroy (); 641 op->destroy ();
641 } 642 }
642 else 643 else
671 * 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,
672 * 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
673 * 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,
674 * and it is easy enough to clean it up here. 675 * and it is easy enough to clean it up here.
675 */ 676 */
676 if (op->inv == NULL) 677 if (!op->inv)
677 { 678 {
678 op->destroy (); 679 op->destroy ();
679 return; 680 return;
680 } 681 }
681 682
810 return; 811 return;
811 } 812 }
812 813
813 /* update object image for new facing */ 814 /* update object image for new facing */
814 /* many thrown objects *don't* have more than one face */ 815 /* many thrown objects *don't* have more than one face */
815 if (GET_ANIM_ID (op)) 816 if (op->has_anim ())
816 SET_ANIMATION (op, op->direction); 817 op->set_anim_frame (op->direction);
817 } /* object is reflected */ 818 } /* object is reflected */
818 } /* object ran into a wall */ 819 } /* object ran into a wall */
819 820
820 /* 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
821 * about 17 squares. Tune as needed. 822 * about 17 squares. Tune as needed.
850 851
851 op->remove (); 852 op->remove ();
852 for (i = 0; i < op->stats.food; i++) 853 for (i = 0; i < op->stats.food; i++)
853 { 854 {
854 object *tmp = arch_to_object (op->other_arch); 855 object *tmp = arch_to_object (op->other_arch);
855
856 if (op->type == LAMP)
857 tmp->stats.food = op->stats.food - 1;
858 856
859 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ 857 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */
860 858
861 if (env) 859 if (env)
862 env->insert (tmp); 860 env->insert (tmp);
1164 { 1162 {
1165 creator->stats.hp = -1; 1163 creator->stats.hp = -1;
1166 return; 1164 return;
1167 } 1165 }
1168 1166
1169 if (creator->inv != NULL) 1167 if (creator->inv)
1170 { 1168 {
1171 object *ob; 1169 object *ob;
1172 int i; 1170 int i;
1173 object *ob_to_copy; 1171 object *ob_to_copy;
1174 1172
1185 CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE); 1183 CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE);
1186 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE); 1184 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE);
1187 } 1185 }
1188 else 1186 else
1189 { 1187 {
1190 if (creator->other_arch == NULL) 1188 if (!creator->other_arch)
1191 { 1189 {
1192 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",
1193 &creator->name, &creator->map->path, creator->x, creator->y); 1191 &creator->name, &creator->map->path, creator->x, creator->y);
1194 return; 1192 return;
1195 } 1193 }
1212 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);
1213 if (QUERY_FLAG (new_ob, FLAG_FREED)) 1211 if (QUERY_FLAG (new_ob, FLAG_FREED))
1214 return; 1212 return;
1215 1213
1216 if (creator->slaying) 1214 if (creator->slaying)
1217 {
1218 new_ob->name = new_ob->title = creator->slaying; 1215 new_ob->name = new_ob->title = creator->slaying;
1219 }
1220} 1216}
1221 1217
1222/* move_marker --peterm@soda.csua.berkeley.edu 1218/* move_marker --peterm@soda.csua.berkeley.edu
1223 when moved, a marker will search for a player sitting above 1219 when moved, a marker will search for a player sitting above
1224 it, and insert an invisible, weightless force into him 1220 it, and insert an invisible, weightless force into him
1234 { 1230 {
1235 /* remove an old force with a slaying field == op->name */ 1231 /* remove an old force with a slaying field == op->name */
1236 if (object *force = tmp->force_find (op->name)) 1232 if (object *force = tmp->force_find (op->name))
1237 force->destroy (); 1233 force->destroy ();
1238 1234
1239 if (!tmp->force_find (op->slaying)) 1235 if (op->slaying && !tmp->force_find (op->slaying))
1240 { 1236 {
1241 tmp->force_add (op->slaying, op->stats.food); 1237 tmp->force_add (op->slaying, op->stats.food);
1242 1238
1243 if (op->msg) 1239 if (op->msg)
1244 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); 1240 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg);
1256 } 1252 }
1257 } 1253 }
1258 } 1254 }
1259} 1255}
1260 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
1261void 1302void
1262process_object (object *op) 1303process_object (object *op)
1263{ 1304{
1264 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))) 1305 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)))
1265 return; 1306 return;
1298 { 1339 {
1299 if (QUERY_FLAG (op, FLAG_APPLIED)) 1340 if (QUERY_FLAG (op, FLAG_APPLIED))
1300 remove_force (op); 1341 remove_force (op);
1301 else 1342 else
1302 { 1343 {
1303 op->remove (); 1344 op->remove (); // TODO: really necessary?
1304 1345
1305 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1346 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))
1306 make_sure_not_seen (op); 1347 make_sure_not_seen (op);
1307 1348
1308 op->destroy (); 1349 op->drop_and_destroy ();
1309 } 1350 }
1310 1351
1311 return; 1352 return;
1312 } 1353 }
1313 } 1354 }
1437 1478
1438 case PLAYER: 1479 case PLAYER:
1439 // players have their own speed-management, so undo the --speed_left 1480 // players have their own speed-management, so undo the --speed_left
1440 ++op->speed_left; 1481 ++op->speed_left;
1441 break; 1482 break;
1442 }
1443}
1444 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