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 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 |
… | |
… | |
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 |
… | |
… | |
655 | { |
655 | { |
656 | int was_reflected; |
656 | int was_reflected; |
657 | |
657 | |
658 | if (!op->map) |
658 | if (!op->map) |
659 | { |
659 | { |
660 | LOG (llevError, "BUG: Arrow had no map.\n"); |
660 | LOG (llevError | logBacktrace, "BUG: Arrow %s had no map.\n", op->debug_desc ()); |
661 | op->destroy (); |
661 | op->destroy (); |
662 | return; |
662 | return; |
663 | } |
663 | } |
664 | |
664 | |
665 | /* we need to stop thrown objects at some point. Like here. */ |
665 | /* we need to stop thrown objects at some point. Like here. */ |
… | |
… | |
687 | } |
687 | } |
688 | |
688 | |
689 | /* decrease the speed as it flies. 0.05 means a standard bow will shoot |
689 | /* decrease the speed as it flies. 0.05 means a standard bow will shoot |
690 | * about 17 squares. Tune as needed. |
690 | * about 17 squares. Tune as needed. |
691 | */ |
691 | */ |
692 | op->speed -= 0.05; |
692 | op->set_speed (op->speed - 0.05); |
693 | |
693 | |
694 | /* if the arrow is moving too slow.. stop it. 0.5 was chosen as lower |
694 | /* if the arrow is moving too slow.. stop it. 0.5 was chosen as lower |
695 | values look rediculous. */ |
695 | values look rediculous. */ |
696 | if (op->speed < (op->type == ARROW ? 0.05 : MIN_ACTIVE_SPEED)) |
696 | if (op->speed < (op->type == ARROW ? 0.5 : MIN_ACTIVE_SPEED)) |
697 | { |
697 | { |
698 | stop_arrow (op); |
698 | stop_arrow (op); |
699 | return; |
699 | return; |
700 | } |
700 | } |
701 | |
701 | |
… | |
… | |
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 | */ |
1018 | static void |
1018 | static void |
1019 | move_player_mover (object *op) |
1019 | move_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 + freearr_x[dir]; |
|
|
1041 | sint16 ny = op->y + freearr_y[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) |
… | |
… | |
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 | |