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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 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. |
… | |
… | |
110 | link_skills (); |
110 | link_skills (); |
111 | |
111 | |
112 | assign (title, ob->arch->object::name); |
112 | assign (title, ob->arch->object::name); |
113 | |
113 | |
114 | /* if it's a dragon player, set the correct title here */ |
114 | /* if it's a dragon player, set the correct title here */ |
115 | if (is_dragon_pl (ob)) |
115 | if (ob->is_dragon ()) |
116 | { |
116 | { |
117 | object *tmp, *abil = 0, *skin = 0; |
117 | object *tmp, *abil = 0, *skin = 0; |
118 | |
118 | |
119 | for (tmp = ob->inv; tmp; tmp = tmp->below) |
119 | for (tmp = ob->inv; tmp; tmp = tmp->below) |
120 | if (tmp->type == FORCE) |
120 | if (tmp->type == FORCE) |
… | |
… | |
136 | esrv_send_inventory (ob, ob); |
136 | esrv_send_inventory (ob, ob); |
137 | esrv_add_spells (this, 0); |
137 | esrv_add_spells (this, 0); |
138 | |
138 | |
139 | ob->flag [FLAG_READY_WEAPON] = false; |
139 | ob->flag [FLAG_READY_WEAPON] = false; |
140 | ob->flag [FLAG_READY_SKILL] = false; |
140 | ob->flag [FLAG_READY_SKILL] = false; |
|
|
141 | ob->flag [FLAG_READY_RANGE] = false; |
141 | ob->flag [FLAG_READY_BOW] = false; |
142 | ob->flag [FLAG_READY_BOW] = false; |
142 | |
143 | |
143 | for (object *op = ob->inv; op; op = op->below) |
144 | for (object *op = ob->inv; op; op = op->below) |
144 | if (op->flag [FLAG_APPLIED]) |
145 | if (op->flag [FLAG_APPLIED]) |
145 | switch (op->type) |
146 | switch (op->type) |
146 | { |
147 | { |
147 | case SKILL: |
148 | case SKILL: |
148 | op->flag [FLAG_APPLIED] = false; |
149 | op->flag [FLAG_APPLIED] = false; |
149 | break; |
150 | break; |
150 | |
151 | |
|
|
152 | case SPELL: |
151 | case WAND: |
153 | case WAND: |
152 | case ROD: |
154 | case ROD: |
153 | case HORN: |
155 | case HORN: |
154 | case BOW: |
156 | case BOW: |
|
|
157 | case RANGED: |
155 | ranged_ob = op; |
158 | ranged_ob = op; |
|
|
159 | op->flag [FLAG_APPLIED] = false; |
156 | break; |
160 | break; |
157 | |
161 | |
158 | case WEAPON: |
162 | case WEAPON: |
159 | combat_ob = op; |
163 | combat_ob = op; |
|
|
164 | op->flag [FLAG_APPLIED] = false; |
160 | break; |
165 | break; |
161 | } |
166 | } |
162 | |
167 | |
|
|
168 | ob->update_stats (); // we unapplied stuff above |
|
|
169 | |
163 | ob->current_weapon = 0; |
170 | ob->current_weapon = 0; |
164 | ob->change_weapon (combat_ob ? combat_ob : ranged_ob); |
171 | if (object *item = combat_ob ? combat_ob : ranged_ob) |
165 | activate (); // change_weapon also activates, but this doesn't hurt |
172 | ob->apply (item); |
|
|
173 | |
|
|
174 | activate (); |
166 | |
175 | |
167 | INVOKE_PLAYER (CONNECT, this); |
176 | INVOKE_PLAYER (CONNECT, this); |
168 | INVOKE_PLAYER (LOGIN, this); |
177 | INVOKE_PLAYER (LOGIN, this); |
169 | } |
178 | } |
170 | |
179 | |
… | |
… | |
838 | dir = absdir (4 + rv.direction); |
847 | dir = absdir (4 + rv.direction); |
839 | for (diff = 0; diff < 3; diff++) |
848 | for (diff = 0; diff < 3; diff++) |
840 | { |
849 | { |
841 | int m = 1 - rndm (2) * 2; |
850 | int m = 1 - rndm (2) * 2; |
842 | |
851 | |
843 | if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) |
852 | if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m)))) |
844 | return; |
853 | return; |
845 | } |
854 | } |
846 | |
855 | |
847 | /* Cornered, get rid of scared */ |
856 | /* Cornered, get rid of scared */ |
848 | CLEAR_FLAG (op, FLAG_SCARED); |
857 | CLEAR_FLAG (op, FLAG_SCARED); |
… | |
… | |
858 | { |
867 | { |
859 | object *tmp, *next; |
868 | object *tmp, *next; |
860 | int stop = 0; |
869 | int stop = 0; |
861 | int wvratio; |
870 | int wvratio; |
862 | |
871 | |
863 | /* if you're flying, you cna't pick up anything */ |
872 | /* if you're flying, you can't pick up anything */ |
864 | if (op->move_type & MOVE_FLYING) |
873 | if (op->move_type & MOVE_FLYING) |
865 | return 1; |
874 | return 1; |
866 | |
875 | |
867 | next = op->below; |
876 | next = op->below; |
868 | |
877 | |
… | |
… | |
1584 | { |
1593 | { |
1585 | LOG (llevError, "Object %s lacks a spell\n", &item->name); |
1594 | LOG (llevError, "Object %s lacks a spell\n", &item->name); |
1586 | return; |
1595 | return; |
1587 | } |
1596 | } |
1588 | |
1597 | |
1589 | if (!op->change_weapon (item)) |
1598 | if (!op->apply (item)) |
1590 | return; |
1599 | return; |
1591 | |
1600 | |
1592 | if (item->type == WAND) |
1601 | if (item->type == WAND) |
1593 | { |
1602 | { |
1594 | if (item->stats.food <= 0) |
1603 | if (item->stats.food <= 0) |
… | |
… | |
1667 | if (op->speed_left > 0.f) |
1676 | if (op->speed_left > 0.f) |
1668 | --op->speed_left; |
1677 | --op->speed_left; |
1669 | else |
1678 | else |
1670 | return false; |
1679 | return false; |
1671 | |
1680 | |
1672 | if (!op->change_weapon (ob)) |
1681 | if (!op->apply (ob)) |
1673 | return false; |
1682 | return false; |
1674 | |
1683 | |
1675 | /* check for loss of invisiblity/hide */ |
1684 | /* check for loss of invisiblity/hide */ |
1676 | if (action_makes_visible (op)) |
1685 | if (action_makes_visible (op)) |
1677 | make_visible (op); |
1686 | make_visible (op); |
… | |
… | |
1856 | * going to try and move (not fire weapons). |
1865 | * going to try and move (not fire weapons). |
1857 | */ |
1866 | */ |
1858 | bool |
1867 | bool |
1859 | move_player_attack (object *op, int dir) |
1868 | move_player_attack (object *op, int dir) |
1860 | { |
1869 | { |
1861 | if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op)) |
1870 | if (!op->contr->braced && op->speed_left > 0.f && op->move (dir)) |
1862 | { |
1871 | { |
1863 | --op->speed_left; |
1872 | --op->speed_left; |
1864 | return true; |
1873 | return true; |
1865 | } |
1874 | } |
1866 | |
1875 | |
1867 | int on_battleground; |
|
|
1868 | |
|
|
1869 | sint16 nx = freearr_x[dir] + op->x; |
1876 | sint16 nx = freearr_x[dir] + op->x; |
1870 | sint16 ny = freearr_y[dir] + op->y; |
1877 | sint16 ny = freearr_y[dir] + op->y; |
1871 | |
|
|
1872 | on_battleground = op_on_battleground (op, 0, 0); |
|
|
1873 | |
1878 | |
1874 | if (out_of_map (op->map, nx, ny)) |
1879 | if (out_of_map (op->map, nx, ny)) |
1875 | return false; |
1880 | return false; |
1876 | |
1881 | |
1877 | /* If braced, or can't move to the square, and it is not out of the |
1882 | /* If braced, or can't move to the square, and it is not out of the |
… | |
… | |
1949 | } |
1954 | } |
1950 | else |
1955 | else |
1951 | return false; |
1956 | return false; |
1952 | } |
1957 | } |
1953 | |
1958 | |
|
|
1959 | bool on_battleground = op_on_battleground (op, 0, 0); |
|
|
1960 | |
1954 | /* in certain circumstances, you shouldn't attack friendly |
1961 | /* in certain circumstances, you shouldn't attack friendly |
1955 | * creatures. Note that if you are braced, you can't push |
1962 | * creatures. Note that if you are braced, you can't push |
1956 | * someone, but put it inside this loop so that you won't |
1963 | * someone, but put it inside this loop so that you won't |
1957 | * attack them either. |
1964 | * attack them either. |
1958 | */ |
1965 | */ |
… | |
… | |
2026 | { |
2033 | { |
2027 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
2034 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
2028 | return 0; |
2035 | return 0; |
2029 | |
2036 | |
2030 | /* Sanity check: make sure dir is valid */ |
2037 | /* Sanity check: make sure dir is valid */ |
2031 | if ((dir < 0) || (dir >= 9)) |
2038 | if (dir < 0 || dir >= 9) |
2032 | { |
2039 | { |
2033 | LOG (llevError, "move_player: invalid direction %d\n", dir); |
2040 | LOG (llevError, "move_player: invalid direction %d\n", dir); |
2034 | return 0; |
2041 | return 0; |
2035 | } |
2042 | } |
2036 | |
2043 | |
… | |
… | |
2128 | |
2135 | |
2129 | if (op->stats.hp < 0) |
2136 | if (op->stats.hp < 0) |
2130 | op->stats.hp = op->stats.maxhp; |
2137 | op->stats.hp = op->stats.maxhp; |
2131 | |
2138 | |
2132 | if (op->stats.food < 0) |
2139 | if (op->stats.food < 0) |
2133 | op->stats.food = 999; |
2140 | op->stats.food = MAX_FOOD; |
2134 | |
2141 | |
2135 | op->update_stats (); |
2142 | op->update_stats (); |
2136 | return 1; |
2143 | return 1; |
2137 | } |
2144 | } |
2138 | |
2145 | |
… | |
… | |
2449 | cure_disease (op, 0, 0); /* remove any disease */ |
2456 | cure_disease (op, 0, 0); /* remove any disease */ |
2450 | |
2457 | |
2451 | max_it (op->stats.hp , op->stats.maxhp); |
2458 | max_it (op->stats.hp , op->stats.maxhp); |
2452 | max_it (op->stats.sp , op->stats.maxsp); |
2459 | max_it (op->stats.sp , op->stats.maxsp); |
2453 | max_it (op->stats.grace, op->stats.maxgrace); |
2460 | max_it (op->stats.grace, op->stats.maxgrace); |
2454 | |
|
|
2455 | if (op->stats.food <= 0) |
2461 | max_it (op->stats.food , 200); |
2456 | op->stats.food = 999; |
|
|
2457 | |
2462 | |
2458 | // remove all spell effects that are active |
2463 | // remove all spell effects that are active |
2459 | // to avoid long-term effects such as word-of-recall |
2464 | // to avoid long-term effects such as word-of-recall |
2460 | for (object *item = op->inv; item; ) |
2465 | for (object *item = op->inv; item; ) |
2461 | { |
2466 | { |
… | |
… | |
3045 | && tmp->name == shstr_battleground |
3050 | && tmp->name == shstr_battleground |
3046 | && EXIT_X (tmp) && EXIT_Y (tmp)) |
3051 | && EXIT_X (tmp) && EXIT_Y (tmp)) |
3047 | { |
3052 | { |
3048 | /* before we assign the exit, check if this is a teambattle */ |
3053 | /* before we assign the exit, check if this is a teambattle */ |
3049 | if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) |
3054 | if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) |
3050 | { |
|
|
3051 | for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below) |
3055 | for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below) |
|
|
3056 | if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying) |
3052 | { |
3057 | { |
3053 | if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying) |
|
|
3054 | { |
|
|
3055 | if (x && y) |
3058 | if (x && y) |
3056 | *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); |
3059 | *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); |
3057 | |
3060 | |
3058 | return 1; |
3061 | return 1; |
3059 | } |
|
|
3060 | } |
3062 | } |
3061 | } |
|
|
3062 | |
3063 | |
3063 | if (x && y) |
3064 | if (x && y) |
3064 | *x = EXIT_X (tmp), *y = EXIT_Y (tmp); |
3065 | *x = EXIT_X (tmp), *y = EXIT_Y (tmp); |
3065 | |
3066 | |
3066 | return 1; |
3067 | return 1; |
… | |
… | |
3229 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3230 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3230 | who->insert (tmp); |
3231 | who->insert (tmp); |
3231 | } |
3232 | } |
3232 | } |
3233 | } |
3233 | |
3234 | |
3234 | /** |
|
|
3235 | * Unready an object for a player. This function does nothing if the object was |
|
|
3236 | * not readied. |
|
|
3237 | */ |
|
|
3238 | void |
|
|
3239 | player_unready_range_ob (player *pl, object *ob) |
|
|
3240 | { |
|
|
3241 | if (pl->ob->current_weapon == ob) |
|
|
3242 | pl->ob->current_weapon = 0; |
|
|
3243 | |
|
|
3244 | if (pl->combat_ob == ob) |
|
|
3245 | pl->combat_ob = 0; |
|
|
3246 | |
|
|
3247 | if (pl->ranged_ob == ob) |
|
|
3248 | pl->ranged_ob = 0; |
|
|
3249 | } |
|
|
3250 | |
|
|
3251 | //-GPL |
3235 | //-GPL |
3252 | |
3236 | |
3253 | sint8 |
3237 | sint8 |
3254 | player::darkness_at (maptile *map, int x, int y) const |
3238 | player::darkness_at (maptile *map, int x, int y) const |
3255 | { |
3239 | { |