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.121 by root, Wed Nov 16 23:42:03 2016 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,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * 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 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * 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 9 * 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 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * 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 Affero GNU General Public License 18 * 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 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * 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>
23 */ 23 */
24 24
25/* 25/*
26 * Routines that is executed from objects based on their speed have been 26 * Routines that is executed from objects based on their speed have been
239{ /* 1 = going down, 0 = going up */ 239{ /* 1 = going down, 0 = going up */
240 object *tmp; 240 object *tmp;
241 241
242 if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op)) 242 if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op))
243 { 243 {
244 LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op)); 244 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; 245 op->stats.wc = 0;
246 } 246 }
247 247
248 /* We're going down */ 248 /* We're going down */
249 if (op->value) 249 if (op->value)
272 /* We're going up */ 272 /* We're going up */
273 273
274 /* First, lets see if we are already at the top */ 274 /* First, lets see if we are already at the top */
275 if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1)) 275 if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1))
276 { 276 {
277
278 /* Check to make sure that only non pickable and non rollable 277 /* Check to make sure that only non pickable and non rollable
279 * objects are above the gate. If so, we finish closing the gate, 278 * objects are above the gate. If so, we finish closing the gate,
280 * otherwise, we fall through to the code below which should lower 279 * otherwise, we fall through to the code below which should lower
281 * the gate slightly. 280 * the gate slightly.
282 */ 281 */
502 move_apply (op, tmp, tmp); 501 move_apply (op, tmp, tmp);
503 } 502 }
504 } 503 }
505 504
506 SET_ANIMATION (op, op->stats.wc); 505 SET_ANIMATION (op, op->stats.wc);
507 update_object (op, UP_OBJ_FACE); 506 update_object (op, UP_OBJ_CHANGE);
508 return; 507 return;
509 } 508 }
510 509
511 /* We're closing */ 510 /* We're closing */
512 op->move_on = 0; 511 op->move_on = 0;
513 512
514 op->stats.wc++; 513 op->stats.wc++;
515 if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) 514 if (op->stats.wc >= NUM_ANIMATIONS (op))
516 op->stats.wc = NUM_ANIMATIONS (op) - 1; 515 op->stats.wc = NUM_ANIMATIONS (op) - 1;
517 516
518 SET_ANIMATION (op, op->stats.wc); 517 SET_ANIMATION (op, op->stats.wc);
519 update_object (op, UP_OBJ_FACE); 518 update_object (op, UP_OBJ_CHANGE);
520 if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1)) 519 if (op->stats.wc == (NUM_ANIMATIONS (op) - 1))
521 op->set_speed (0); /* closed, let's stop */ 520 op->set_speed (0); /* closed, let's stop */
522} 521}
523 522
524 523
525/* stop_item() returns a pointer to the stopped object. The stopped object 524/* stop_item() returns a pointer to the stopped object. The stopped object
655{ 654{
656 int was_reflected; 655 int was_reflected;
657 656
658 if (!op->map) 657 if (!op->map)
659 { 658 {
660 LOG (llevError, "BUG: Arrow had no map.\n"); 659 LOG (llevError | logBacktrace, "BUG: Arrow %s had no map.\n", op->debug_desc ());
661 op->destroy (); 660 op->destroy ();
662 return; 661 return;
663 } 662 }
664 663
665 /* we need to stop thrown objects at some point. Like here. */ 664 /* we need to stop thrown objects at some point. Like here. */
687 } 686 }
688 687
689 /* decrease the speed as it flies. 0.05 means a standard bow will shoot 688 /* decrease the speed as it flies. 0.05 means a standard bow will shoot
690 * about 17 squares. Tune as needed. 689 * about 17 squares. Tune as needed.
691 */ 690 */
692 op->speed -= 0.05; 691 op->set_speed (op->speed - 0.05);
693 692
694 /* if the arrow is moving too slow.. stop it. 0.5 was chosen as lower 693 /* if the arrow is moving too slow.. stop it. 0.5 was chosen as lower
695 values look rediculous. */ 694 values look ridiculous. */
696 if (op->speed < (op->type == ARROW ? 0.05 : MIN_ACTIVE_SPEED)) 695 if (op->speed < (op->type == ARROW ? 0.5 : MIN_ACTIVE_SPEED))
697 { 696 {
698 stop_arrow (op); 697 stop_arrow (op);
699 return; 698 return;
700 } 699 }
701 700
714 if (pos->flags () & P_IS_ALIVE) 713 if (pos->flags () & P_IS_ALIVE)
715 { 714 {
716 object *tmp; 715 object *tmp;
717 716
718 for (tmp = pos->bot; tmp; tmp = tmp->above) 717 for (tmp = pos->bot; tmp; tmp = tmp->above)
719 if (tmp->flag [FLAG_ALIVE]) 718 if (tmp->flag [FLAG_ALIVE] && tmp != op->owner)
720 break; 719 {
721
722 /* Not really fair, but don't let monsters hit themselves with 720 /* Not really fair, but don't let monsters hit themselves with
723 * their own arrow - this can be because they fire it then 721 * their own arrow - this can be because they fire it then
724 * move into it. 722 * move into it.
725 */ 723 */
726 if (tmp && tmp != op->owner) 724
727 {
728 /* Found living object, but it is reflecting the missile. Update 725 /* Found living object, but it is reflecting the missile. Update
729 * as below. (Note that for living creatures there is a small 726 * as below. (Note that for living creatures there is a small
730 * chance that reflect_missile fails.) 727 * chance that reflect_missile fails.)
731 */ 728 */
732 if (tmp->flag [FLAG_REFL_MISSILE] && (rndm (0, 99)) < (90 - op->level / 10)) 729 if (tmp->flag [FLAG_REFL_MISSILE] && (rndm (0, 99)) < (90 - op->level / 10))
733 { 730 {
734 int number = op->face;
735
736 op->direction = absdir (op->direction + 4); 731 op->direction = absdir (op->direction + 4);
737 update_turn_face (op); 732 update_turn_face (op);
738 was_reflected = 1; /* skip normal movement calculations */ 733 was_reflected = 1; /* skip normal movement calculations */
739 } 734 }
740 else 735 else
741 { 736 {
742 /* Attack the object. */ 737 /* Attack the object. */
743 op = hit_with_arrow (op, tmp); 738 op = hit_with_arrow (op, tmp);
744 739
745 if (!op) 740 if (!op)
746 return; 741 return;
747 } 742 }
748 } /* if this is not hitting its owner */ 743
749 } /* if there is something alive on this space */ 744 break;
745 }
746 }
750 747
751 if (OB_TYPE_MOVE_BLOCK (op, pos->move_block)) 748 if (OB_TYPE_MOVE_BLOCK (op, pos->move_block))
752 { 749 {
753 int retry = 0; 750 int retry = 0;
754 751
1004 } 1001 }
1005 1002
1006 cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL); 1003 cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL);
1007} 1004}
1008 1005
1009/* move_player_mover: this function takes a "player mover" as an 1006/* move_player_mover: this function takes a "player mover" as an
1010 * argument, and performs the function of a player mover, which is: 1007 * argument, and performs the function of a player mover, which is:
1011 * 1008 *
1012 * a player mover finds any players that are sitting on it. It 1009 * 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. 1010 * 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, 1011 * 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 1013 * it'll paralyze the victim for hp*his speed/op->speed
1017 */ 1014 */
1018static void 1015static void
1019move_player_mover (object *op) 1016move_player_mover (object *op)
1020{ 1017{
1021 int dir = op->stats.sp; 1018 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 1019
1029 for (object *victim = op->ms ().bot; victim; victim = victim->above) 1020 for (object *victim = op->ms ().bot; victim; victim = victim->above)
1030 { 1021 {
1031 if (victim->flag [FLAG_ALIVE] && !victim->flag [FLAG_WIZPASS] && 1022 if (victim->flag [FLAG_ALIVE]
1023 && !victim->flag [FLAG_WIZPASS]
1032 (victim->move_type & op->move_type || !victim->move_type)) 1024 && (victim->move_type & op->move_type || !victim->move_type))
1025 {
1026 if (op->flag [FLAG_LIFESAVE] && op->stats.hp-- < 0)
1033 { 1027 {
1028 op->destroy ();
1029 return;
1030 }
1031
1032 /* Determine direction only once so we do the right thing */
1033 // why is it the right thing, though?
1034 if (!dir)
1035 dir = op->stats.sp ? op->stats.sp : rndm (1, 8);
1036
1037 sint16 nx = op->x + freearr_x[dir];
1038 sint16 ny = op->y + freearr_y[dir];
1039 maptile *m = op->map;
1040 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP)
1041 {
1042 LOG (llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", &m->path, op->x, op->y);
1043 return;
1044 }
1034 1045
1035 if (victim->head) 1046 if (victim->head)
1036 victim = victim->head; 1047 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 1048
1053 if (should_director_abort (op, victim)) 1049 if (should_director_abort (op, victim))
1054 return; 1050 return;
1055 1051
1056 for (object *nextmover = m->at (nx, ny).bot; nextmover; nextmover = nextmover->above) 1052 for (object *nextmover = m->at (nx, ny).bot; nextmover; nextmover = nextmover->above)
1165 int i; 1161 int i;
1166 object *ob_to_copy; 1162 object *ob_to_copy;
1167 1163
1168 /* select random object from inventory to copy */ 1164 /* select random object from inventory to copy */
1169 ob_to_copy = creator->inv; 1165 ob_to_copy = creator->inv;
1170 for (ob = creator->inv->below, i = 1; ob != NULL; ob = ob->below, i++) 1166 for (ob = creator->inv->below, i = 1; ob; ob = ob->below, i++)
1171 { 1167 {
1172 if (rndm (0, i) == 0) 1168 if (rndm (0, i) == 0)
1173 { 1169 {
1174 ob_to_copy = ob; 1170 ob_to_copy = ob;
1175 } 1171 }
1176 } 1172 }
1173
1177 new_ob = ob_to_copy->deep_clone (); 1174 new_ob = ob_to_copy->deep_clone ();
1178 new_ob->clr_flag (FLAG_IS_A_TEMPLATE); 1175 new_ob->clr_flag (FLAG_IS_A_TEMPLATE);
1179 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE); 1176 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE);
1180 } 1177 }
1181 else 1178 else
1198 return; 1195 return;
1199 } 1196 }
1200 1197
1201 // for now lets try to identify everything generated here, it mostly 1198 // for now lets try to identify everything generated here, it mostly
1202 // happens automated, so this will at least fix many identify-experience holes 1199 // happens automated, so this will at least fix many identify-experience holes
1200 if (new_ob->need_identify ())
1203 new_ob->set_flag (FLAG_IDENTIFIED); 1201 new_ob->set_flag (FLAG_IDENTIFIED);
1204 1202
1205 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); 1203 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y);
1206 if (new_ob->flag [FLAG_FREED]) 1204 if (new_ob->flag [FLAG_FREED])
1207 return; 1205 return;
1208 1206
1483 1481
1484 case LAMP: 1482 case LAMP:
1485 case TORCH: 1483 case TORCH:
1486 move_lamp (op); 1484 move_lamp (op);
1487 break; 1485 break;
1488 }
1489}
1490 1486
1487 case PHYSICS: // hmm, bad naming
1488 move_physics (op);
1489 break;
1490 }
1491}
1492

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines