… | |
… | |
147 | draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, |
147 | draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, |
148 | MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s\n", (char *)"%s\n%s", subject, news); |
148 | MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s\n", (char *)"%s\n%s", subject, news); |
149 | close_and_delete (fp, comp); |
149 | close_and_delete (fp, comp); |
150 | } |
150 | } |
151 | |
151 | |
152 | float |
|
|
153 | player::weapon_speed () const |
|
|
154 | { |
|
|
155 | return ob->speed / weapon_sp * .5f;//TODO, the .5 is arbitrary |
|
|
156 | } |
|
|
157 | |
|
|
158 | /* This loads the first map an puts the player on it. */ |
152 | /* This loads the first map an puts the player on it. */ |
159 | static void |
153 | static void |
160 | set_first_map (object *op) |
154 | set_first_map (object *op) |
161 | { |
155 | { |
162 | op->contr->maplevel = first_map_path; |
156 | op->contr->maplevel = first_map_path; |
163 | op->x = -1; |
157 | op->x = -1; |
164 | op->y = -1; |
158 | op->y = -1; |
165 | } |
|
|
166 | |
|
|
167 | void |
|
|
168 | player::enter_map () |
|
|
169 | { |
|
|
170 | object *tmp = object::create (); |
|
|
171 | |
|
|
172 | EXIT_PATH (tmp) = maplevel; |
|
|
173 | EXIT_X (tmp) = ob->x; |
|
|
174 | EXIT_Y (tmp) = ob->y; |
|
|
175 | ob->enter_exit (tmp); |
|
|
176 | |
|
|
177 | tmp->destroy (); |
|
|
178 | } |
159 | } |
179 | |
160 | |
180 | void |
161 | void |
181 | player::activate () |
162 | player::activate () |
182 | { |
163 | { |
… | |
… | |
187 | ob->remove (); |
168 | ob->remove (); |
188 | ob->map = 0; |
169 | ob->map = 0; |
189 | ob->activate_recursive (); |
170 | ob->activate_recursive (); |
190 | CLEAR_FLAG (ob, FLAG_FRIENDLY); |
171 | CLEAR_FLAG (ob, FLAG_FRIENDLY); |
191 | add_friendly_object (ob); |
172 | add_friendly_object (ob); |
192 | enter_map (); |
|
|
193 | } |
173 | } |
194 | |
174 | |
195 | void |
175 | void |
196 | player::deactivate () |
176 | player::deactivate () |
197 | { |
177 | { |
… | |
… | |
264 | |
244 | |
265 | new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); |
245 | new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); |
266 | |
246 | |
267 | esrv_new_player (this, ob->weight + ob->carrying); |
247 | esrv_new_player (this, ob->weight + ob->carrying); |
268 | |
248 | |
|
|
249 | ob->flag [FLAG_READY_WEAPON] = false; |
|
|
250 | ob->flag [FLAG_READY_SKILL] = false; |
|
|
251 | ob->flag [FLAG_READY_BOW] = false; |
|
|
252 | |
269 | for (object *op = ob->inv; op; op = op->below) |
253 | for (object *op = ob->inv; op; op = op->below) |
270 | if (op->flag [FLAG_APPLIED]) |
254 | if (op->flag [FLAG_APPLIED]) |
271 | switch (op->type) |
255 | switch (op->type) |
272 | { |
256 | { |
|
|
257 | case SKILL: |
|
|
258 | ob->flag [FLAG_APPLIED] = false; |
|
|
259 | break; |
|
|
260 | |
273 | case WAND: |
261 | case WAND: |
274 | case ROD: |
262 | case ROD: |
275 | case HORN: |
263 | case HORN: |
276 | case BOW: |
264 | case BOW: |
277 | case SKILL_TOOL: |
265 | ranged_ob = op; |
|
|
266 | break; |
|
|
267 | |
278 | case WEAPON: |
268 | case WEAPON: |
279 | op->flag [FLAG_APPLIED] = false; |
269 | combat_ob = op; |
280 | apply_special (ob, op, AP_APPLY); |
|
|
281 | break; |
270 | break; |
282 | } |
271 | } |
283 | |
272 | |
|
|
273 | ob->change_weapon (combat_ob ? combat_ob : ranged_ob); |
284 | ob->update_stats (); |
274 | ob->update_stats (); |
|
|
275 | |
285 | ns->floorbox_update (); |
276 | ns->floorbox_update (); |
286 | |
|
|
287 | esrv_send_inventory (ob, ob); |
277 | esrv_send_inventory (ob, ob); |
288 | esrv_add_spells (this, 0); |
278 | esrv_add_spells (this, 0); |
289 | |
279 | |
290 | activate (); |
280 | activate (); |
291 | |
281 | |
… | |
… | |
324 | player::set_object (object *op) |
314 | player::set_object (object *op) |
325 | { |
315 | { |
326 | ob = op; |
316 | ob = op; |
327 | ob->contr = this; /* this aren't yet in archetype */ |
317 | ob->contr = this; /* this aren't yet in archetype */ |
328 | |
318 | |
329 | ob->speed_left = 0.5f; |
|
|
330 | ob->speed = 1.0f; |
319 | ob->speed = 1.0f; |
|
|
320 | ob->speed_left = 0.5f; |
|
|
321 | |
331 | ob->direction = 5; /* So player faces south */ |
322 | ob->direction = 5; /* So player faces south */ |
332 | } |
323 | } |
333 | |
324 | |
334 | player::player () |
325 | player::player () |
335 | { |
326 | { |
336 | /* There are some elements we want initialised to non zero value - |
327 | /* There are some elements we want initialised to non zero value - |
… | |
… | |
347 | petmode = pet_normal; |
338 | petmode = pet_normal; |
348 | listening = 10; |
339 | listening = 10; |
349 | usekeys = containers; |
340 | usekeys = containers; |
350 | peaceful = 1; /* default peaceful */ |
341 | peaceful = 1; /* default peaceful */ |
351 | do_los = 1; |
342 | do_los = 1; |
|
|
343 | |
|
|
344 | weapon_sp = 1.0f; |
|
|
345 | weapon_sp_left = 0.5f; |
352 | } |
346 | } |
353 | |
347 | |
354 | void |
348 | void |
355 | player::do_destroy () |
349 | player::do_destroy () |
356 | { |
350 | { |
… | |
… | |
1631 | arrow->stats.grace = arrow->attacktype; |
1625 | arrow->stats.grace = arrow->attacktype; |
1632 | |
1626 | |
1633 | if (arrow->slaying) |
1627 | if (arrow->slaying) |
1634 | arrow->spellarg = strdup (arrow->slaying); |
1628 | arrow->spellarg = strdup (arrow->slaying); |
1635 | |
1629 | |
|
|
1630 | #if 0 |
1636 | if (player *pl = op->contr) |
1631 | if (player *pl = op->contr) |
1637 | { |
1632 | { |
1638 | if (!pl->has_hit) |
|
|
1639 | { |
|
|
1640 | pl->has_hit = 1; |
|
|
1641 | pl->ob->speed_left += pl->weapon_speed () - pl->ob->speed; |
|
|
1642 | } |
|
|
1643 | #if 0 |
|
|
1644 | float speed = pl->weapon_sp; |
1633 | float speed = pl->weapon_sp; |
1645 | |
1634 | |
1646 | /* penalize ROF for bestarrow */ |
1635 | /* penalize ROF for bestarrow */ |
1647 | if (pl->bowtype == bow_bestarrow) |
1636 | if (pl->bowtype == bow_bestarrow) |
1648 | speed *= .9f; |
1637 | speed *= .9f; |
1649 | else |
1638 | else |
1650 | speed *= 1.f + dex_bonus[op->stats.Dex] * .2f; |
1639 | speed *= 1.f + dex_bonus[op->stats.Dex] * .2f; |
1651 | |
1640 | |
1652 | op->speed_left += speed - op->speed; |
1641 | op->speed_left += speed - op->speed; |
|
|
1642 | } |
1653 | #endif |
1643 | #endif |
1654 | } |
|
|
1655 | |
1644 | |
1656 | SET_ANIMATION (arrow, arrow->direction); |
1645 | SET_ANIMATION (arrow, arrow->direction); |
1657 | |
1646 | |
1658 | /* update the speed */ |
1647 | /* update the speed */ |
1659 | arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 |
1648 | arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.f |
1660 | + bow->stats.dam / 7.0; |
1649 | + bow->stats.dam / 7.f; |
1661 | |
1650 | |
1662 | arrow->set_speed (max (arrow->speed, 2.0)); |
1651 | arrow->set_speed (max (arrow->speed, 2.f)); |
1663 | arrow->speed_left = 0; |
1652 | arrow->speed_left = 0; |
1664 | |
1653 | |
1665 | int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc; |
1654 | int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc; |
1666 | |
1655 | |
1667 | if (op->type == PLAYER) |
1656 | if (op->type == PLAYER) |
… | |
… | |
1826 | } |
1815 | } |
1827 | } |
1816 | } |
1828 | |
1817 | |
1829 | /* Received a fire command for the player - go and do it. |
1818 | /* Received a fire command for the player - go and do it. |
1830 | */ |
1819 | */ |
1831 | void |
1820 | bool |
1832 | fire (object *op, int dir) |
1821 | fire (object *op, int dir) |
1833 | { |
1822 | { |
1834 | int spellcost = 0; |
1823 | int spellcost = 0; |
1835 | |
1824 | |
1836 | /* check for loss of invisiblity/hide */ |
1825 | /* check for loss of invisiblity/hide */ |
… | |
… | |
1840 | player *pl = op->contr; |
1829 | player *pl = op->contr; |
1841 | |
1830 | |
1842 | if (pl->golem) |
1831 | if (pl->golem) |
1843 | { |
1832 | { |
1844 | control_golem (op->contr->golem, dir); |
1833 | control_golem (op->contr->golem, dir); |
1845 | return; |
1834 | return false; |
1846 | } |
1835 | } |
1847 | |
1836 | |
1848 | object *ob = pl->ranged_ob; |
1837 | object *ob = pl->ranged_ob; |
1849 | |
1838 | |
1850 | if (!ob) |
1839 | if (!ob) |
1851 | return; |
1840 | return false; |
1852 | |
1841 | |
1853 | if (!op->change_weapon (ob)) |
1842 | if (!op->change_weapon (ob)) |
1854 | return; |
1843 | return false; |
|
|
1844 | |
|
|
1845 | if (op->speed_left > 0.f) |
|
|
1846 | --op->speed_left; |
|
|
1847 | else |
|
|
1848 | return false; |
1855 | |
1849 | |
1856 | switch (ob->type) |
1850 | switch (ob->type) |
1857 | { |
1851 | { |
1858 | case BOW: |
1852 | case BOW: |
1859 | player_fire_bow (op, dir); |
1853 | player_fire_bow (op, dir); |
… | |
… | |
1873 | |
1867 | |
1874 | default: |
1868 | default: |
1875 | fire_misc_object (op, dir); |
1869 | fire_misc_object (op, dir); |
1876 | break; |
1870 | break; |
1877 | } |
1871 | } |
|
|
1872 | |
|
|
1873 | return true; |
1878 | } |
1874 | } |
1879 | |
1875 | |
1880 | /* find_key |
1876 | /* find_key |
1881 | * We try to find a key for the door as passed. If we find a key |
1877 | * We try to find a key for the door as passed. If we find a key |
1882 | * and successfully use it, we return the key, otherwise NULL |
1878 | * and successfully use it, we return the key, otherwise NULL |
… | |
… | |
1969 | * 0 otherwise |
1965 | * 0 otherwise |
1970 | */ |
1966 | */ |
1971 | static int |
1967 | static int |
1972 | player_attack_door (object *op, object *door) |
1968 | player_attack_door (object *op, object *door) |
1973 | { |
1969 | { |
1974 | /* If its a door, try to find a use a key. If we do destroy the door, |
1970 | /* If its a door, try to find a key. If we do destroy the door, |
1975 | * might as well return immediately as there is nothing more to do - |
1971 | * might as well return immediately as there is nothing more to do - |
1976 | * otherwise, we fall through to the rest of the code. |
1972 | * otherwise, we fall through to the rest of the code. |
1977 | */ |
1973 | */ |
1978 | object *key = find_key (op, op, door); |
1974 | object *key = find_key (op, op, door); |
1979 | |
1975 | |
1980 | /* IF we found a key, do some extra work */ |
1976 | /* If we found a key, do some extra work */ |
1981 | if (key) |
1977 | if (key) |
1982 | { |
1978 | { |
1983 | object *container = key->env; |
1979 | object *container = key->env; |
1984 | |
1980 | |
1985 | play_sound_map (op->map, op->x, op->y, SOUND_OPEN_DOOR); |
1981 | play_sound_map (op->map, op->x, op->y, SOUND_OPEN_DOOR); |
… | |
… | |
2020 | * It should keep the code cleaner. |
2016 | * It should keep the code cleaner. |
2021 | * When this is called, the players direction has been updated |
2017 | * When this is called, the players direction has been updated |
2022 | * (taking into account confusion.) The player is also actually |
2018 | * (taking into account confusion.) The player is also actually |
2023 | * going to try and move (not fire weapons). |
2019 | * going to try and move (not fire weapons). |
2024 | */ |
2020 | */ |
2025 | void |
2021 | bool |
2026 | move_player_attack (object *op, int dir) |
2022 | move_player_attack (object *op, int dir) |
2027 | { |
2023 | { |
2028 | object *tmp, *mon; |
|
|
2029 | int on_battleground; |
2024 | int on_battleground; |
2030 | maptile *m; |
|
|
2031 | |
2025 | |
2032 | sint16 nx = freearr_x[dir] + op->x; |
2026 | sint16 nx = freearr_x[dir] + op->x; |
2033 | sint16 ny = freearr_y[dir] + op->y; |
2027 | sint16 ny = freearr_y[dir] + op->y; |
2034 | |
2028 | |
2035 | on_battleground = op_on_battleground (op, 0, 0); |
2029 | on_battleground = op_on_battleground (op, 0, 0); |
|
|
2030 | |
|
|
2031 | if (out_of_map (op->map, nx, ny)) |
|
|
2032 | return false; |
|
|
2033 | |
|
|
2034 | if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op)) |
|
|
2035 | { |
|
|
2036 | --op->speed_left; |
|
|
2037 | return true; |
|
|
2038 | } |
2036 | |
2039 | |
2037 | /* If braced, or can't move to the square, and it is not out of the |
2040 | /* If braced, or can't move to the square, and it is not out of the |
2038 | * map, attack it. Note order of if statement is important - don't |
2041 | * map, attack it. Note order of if statement is important - don't |
2039 | * want to be calling move_ob if braced, because move_ob will move the |
2042 | * want to be calling move_ob if braced, because move_ob will move the |
2040 | * player. This is a pretty nasty hack, because if we could |
2043 | * player. This is a pretty nasty hack, because if we could |
2041 | * move to some space, it then means that if we are braced, we should |
2044 | * move to some space, it then means that if we are braced, we should |
2042 | * do nothing at all. As it is, if we are braced, we go through |
2045 | * do nothing at all. As it is, if we are braced, we go through |
2043 | * quite a bit of processing. However, it probably is less than what |
2046 | * quite a bit of processing. However, it probably is less than what |
2044 | * move_ob uses. |
2047 | * move_ob uses. |
2045 | */ |
2048 | */ |
2046 | if ((op->contr->braced || !move_ob (op, dir, op)) && !out_of_map (op->map, nx, ny)) |
|
|
2047 | { |
|
|
2048 | if (OUT_OF_REAL_MAP (op->map, nx, ny)) |
|
|
2049 | { |
|
|
2050 | m = op->map->xy_find (nx, ny); |
2049 | maptile *m = op->map->xy_find (nx, ny); |
2051 | if (!m) |
|
|
2052 | return; /* Don't think this should happen */ |
|
|
2053 | } |
|
|
2054 | else |
|
|
2055 | m = op->map; |
|
|
2056 | |
2050 | |
2057 | if (!(tmp = m->at (nx, ny).bot)) |
|
|
2058 | return; |
|
|
2059 | |
|
|
2060 | mon = 0; |
|
|
2061 | /* Go through all the objects, and find ones of interest. Only stop if |
2051 | /* Go through all the objects, and find ones of interest. Only stop if |
2062 | * we find a monster - that is something we know we want to attack. |
2052 | * we find a monster - that is something we know we want to attack. |
2063 | * if its a door or barrel (can roll) see if there may be monsters |
2053 | * if its a door or barrel (can roll) see if there may be monsters |
2064 | * on the space |
2054 | * on the space |
2065 | */ |
2055 | */ |
2066 | while (tmp) |
2056 | object *mon; |
2067 | { |
2057 | for (mon = m->at (nx, ny).bot; mon; mon = mon->above) |
2068 | if (tmp == op) |
2058 | { |
2069 | { |
2059 | if ((mon->flag [FLAG_ALIVE] |
2070 | tmp = tmp->above; |
2060 | || mon->type == LOCKED_DOOR |
2071 | continue; |
2061 | || mon->flag [FLAG_CAN_ROLL]) |
2072 | } |
|
|
2073 | |
|
|
2074 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
|
|
2075 | { |
|
|
2076 | mon = tmp; |
2062 | && mon != op) |
2077 | break; |
2063 | break; |
2078 | } |
2064 | } |
2079 | |
2065 | |
2080 | if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL)) |
|
|
2081 | mon = tmp; |
|
|
2082 | |
|
|
2083 | tmp = tmp->above; |
|
|
2084 | } |
|
|
2085 | |
|
|
2086 | if (!mon) /* This happens anytime the player tries to move */ |
2066 | if (!mon) /* This happens anytime the player tries to move */ |
2087 | return; /* into a wall */ |
2067 | return false; /* into a wall */ |
2088 | |
2068 | |
2089 | if (mon->head) |
|
|
2090 | mon = mon->head; |
2069 | mon = mon->head_ (); |
2091 | |
2070 | |
2092 | if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) |
2071 | if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) |
|
|
2072 | if (op->contr->weapon_sp_left > 0.f) |
2093 | if (player_attack_door (op, mon)) |
2073 | if (player_attack_door (op, mon)) |
|
|
2074 | { |
|
|
2075 | --op->contr->weapon_sp_left; |
2094 | return; |
2076 | return true; |
|
|
2077 | } |
2095 | |
2078 | |
2096 | /* The following deals with possibly attacking peaceful |
2079 | /* The following deals with possibly attacking peaceful |
2097 | * or frienddly creatures. Basically, all players are considered |
2080 | * or friendly creatures. Basically, all players are considered |
2098 | * unaggressive. If the moving player has peaceful set, then the |
2081 | * unaggressive. If the moving player has peaceful set, then the |
2099 | * object should be pushed instead of attacked. It is assumed that |
2082 | * object should be pushed instead of attacked. It is assumed that |
2100 | * if you are braced, you will not attack friends accidently, |
2083 | * if you are braced, you will not attack friends accidently, |
2101 | * and thus will not push them. |
2084 | * and thus will not push them. |
2102 | */ |
2085 | */ |
2103 | |
2086 | |
2104 | /* If the creature is a pet, push it even if the player is not |
2087 | /* If the creature is a pet, push it even if the player is not |
2105 | * peaceful. Our assumption is the creature is a pet if the |
2088 | * peaceful. Our assumption is the creature is a pet if the |
2106 | * player owns it and it is either friendly or unagressive. |
2089 | * player owns it and it is either friendly or unagressive. |
2107 | */ |
2090 | */ |
2108 | if (op->type == PLAYER |
2091 | if (op->type == PLAYER |
2109 | && ((mon->owner && mon->owner->contr |
2092 | && ((mon->owner && mon->owner->contr |
2110 | && same_party (mon->owner->contr->party, op->contr->party)) |
2093 | && same_party (mon->owner->contr->party, op->contr->party)) |
2111 | || mon->owner == op) |
2094 | || mon->owner == op) |
2112 | && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) |
2095 | && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) |
2113 | { |
2096 | { |
2114 | /* If we're braced, we don't want to switch places with it */ |
2097 | /* If we're braced, we don't want to switch places with it */ |
2115 | if (op->contr->braced) |
2098 | if (op->contr->braced) |
2116 | return; |
2099 | return false; |
|
|
2100 | |
|
|
2101 | if (op->speed_left > 0.f) |
|
|
2102 | { |
|
|
2103 | --op->speed_left; |
2117 | |
2104 | |
2118 | play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); |
2105 | play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); |
2119 | push_ob (mon, dir, op); |
2106 | push_ob (mon, dir, op); |
|
|
2107 | |
2120 | if (op->contr->tmp_invis || op->hide) |
2108 | if (op->contr->tmp_invis || op->hide) |
2121 | make_visible (op); |
2109 | make_visible (op); |
2122 | |
2110 | |
2123 | return; |
2111 | return true; |
2124 | } |
2112 | } |
|
|
2113 | else |
|
|
2114 | return false; |
|
|
2115 | } |
2125 | |
2116 | |
2126 | /* in certain circumstances, you shouldn't attack friendly |
2117 | /* in certain circumstances, you shouldn't attack friendly |
2127 | * creatures. Note that if you are braced, you can't push |
2118 | * creatures. Note that if you are braced, you can't push |
2128 | * someone, but put it inside this loop so that you won't |
2119 | * someone, but put it inside this loop so that you won't |
2129 | * attack them either. |
2120 | * attack them either. |
2130 | */ |
2121 | */ |
2131 | if ((mon->type == PLAYER || mon->enemy != op) |
2122 | if ((mon->type == PLAYER || mon->enemy != op) |
2132 | && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) |
2123 | && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) |
2133 | && ((op->contr->peaceful |
2124 | && ((op->contr->peaceful |
2134 | || (mon->type == PLAYER && mon->contr->peaceful)) |
2125 | || (mon->type == PLAYER && mon->contr->peaceful)) |
2135 | && !on_battleground)) |
2126 | && !on_battleground)) |
|
|
2127 | { |
|
|
2128 | if (op->speed_left > 0.f) |
2136 | { |
2129 | { |
|
|
2130 | --op->speed_left; |
|
|
2131 | |
2137 | if (!op->contr->braced) |
2132 | if (!op->contr->braced) |
2138 | { |
2133 | { |
2139 | play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); |
2134 | play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); |
2140 | push_ob (mon, dir, op); |
2135 | push_ob (mon, dir, op); |
2141 | } |
2136 | } |
2142 | else |
2137 | else |
2143 | new_draw_info (0, 0, op, "You withhold your attack"); |
2138 | new_draw_info (0, 0, op, "You withhold your attack"); |
2144 | |
2139 | |
2145 | if (op->contr->tmp_invis || op->hide) |
2140 | if (op->contr->tmp_invis || op->hide) |
2146 | make_visible (op); |
2141 | make_visible (op); |
2147 | } |
|
|
2148 | |
2142 | |
|
|
2143 | return true; |
|
|
2144 | } |
|
|
2145 | } |
2149 | /* If the object is a boulder or other rollable object, then |
2146 | /* If the object is a boulder or other rollable object, then |
2150 | * roll it if not braced. You can't roll it if you are braced. |
2147 | * roll it if not braced. You can't roll it if you are braced. |
2151 | */ |
2148 | */ |
2152 | else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced)) |
2149 | else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced)) |
|
|
2150 | { |
|
|
2151 | if (op->speed_left > 0.f) |
2153 | { |
2152 | { |
|
|
2153 | --op->speed_left; |
|
|
2154 | |
2154 | recursive_roll (mon, dir, op); |
2155 | recursive_roll (mon, dir, op); |
2155 | if (action_makes_visible (op)) |
2156 | if (action_makes_visible (op)) |
2156 | make_visible (op); |
2157 | make_visible (op); |
2157 | } |
|
|
2158 | |
2158 | |
|
|
2159 | return true; |
|
|
2160 | } |
|
|
2161 | } |
2159 | /* Any generic living creature. Including things like doors. |
2162 | /* Any generic living creature. Including things like doors. |
2160 | * Way it works is like this: First, it must have some hit points |
2163 | * Way it works is like this: First, it must have some hit points |
2161 | * and be living. Then, it must be one of the following: |
2164 | * and be living. Then, it must be one of the following: |
2162 | * 1) Not a player, 2) A player, but of a different party. Note |
2165 | * 1) Not a player, 2) A player, but of a different party. Note |
2163 | * that party_number -1 is no party, so attacks can still happen. |
2166 | * that party_number -1 is no party, so attacks can still happen. |
2164 | */ |
2167 | */ |
2165 | else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && |
2168 | else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && |
2166 | ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) |
2169 | ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) |
2167 | { |
2170 | { |
2168 | if (!op->contr->has_hit) |
2171 | if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS]) |
2169 | { |
2172 | { |
2170 | op->contr->has_hit = 1; |
2173 | --op->contr->weapon_sp_left; |
2171 | op->speed_left += op->contr->weapon_speed () - op->speed; |
|
|
2172 | } |
|
|
2173 | |
2174 | |
2174 | skill_attack (mon, op, 0, 0, 0); |
2175 | skill_attack (mon, op, 0, 0, 0); |
2175 | |
|
|
2176 | /* If attacking another player, that player gets automatic |
|
|
2177 | * hitback, and doesn't loose luck either. |
|
|
2178 | * Disable hitback on the battleground or if the target is |
|
|
2179 | * the wiz. |
|
|
2180 | */ |
|
|
2181 | if (mon->type == PLAYER && mon->stats.hp >= 0 && !mon->contr->has_hit && !on_battleground && !QUERY_FLAG (mon, FLAG_WIZ)) |
|
|
2182 | { |
|
|
2183 | short luck = mon->stats.luck; |
|
|
2184 | |
|
|
2185 | mon->contr->has_hit = 1; |
|
|
2186 | skill_attack (op, mon, 0, 0, 0); |
|
|
2187 | mon->stats.luck = luck; |
|
|
2188 | } |
|
|
2189 | |
2176 | |
2190 | if (action_makes_visible (op)) |
2177 | if (action_makes_visible (op)) |
2191 | make_visible (op); |
2178 | make_visible (op); |
2192 | } |
|
|
2193 | } /* if player should attack something */ |
|
|
2194 | } |
|
|
2195 | |
2179 | |
2196 | int |
2180 | return true; |
|
|
2181 | } |
|
|
2182 | } |
|
|
2183 | |
|
|
2184 | return false; |
|
|
2185 | } |
|
|
2186 | |
|
|
2187 | bool |
2197 | move_player (object *op, int dir) |
2188 | move_player (object *op, int dir) |
2198 | { |
2189 | { |
2199 | int pick; |
2190 | int pick; |
2200 | |
2191 | |
2201 | if (!op->map || op->map->in_memory != MAP_IN_MEMORY) |
2192 | if (!op->map || op->map->in_memory != MAP_IN_MEMORY) |
… | |
… | |
2215 | op->facing = dir; |
2206 | op->facing = dir; |
2216 | |
2207 | |
2217 | if (op->hide) |
2208 | if (op->hide) |
2218 | do_hidden_move (op); |
2209 | do_hidden_move (op); |
2219 | |
2210 | |
|
|
2211 | bool retval; |
|
|
2212 | |
2220 | if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) |
2213 | if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) |
2221 | /*nop */ ; |
2214 | retval = RESULT_INT (0); |
2222 | else if (op->contr->fire_on) |
2215 | else if (op->contr->fire_on) |
2223 | fire (op, dir); |
2216 | retval = fire (op, dir); |
2224 | else |
2217 | else |
2225 | { |
2218 | { |
2226 | move_player_attack (op, dir); |
2219 | retval = move_player_attack (op, dir); |
2227 | pick = check_pick (op); |
2220 | pick = check_pick (op); |
2228 | } |
2221 | } |
2229 | |
2222 | |
2230 | /* Add special check for newcs players and fire on - this way, the |
2223 | /* Add special check for newcs players and fire on - this way, the |
2231 | * server can handle repeat firing. |
2224 | * server can handle repeat firing. |
… | |
… | |
2238 | /* Update how the player looks. Use the facing, so direction may |
2231 | /* Update how the player looks. Use the facing, so direction may |
2239 | * get reset to zero. This allows for full animation capabilities |
2232 | * get reset to zero. This allows for full animation capabilities |
2240 | * for players. |
2233 | * for players. |
2241 | */ |
2234 | */ |
2242 | animate_object (op, op->facing); |
2235 | animate_object (op, op->facing); |
2243 | return 0; |
2236 | |
|
|
2237 | return retval; |
2244 | } |
2238 | } |
2245 | |
2239 | |
2246 | /* This is similar to handle_player, below, but is only used by the |
2240 | /* This is similar to handle_player, below, but is only used by the |
2247 | * new client/server stuff. |
2241 | * new client/server stuff. |
2248 | * This is sort of special, in that the new client/server actually uses |
2242 | * This is sort of special, in that the new client/server actually uses |
2249 | * the new speed values for commands. |
2243 | * the new speed values for commands. |
2250 | * |
2244 | * |
2251 | * Returns true if there are more actions we can do. |
2245 | * Returns true if there are more actions we can do. Should not do |
|
|
2246 | * many actions in a row, as that would be too unfair to other |
|
|
2247 | * players. |
2252 | */ |
2248 | */ |
2253 | int |
2249 | bool |
2254 | handle_newcs_player (object *op) |
2250 | handle_newcs_player (object *op) |
2255 | { |
2251 | { |
2256 | if (QUERY_FLAG (op, FLAG_SCARED)) |
2252 | if (QUERY_FLAG (op, FLAG_SCARED)) |
2257 | { |
2253 | { |
2258 | flee_player (op); |
2254 | if (op->speed_left > 0.f) |
2259 | |
|
|
2260 | /* If player is still scared, that is his action for this tick */ |
|
|
2261 | if (op->flag [FLAG_SCARED]) |
|
|
2262 | { |
2255 | { |
2263 | --op->speed_left; |
2256 | --op->speed_left; |
|
|
2257 | flee_player (op); |
|
|
2258 | |
2264 | return 0; |
2259 | return true; |
2265 | } |
2260 | } |
|
|
2261 | else |
|
|
2262 | return false; |
2266 | } |
2263 | } |
2267 | |
2264 | |
2268 | /* call this here - we also will call this in do_ericserver, but |
2265 | /* call this here - we also will call this in do_ericserver, but |
2269 | * the players time has been increased when doericserver has been |
2266 | * the players time has been increased when doericserver has been |
2270 | * called, so we recheck it here. |
2267 | * called, so we recheck it here. |
2271 | */ |
2268 | */ |
2272 | if (op->contr->ns->handle_command ()) |
2269 | if (op->contr->ns->handle_command ()) |
2273 | return 1; |
2270 | return true; |
2274 | |
2271 | |
2275 | if (op->speed_left > 0.f) |
|
|
2276 | { |
|
|
2277 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2272 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2278 | { |
|
|
2279 | /* All move commands take 1 tick, at least for now */ |
|
|
2280 | --op->speed_left; |
|
|
2281 | |
|
|
2282 | /* Instead of all the stuff below, let move_player take care |
|
|
2283 | * of it. Also, some of the skill stuff is only put in |
|
|
2284 | * there, as well as the confusion stuff. |
|
|
2285 | */ |
|
|
2286 | move_player (op, op->direction); |
2273 | return move_player (op, op->direction); |
2287 | |
2274 | |
2288 | return op->speed_left > 0.f; |
|
|
2289 | } |
|
|
2290 | } |
|
|
2291 | |
|
|
2292 | return 0; |
2275 | return false; |
2293 | } |
2276 | } |
2294 | |
2277 | |
2295 | int |
2278 | int |
2296 | save_life (object *op) |
2279 | save_life (object *op) |
2297 | { |
2280 | { |
… | |
… | |
3104 | /* For Hidden creatures - a chance of becoming 'unhidden' |
3087 | /* For Hidden creatures - a chance of becoming 'unhidden' |
3105 | * every time they move - as we subtract off 'invisibility' |
3088 | * every time they move - as we subtract off 'invisibility' |
3106 | * AND, for players, if they move into a ridiculously unhideable |
3089 | * AND, for players, if they move into a ridiculously unhideable |
3107 | * spot (surrounded by clear terrain in broad daylight). -b.t. |
3090 | * spot (surrounded by clear terrain in broad daylight). -b.t. |
3108 | */ |
3091 | */ |
3109 | |
|
|
3110 | void |
3092 | void |
3111 | do_hidden_move (object *op) |
3093 | do_hidden_move (object *op) |
3112 | { |
3094 | { |
3113 | int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); |
3095 | int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); |
3114 | object *skop; |
3096 | object *skop; |