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.107 by root, Sun Apr 11 18:50:04 2010 UTC vs.
Revision 1.126 by root, Sat Nov 17 23:40:05 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 10 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25/* 26/*
26 * Routines that is executed from objects based on their speed have been 27 * Routines that is executed from objects based on their speed have been
28 */ 29 */
29#include <global.h> 30#include <global.h>
30#include <spells.h> 31#include <spells.h>
31#include <sproto.h> 32#include <sproto.h>
32 33
33/* The following removes doors. The functions check to see if similar 34/* The following removes doors. The functions check to see if similar
34 * doors are next to the one that is being removed, and if so, set it 35 * doors are next to the one that is being removed, and if so, set it
35 * so those will be removed shortly (in a cascade like fashion.) 36 * so those will be removed shortly (in a cascade like fashion.)
36 */ 37 */
37void 38void
38remove_door (object *op) 39remove_door (object *op)
69 int i; 70 int i;
70 object *tmp; 71 object *tmp;
71 72
72 for (i = 1; i < 9; i += 2) 73 for (i = 1; i < 9; i += 2)
73 { 74 {
74 tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]); 75 tmp = present (LOCKED_DOOR, op->map, op->x + DIRX (i), op->y + DIRY (i));
75 if (tmp && tmp->slaying == op->slaying) 76 if (tmp && tmp->slaying == op->slaying)
76 { /* same key both doors */ 77 { /* same key both doors */
77 tmp->set_speed (0.1f); 78 tmp->set_speed (0.1f);
78 tmp->speed_left = -0.2f; 79 tmp->speed_left = -0.2f;
79 } 80 }
239{ /* 1 = going down, 0 = going up */ 240{ /* 1 = going down, 0 = going up */
240 object *tmp; 241 object *tmp;
241 242
242 if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op)) 243 if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op))
243 { 244 {
244 LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op)); 245 LOG (llevError, "%s: gate error: animation was %d, max=%d\n", op->debug_desc (), op->stats.wc, NUM_ANIMATIONS (op));
245 op->stats.wc = 0; 246 op->stats.wc = 0;
246 } 247 }
247 248
248 /* We're going down */ 249 /* We're going down */
249 if (op->value) 250 if (op->value)
272 /* We're going up */ 273 /* We're going up */
273 274
274 /* First, lets see if we are already at the top */ 275 /* First, lets see if we are already at the top */
275 if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1)) 276 if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1))
276 { 277 {
277
278 /* Check to make sure that only non pickable and non rollable 278 /* Check to make sure that only non pickable and non rollable
279 * objects are above the gate. If so, we finish closing the gate, 279 * objects are above the gate. If so, we finish closing the gate,
280 * otherwise, we fall through to the code below which should lower 280 * otherwise, we fall through to the code below which should lower
281 * the gate slightly. 281 * the gate slightly.
282 */ 282 */
502 move_apply (op, tmp, tmp); 502 move_apply (op, tmp, tmp);
503 } 503 }
504 } 504 }
505 505
506 SET_ANIMATION (op, op->stats.wc); 506 SET_ANIMATION (op, op->stats.wc);
507 update_object (op, UP_OBJ_FACE); 507 update_object (op, UP_OBJ_CHANGE);
508 return; 508 return;
509 } 509 }
510 510
511 /* We're closing */ 511 /* We're closing */
512 op->move_on = 0; 512 op->move_on = 0;
513 513
514 op->stats.wc++; 514 op->stats.wc++;
515 if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) 515 if (op->stats.wc >= NUM_ANIMATIONS (op))
516 op->stats.wc = NUM_ANIMATIONS (op) - 1; 516 op->stats.wc = NUM_ANIMATIONS (op) - 1;
517 517
518 SET_ANIMATION (op, op->stats.wc); 518 SET_ANIMATION (op, op->stats.wc);
519 update_object (op, UP_OBJ_FACE); 519 update_object (op, UP_OBJ_CHANGE);
520 if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1)) 520 if (op->stats.wc == (NUM_ANIMATIONS (op) - 1))
521 op->set_speed (0); /* closed, let's stop */ 521 op->set_speed (0); /* closed, let's stop */
522} 522}
523 523
524 524
525/* stop_item() returns a pointer to the stopped object. The stopped object 525/* stop_item() returns a pointer to the stopped object. The stopped object
610 op->stats.grace = 0; 610 op->stats.grace = 0;
611 op->level = 0; 611 op->level = 0;
612 op->face = op->arch->face; 612 op->face = op->arch->face;
613 op->owner = 0; 613 op->owner = 0;
614 614
615 op->clr_flag (FLAG_NO_PICK); /* fire_bow makes arrows NO_PICK so monsters (or anything else) don't pick them mid-flight */
616
615 update_object (op, UP_OBJ_CHANGE); 617 update_object (op, UP_OBJ_CHANGE);
616 618
617 return op; 619 return op;
618} 620}
619 621
655{ 657{
656 int was_reflected; 658 int was_reflected;
657 659
658 if (!op->map) 660 if (!op->map)
659 { 661 {
660 LOG (llevError, "BUG: Arrow had no map.\n"); 662 LOG (llevError | logBacktrace, "BUG: Arrow %s had no map.\n", op->debug_desc ());
661 op->destroy (); 663 op->destroy ();
662 return; 664 return;
663 } 665 }
664 666
665 /* we need to stop thrown objects at some point. Like here. */ 667 /* we need to stop thrown objects at some point. Like here. */
687 } 689 }
688 690
689 /* decrease the speed as it flies. 0.05 means a standard bow will shoot 691 /* decrease the speed as it flies. 0.05 means a standard bow will shoot
690 * about 17 squares. Tune as needed. 692 * about 17 squares. Tune as needed.
691 */ 693 */
692 op->speed -= 0.05; 694 op->set_speed (op->speed - 0.05);
693 695
694 /* if the arrow is moving too slow.. stop it. 0.5 was chosen as lower 696 /* if the arrow is moving too slow.. stop it. 0.5 was chosen as lower
695 values look rediculous. */ 697 values look ridiculous. */
696 if (op->speed < (op->type == ARROW ? 0.05 : MIN_ACTIVE_SPEED)) 698 if (op->speed < (op->type == ARROW ? 0.5 : MIN_ACTIVE_SPEED))
697 { 699 {
698 stop_arrow (op); 700 stop_arrow (op);
699 return; 701 return;
700 } 702 }
701 703
714 if (pos->flags () & P_IS_ALIVE) 716 if (pos->flags () & P_IS_ALIVE)
715 { 717 {
716 object *tmp; 718 object *tmp;
717 719
718 for (tmp = pos->bot; tmp; tmp = tmp->above) 720 for (tmp = pos->bot; tmp; tmp = tmp->above)
719 if (tmp->flag [FLAG_ALIVE]) 721 if (tmp->flag [FLAG_ALIVE] && tmp != op->owner)
720 break; 722 {
721
722 /* Not really fair, but don't let monsters hit themselves with 723 /* Not really fair, but don't let monsters hit themselves with
723 * their own arrow - this can be because they fire it then 724 * their own arrow - this can be because they fire it then
724 * move into it. 725 * move into it.
725 */ 726 */
726 if (tmp && tmp != op->owner) 727
727 {
728 /* Found living object, but it is reflecting the missile. Update 728 /* Found living object, but it is reflecting the missile. Update
729 * as below. (Note that for living creatures there is a small 729 * as below. (Note that for living creatures there is a small
730 * chance that reflect_missile fails.) 730 * chance that reflect_missile fails.)
731 */ 731 */
732 if (tmp->flag [FLAG_REFL_MISSILE] && (rndm (0, 99)) < (90 - op->level / 10)) 732 if (tmp->flag [FLAG_REFL_MISSILE] && (rndm (0, 99)) < (90 - op->level / 10))
733 { 733 {
734 int number = op->face;
735
736 op->direction = absdir (op->direction + 4); 734 op->direction = absdir (op->direction + 4);
737 update_turn_face (op); 735 update_turn_face (op);
738 was_reflected = 1; /* skip normal movement calculations */ 736 was_reflected = 1; /* skip normal movement calculations */
739 } 737 }
740 else 738 else
741 { 739 {
742 /* Attack the object. */ 740 /* Attack the object. */
743 op = hit_with_arrow (op, tmp); 741 op = hit_with_arrow (op, tmp);
744 742
745 if (!op) 743 if (!op)
746 return; 744 return;
747 } 745 }
748 } /* if this is not hitting its owner */ 746
749 } /* if there is something alive on this space */ 747 break;
748 }
749 }
750 750
751 if (OB_TYPE_MOVE_BLOCK (op, pos->move_block)) 751 if (OB_TYPE_MOVE_BLOCK (op, pos->move_block))
752 { 752 {
753 int retry = 0; 753 int retry = 0;
754 754
1004 } 1004 }
1005 1005
1006 cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL); 1006 cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL);
1007} 1007}
1008 1008
1009/* move_player_mover: this function takes a "player mover" as an 1009/* move_player_mover: this function takes a "player mover" as an
1010 * argument, and performs the function of a player mover, which is: 1010 * argument, and performs the function of a player mover, which is:
1011 * 1011 *
1012 * a player mover finds any players that are sitting on it. It 1012 * a player mover finds any players that are sitting on it. It
1013 * moves them in the op->stats.sp direction. speed is how often it'll move. 1013 * moves them in the op->stats.sp direction. speed is how often it'll move.
1014 * If attacktype is nonzero it will paralyze the player. If lifesave is set, 1014 * If attacktype is nonzero it will paralyze the player. If lifesave is set,
1016 * it'll paralyze the victim for hp*his speed/op->speed 1016 * it'll paralyze the victim for hp*his speed/op->speed
1017 */ 1017 */
1018static void 1018static void
1019move_player_mover (object *op) 1019move_player_mover (object *op)
1020{ 1020{
1021 int dir = op->stats.sp; 1021 int dir = 0;
1022 sint16 nx, ny;
1023 maptile *m;
1024
1025 /* Determine direction now for random movers so we do the right thing */
1026 if (!dir)
1027 dir = rndm (1, 8);
1028 1022
1029 for (object *victim = op->ms ().bot; victim; victim = victim->above) 1023 for (object *victim = op->ms ().bot; victim; victim = victim->above)
1030 { 1024 {
1031 if (victim->flag [FLAG_ALIVE] && !victim->flag [FLAG_WIZPASS] && 1025 if (victim->flag [FLAG_ALIVE]
1026 && !victim->flag [FLAG_WIZPASS]
1032 (victim->move_type & op->move_type || !victim->move_type)) 1027 && (victim->move_type & op->move_type || !victim->move_type))
1028 {
1029 if (op->flag [FLAG_LIFESAVE] && op->stats.hp-- < 0)
1033 { 1030 {
1031 op->destroy ();
1032 return;
1033 }
1034
1035 /* Determine direction only once so we do the right thing */
1036 // why is it the right thing, though?
1037 if (!dir)
1038 dir = op->stats.sp ? op->stats.sp : rndm (1, 8);
1039
1040 sint16 nx = op->x + DIRX (dir);
1041 sint16 ny = op->y + DIRY (dir);
1042 maptile *m = op->map;
1043 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP)
1044 {
1045 LOG (llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", &m->path, op->x, op->y);
1046 return;
1047 }
1034 1048
1035 if (victim->head) 1049 if (victim->head)
1036 victim = victim->head; 1050 victim = victim->head;
1037
1038 if (op->flag [FLAG_LIFESAVE] && op->stats.hp-- < 0)
1039 {
1040 op->remove ();
1041 return;
1042 }
1043
1044 nx = op->x + freearr_x[dir];
1045 ny = op->y + freearr_y[dir];
1046 m = op->map;
1047 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP)
1048 {
1049 LOG (llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", &m->path, op->x, op->y);
1050 return;
1051 }
1052 1051
1053 if (should_director_abort (op, victim)) 1052 if (should_director_abort (op, victim))
1054 return; 1053 return;
1055 1054
1056 for (object *nextmover = m->at (nx, ny).bot; nextmover; nextmover = nextmover->above) 1055 for (object *nextmover = m->at (nx, ny).bot; nextmover; nextmover = nextmover->above)
1133 break; 1132 break;
1134 } 1133 }
1135 } 1134 }
1136} 1135}
1137 1136
1138/* move_creator (by peterm) 1137/* move_creator (by peterm)
1139 * it has the creator object create it's other_arch right on top of it. 1138 * it has the creator object create it's other_arch right on top of it.
1140 * connected: what will trigger it 1139 * connected: what will trigger it
1141 * hp: how many times it may create before stopping 1140 * hp: how many times it may create before stopping
1142 * lifesave: if set, it'll never disappear but will go on creating 1141 * lifesave: if set, it'll never disappear but will go on creating
1143 * everytime it's triggered 1142 * everytime it's triggered
1165 int i; 1164 int i;
1166 object *ob_to_copy; 1165 object *ob_to_copy;
1167 1166
1168 /* select random object from inventory to copy */ 1167 /* select random object from inventory to copy */
1169 ob_to_copy = creator->inv; 1168 ob_to_copy = creator->inv;
1170 for (ob = creator->inv->below, i = 1; ob != NULL; ob = ob->below, i++) 1169 for (ob = creator->inv->below, i = 1; ob; ob = ob->below, i++)
1171 { 1170 {
1172 if (rndm (0, i) == 0) 1171 if (rndm (0, i) == 0)
1173 { 1172 {
1174 ob_to_copy = ob; 1173 ob_to_copy = ob;
1175 } 1174 }
1176 } 1175 }
1176
1177 new_ob = ob_to_copy->deep_clone (); 1177 new_ob = ob_to_copy->deep_clone ();
1178 new_ob->clr_flag (FLAG_IS_A_TEMPLATE); 1178 new_ob->clr_flag (FLAG_IS_A_TEMPLATE);
1179 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE); 1179 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE);
1180 } 1180 }
1181 else 1181 else
1198 return; 1198 return;
1199 } 1199 }
1200 1200
1201 // for now lets try to identify everything generated here, it mostly 1201 // for now lets try to identify everything generated here, it mostly
1202 // happens automated, so this will at least fix many identify-experience holes 1202 // happens automated, so this will at least fix many identify-experience holes
1203 if (new_ob->need_identify ())
1203 new_ob->set_flag (FLAG_IDENTIFIED); 1204 new_ob->set_flag (FLAG_IDENTIFIED);
1204 1205
1205 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); 1206 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y);
1206 if (new_ob->flag [FLAG_FREED]) 1207 if (new_ob->flag [FLAG_FREED])
1207 return; 1208 return;
1208 1209
1483 1484
1484 case LAMP: 1485 case LAMP:
1485 case TORCH: 1486 case TORCH:
1486 move_lamp (op); 1487 move_lamp (op);
1487 break; 1488 break;
1488 }
1489}
1490 1489
1490 case PHYSICS: // hmm, bad naming
1491 move_physics (op);
1492 break;
1493 }
1494}
1495

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines