… | |
… | |
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 | //+GPL |
|
|
26 | |
25 | #include <global.h> |
27 | #include <global.h> |
26 | #include <sproto.h> |
28 | #include <sproto.h> |
27 | #include <sounds.h> |
29 | #include <sounds.h> |
28 | #include <living.h> |
30 | #include <living.h> |
29 | #include <object.h> |
31 | #include <object.h> |
… | |
… | |
168 | observe = viewpoint = ob; |
170 | observe = viewpoint = ob; |
169 | |
171 | |
170 | deactivate (); |
172 | deactivate (); |
171 | } |
173 | } |
172 | |
174 | |
|
|
175 | //-GPL |
|
|
176 | |
173 | // the need for this function can be explained |
177 | // the need for this function can be explained |
174 | // by load_object not returning the object |
178 | // by load_object not returning the object |
175 | void |
179 | void |
176 | player::set_object (object *op) |
180 | player::set_object (object *op) |
177 | { |
181 | { |
… | |
… | |
223 | { |
227 | { |
224 | viewpoint = op ? op : (object *)observe; |
228 | viewpoint = op ? op : (object *)observe; |
225 | do_los = 1; |
229 | do_los = 1; |
226 | } |
230 | } |
227 | |
231 | |
|
|
232 | //+GPL |
|
|
233 | |
228 | player::player () |
234 | player::player () |
229 | { |
235 | { |
230 | /* There are some elements we want initialised to non zero value - |
236 | /* There are some elements we want initialised to non zero value - |
231 | * we deal with that below this point. |
237 | * we deal with that below this point. |
232 | */ |
238 | */ |
… | |
… | |
267 | { |
273 | { |
268 | /* Clear item stack */ |
274 | /* Clear item stack */ |
269 | free (stack_items); |
275 | free (stack_items); |
270 | } |
276 | } |
271 | |
277 | |
|
|
278 | /* |
|
|
279 | * get_player_archetype() return next player archetype from archetype |
|
|
280 | * list. Not very efficient routine, but used only creating new players. |
|
|
281 | * Note: there MUST be at least one player archetype! |
|
|
282 | */ |
|
|
283 | static archetype * |
|
|
284 | get_player_archetype (archetype *at) |
|
|
285 | { |
|
|
286 | // archetypes could have been reloaded |
|
|
287 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
288 | |
|
|
289 | if (!nat) |
|
|
290 | return at; |
|
|
291 | |
|
|
292 | archvec::iterator i = archetypes.find (nat); |
|
|
293 | |
|
|
294 | for (;;) |
|
|
295 | { |
|
|
296 | if (++i == archetypes.end ()) |
|
|
297 | i = archetypes.begin (); |
|
|
298 | else if (*i == at) |
|
|
299 | cleanup ("not a single player archetype found"); |
|
|
300 | |
|
|
301 | if ((*i)->type == PLAYER) |
|
|
302 | return *i; |
|
|
303 | } |
|
|
304 | } |
|
|
305 | |
272 | /* Tries to add player on the connection passed in ns. |
306 | /* Tries to add player on the connection passed in ns. |
273 | * All we can really get in this is some settings like host and display |
307 | * All we can really get in this is some settings like host and display |
274 | * mode. |
308 | * mode. |
275 | */ |
309 | */ |
276 | player * |
310 | player * |
… | |
… | |
285 | pl->ob->run_away = 25; /* Then we panick... */ |
319 | pl->ob->run_away = 25; /* Then we panick... */ |
286 | |
320 | |
287 | set_first_map (pl->ob); |
321 | set_first_map (pl->ob); |
288 | |
322 | |
289 | return pl; |
323 | return pl; |
290 | } |
|
|
291 | |
|
|
292 | /* |
|
|
293 | * get_player_archetype() return next player archetype from archetype |
|
|
294 | * list. Not very efficient routine, but used only creating new players. |
|
|
295 | * Note: there MUST be at least one player archetype! |
|
|
296 | */ |
|
|
297 | archetype * |
|
|
298 | get_player_archetype (archetype *at) |
|
|
299 | { |
|
|
300 | // archetypes could have been reloaded |
|
|
301 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
302 | |
|
|
303 | if (!nat) |
|
|
304 | return at; |
|
|
305 | |
|
|
306 | archvec::iterator i = archetypes.find (nat); |
|
|
307 | |
|
|
308 | for (;;) |
|
|
309 | { |
|
|
310 | if (++i == archetypes.end ()) |
|
|
311 | i = archetypes.begin (); |
|
|
312 | else if (*i == at) |
|
|
313 | cleanup ("not a single player archetype found"); |
|
|
314 | |
|
|
315 | if ((*i)->type == PLAYER) |
|
|
316 | return *i; |
|
|
317 | } |
|
|
318 | } |
324 | } |
319 | |
325 | |
320 | object * |
326 | object * |
321 | get_nearest_player (object *mon) |
327 | get_nearest_player (object *mon) |
322 | { |
328 | { |
… | |
… | |
738 | player::chargen_race_done () |
744 | player::chargen_race_done () |
739 | { |
745 | { |
740 | /* this must before then initial items are given */ |
746 | /* this must before then initial items are given */ |
741 | esrv_new_player (ob->contr); |
747 | esrv_new_player (ob->contr); |
742 | |
748 | |
743 | treasurelist *tl = treasurelist::find ("starting_wealth"); |
749 | treasurelist *tl = treasurelist::find (shstr_starting_wealth); |
744 | if (tl) |
750 | if (tl) |
745 | create_treasure (tl, ob, 0, 0, 0); |
751 | create_treasure (tl, ob, 0, 0, 0); |
746 | |
752 | |
747 | INVOKE_PLAYER (BIRTH, ob->contr); |
753 | INVOKE_PLAYER (BIRTH, ob->contr); |
748 | INVOKE_PLAYER (LOGIN, ob->contr); |
754 | INVOKE_PLAYER (LOGIN, ob->contr); |
… | |
… | |
801 | ob->stats.hp = ob->stats.maxhp; |
807 | ob->stats.hp = ob->stats.maxhp; |
802 | ob->stats.sp = ob->stats.maxsp; |
808 | ob->stats.sp = ob->stats.maxsp; |
803 | ob->stats.grace = 0; |
809 | ob->stats.grace = 0; |
804 | } |
810 | } |
805 | |
811 | |
806 | void |
812 | static void |
807 | flee_player (object *op) |
813 | flee_player (object *op) |
808 | { |
814 | { |
809 | int dir, diff; |
815 | int dir, diff; |
810 | rv_vector rv; |
816 | rv_vector rv; |
811 | |
817 | |
… | |
… | |
897 | if (op->contr->mode & PU_DEBUG) |
903 | if (op->contr->mode & PU_DEBUG) |
898 | { |
904 | { |
899 | /* some debugging code to figure out item information */ |
905 | /* some debugging code to figure out item information */ |
900 | const char *str = tmp->name |
906 | const char *str = tmp->name |
901 | ? format ("item name: %s item type: %d weight/value: %d", |
907 | ? format ("item name: %s item type: %d weight/value: %d", |
902 | &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))) |
908 | &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1)))) |
903 | : format ("item name: %s item type: %d weight/value: %d", |
909 | : format ("item name: %s item type: %d weight/value: %d", |
904 | &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
910 | &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1)))); |
905 | |
911 | |
906 | new_draw_info (NDI_UNIQUE, 0, op, str); |
912 | new_draw_info (NDI_UNIQUE, 0, op, str); |
907 | } |
913 | } |
908 | |
914 | |
909 | if (op->contr->mode & PU_INHIBIT) |
915 | if (op->contr->mode & PU_INHIBIT) |
… | |
… | |
1140 | fprintf (stderr, "%s", tmp->name); |
1146 | fprintf (stderr, "%s", tmp->name); |
1141 | } |
1147 | } |
1142 | else |
1148 | else |
1143 | fprintf (stderr, "%s", tmp->arch->archname); |
1149 | fprintf (stderr, "%s", tmp->arch->archname); |
1144 | fprintf (stderr, ",%d] = ", tmp->type); |
1150 | fprintf (stderr, ",%d] = ", tmp->type); |
1145 | fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1151 | fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1)))); |
1146 | #endif |
1152 | #endif |
1147 | CHK_PICK_PICKUP; |
1153 | CHK_PICK_PICKUP; |
1148 | continue; |
1154 | continue; |
1149 | } |
1155 | } |
1150 | } /* the new pickup model */ |
1156 | } /* the new pickup model */ |
1151 | } |
1157 | } |
1152 | |
1158 | |
1153 | return !stop; |
1159 | return !stop; |
1154 | } |
1160 | } |
1155 | |
1161 | |
|
|
1162 | /* routine for both players and monsters. We call this when |
|
|
1163 | * there is a possibility for our action distrubing our hiding |
|
|
1164 | * place or invisiblity spell. Artefact invisiblity causes |
|
|
1165 | * "noise" instead. If we arent invisible to begin with, we |
|
|
1166 | * return 0. |
|
|
1167 | */ |
|
|
1168 | static int |
|
|
1169 | action_makes_visible (object *op) |
|
|
1170 | { |
|
|
1171 | if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) |
|
|
1172 | { |
|
|
1173 | if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) |
|
|
1174 | { |
|
|
1175 | // artefact invisibility is permanent, but we still make noise |
|
|
1176 | // this is important for game-balance. |
|
|
1177 | if (op->contr) |
|
|
1178 | op->make_noise (); |
|
|
1179 | |
|
|
1180 | return 0; |
|
|
1181 | } |
|
|
1182 | |
|
|
1183 | if (op->contr && op->contr->tmp_invis == 0) |
|
|
1184 | return 0; |
|
|
1185 | |
|
|
1186 | /* If monsters, they should become visible */ |
|
|
1187 | if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis)) |
|
|
1188 | { |
|
|
1189 | new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible"); |
|
|
1190 | return 1; |
|
|
1191 | } |
|
|
1192 | } |
|
|
1193 | |
|
|
1194 | return 0; |
|
|
1195 | } |
|
|
1196 | |
1156 | /* |
1197 | /* |
1157 | * Find an arrow in the inventory and after that |
1198 | * Find an arrow in the inventory and after that |
1158 | * in the right type container (quiver). Pointer to the |
1199 | * in the right type container (quiver). Pointer to the |
1159 | * found object is returned. |
1200 | * found object is returned. |
1160 | */ |
1201 | */ |
1161 | object * |
1202 | static object * |
1162 | find_arrow (object *op, const char *type) |
1203 | find_arrow (object *op, const char *type) |
1163 | { |
1204 | { |
1164 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1205 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1165 | if (tmp->type == ARROW && !strcmp (&tmp->race, type)) |
1206 | if (tmp->type == ARROW && !strcmp (&tmp->race, type)) |
1166 | return splay (tmp); |
1207 | return splay (tmp); |
… | |
… | |
1180 | * Similar to find_arrow, but looks for (roughly) the best arrow to use |
1221 | * Similar to find_arrow, but looks for (roughly) the best arrow to use |
1181 | * against the target. A full test is not performed, simply a basic test |
1222 | * against the target. A full test is not performed, simply a basic test |
1182 | * of resistances. The archer is making a quick guess at what he sees down |
1223 | * of resistances. The archer is making a quick guess at what he sees down |
1183 | * the hall. Failing that it does it's best to pick the highest plus arrow. |
1224 | * the hall. Failing that it does it's best to pick the highest plus arrow. |
1184 | */ |
1225 | */ |
1185 | object * |
1226 | static object * |
1186 | find_better_arrow (object *op, object *target, shstr_cmp type, int *better) |
1227 | find_better_arrow (object *op, object *target, shstr_cmp type, int *better) |
1187 | { |
1228 | { |
1188 | object *tmp = NULL, *arrow, *ntmp; |
1229 | object *tmp = NULL, *arrow, *ntmp; |
1189 | int attacknum, attacktype, betterby = 0, i; |
1230 | int attacknum, attacktype, betterby = 0, i; |
1190 | |
1231 | |
… | |
… | |
1259 | * find_better_arrow to find a decent arrow to use. |
1300 | * find_better_arrow to find a decent arrow to use. |
1260 | * op = the shooter |
1301 | * op = the shooter |
1261 | * type = bow->race |
1302 | * type = bow->race |
1262 | * dir = fire direction |
1303 | * dir = fire direction |
1263 | */ |
1304 | */ |
1264 | object * |
1305 | static object * |
1265 | pick_arrow_target (object *op, shstr_cmp type, int dir) |
1306 | pick_arrow_target (object *op, shstr_cmp type, int dir) |
1266 | { |
1307 | { |
1267 | object *tmp = NULL; |
1308 | object *tmp = NULL; |
1268 | maptile *m; |
1309 | maptile *m; |
1269 | int i, mflags, found, number; |
1310 | int i, mflags, found, number; |
… | |
… | |
1484 | * but monsters can't. Putting that code here |
1525 | * but monsters can't. Putting that code here |
1485 | * makes the fire_bow code much cleaner. |
1526 | * makes the fire_bow code much cleaner. |
1486 | * this function should only be called if 'op' is a player, |
1527 | * this function should only be called if 'op' is a player, |
1487 | * hence the function name. |
1528 | * hence the function name. |
1488 | */ |
1529 | */ |
1489 | int |
1530 | static int |
1490 | player_fire_bow (object *op, int dir) |
1531 | player_fire_bow (object *op, int dir) |
1491 | { |
1532 | { |
1492 | int ret; |
1533 | int ret; |
1493 | |
1534 | |
1494 | if (op->contr->bowtype == bow_bestarrow) |
1535 | if (op->contr->bowtype == bow_bestarrow) |
… | |
… | |
1522 | } |
1563 | } |
1523 | |
1564 | |
1524 | /* Fires a misc (wand/rod/horn) object in 'dir'. |
1565 | /* Fires a misc (wand/rod/horn) object in 'dir'. |
1525 | * Broken apart from 'fire' to keep it more readable. |
1566 | * Broken apart from 'fire' to keep it more readable. |
1526 | */ |
1567 | */ |
1527 | void |
1568 | static void |
1528 | fire_misc_object (object *op, int dir) |
1569 | fire_misc_object (object *op, int dir) |
1529 | { |
1570 | { |
1530 | object *item = op->contr->ranged_ob; |
1571 | object *item = op->contr->ranged_ob; |
1531 | |
1572 | |
1532 | if (!item) |
1573 | if (!item) |
… | |
… | |
1554 | return; |
1595 | return; |
1555 | } |
1596 | } |
1556 | } |
1597 | } |
1557 | else if (item->type == ROD || item->type == HORN) |
1598 | else if (item->type == ROD || item->type == HORN) |
1558 | { |
1599 | { |
1559 | sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace); |
1600 | sint16 spell_sp = max (item->inv->stats.sp, item->inv->stats.grace); |
1560 | |
1601 | |
1561 | // using the maximum of the rods charge allows at least one spell cast |
1602 | // using the maximum of the rods charge allows at least one spell cast |
1562 | // for a rod or horn, this fixes some broken rods. |
1603 | // for a rod or horn, this fixes some broken rods. |
1563 | if (item->stats.hp < MIN (spell_sp, item->stats.maxhp)) |
1604 | if (item->stats.hp < min (spell_sp, item->stats.maxhp)) |
1564 | { |
1605 | { |
1565 | op->contr->play_sound (sound_find ("wand_poof")); |
1606 | op->contr->play_sound (sound_find ("wand_poof")); |
1566 | |
1607 | |
1567 | if (item->type == ROD) |
1608 | if (item->type == ROD) |
1568 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); |
1609 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); |
… | |
… | |
1655 | } |
1696 | } |
1656 | |
1697 | |
1657 | return true; |
1698 | return true; |
1658 | } |
1699 | } |
1659 | |
1700 | |
1660 | /* find_key |
1701 | static object * |
1661 | * We try to find a key for the door as passed. If we find a key |
|
|
1662 | * and successfully use it, we return the key, otherwise NULL |
|
|
1663 | * This function merges both normal and locked door, since the logic |
|
|
1664 | * for both is the same - just the specific key is different. |
|
|
1665 | * pl is the player, |
|
|
1666 | * inv is the objects inventory to searched |
|
|
1667 | * door is the door we are trying to match against. |
|
|
1668 | * This function can be called recursively to search containers. |
|
|
1669 | */ |
|
|
1670 | object * |
|
|
1671 | find_key (object *pl, object *container, object *door) |
1702 | find_key_ (object *pl, object *container, object *door) |
1672 | { |
1703 | { |
1673 | object *tmp, *key; |
1704 | object *tmp, *key; |
1674 | |
1705 | |
1675 | /* Should not happen, but sanity checking is never bad */ |
1706 | /* Should not happen, but sanity checking is never bad */ |
1676 | if (!container->inv) |
1707 | if (!container->inv) |
… | |
… | |
1697 | if (!tmp) |
1728 | if (!tmp) |
1698 | { |
1729 | { |
1699 | for (tmp = container->inv; tmp; tmp = tmp->below) |
1730 | for (tmp = container->inv; tmp; tmp = tmp->below) |
1700 | /* No reason to search empty containers */ |
1731 | /* No reason to search empty containers */ |
1701 | if (tmp->type == CONTAINER && tmp->inv) |
1732 | if (tmp->type == CONTAINER && tmp->inv) |
1702 | if ((key = find_key (pl, tmp, door))) |
1733 | if ((key = find_key_ (pl, tmp, door))) |
1703 | return key; |
1734 | return key; |
1704 | |
1735 | |
1705 | if (!tmp) |
1736 | if (!tmp) |
1706 | return 0; |
1737 | return 0; |
1707 | } |
1738 | } |
… | |
… | |
1739 | } |
1770 | } |
1740 | |
1771 | |
1741 | return tmp; |
1772 | return tmp; |
1742 | } |
1773 | } |
1743 | |
1774 | |
|
|
1775 | /* find_key |
|
|
1776 | * We try to find a key for the door as passed. If we find a key |
|
|
1777 | * and successfully use it, we return the key, otherwise NULL |
|
|
1778 | * This function merges both normal and locked door, since the logic |
|
|
1779 | * for both is the same - just the specific key is different. |
|
|
1780 | * pl is the player, |
|
|
1781 | * inv is the objects inventory to searched |
|
|
1782 | * door is the door we are trying to match against. |
|
|
1783 | * This function can be called recursively to search containers. |
|
|
1784 | */ |
|
|
1785 | object * |
|
|
1786 | find_key (object *pl, object *container, object *door) |
|
|
1787 | { |
|
|
1788 | if (door->slaying && is_match_expr (door->slaying)) |
|
|
1789 | { |
|
|
1790 | // for match expressions, we try to find the key by applying the match |
|
|
1791 | // to the op itself, which is supposed to find the "key", instead |
|
|
1792 | // of searching through containers ourselves. |
|
|
1793 | |
|
|
1794 | return match_one (door->slaying, container, door, pl, pl); |
|
|
1795 | } |
|
|
1796 | else |
|
|
1797 | return find_key_ (pl, container, door); |
|
|
1798 | } |
|
|
1799 | |
1744 | /* moved door processing out of move_player_attack. |
1800 | /* moved door processing out of move_player_attack. |
1745 | * returns 1 if player has opened the door with a key |
1801 | * returns 1 if player has opened the door with a key |
1746 | * such that the caller should not do anything more, |
1802 | * such that the caller should not do anything more, |
1747 | * 0 otherwise |
1803 | * 0 otherwise |
1748 | */ |
1804 | */ |
… | |
… | |
1751 | { |
1807 | { |
1752 | /* If its a door, try to find a key. If we do destroy the door, |
1808 | /* If its a door, try to find a key. If we do destroy the door, |
1753 | * might as well return immediately as there is nothing more to do - |
1809 | * might as well return immediately as there is nothing more to do - |
1754 | * otherwise, we fall through to the rest of the code. |
1810 | * otherwise, we fall through to the rest of the code. |
1755 | */ |
1811 | */ |
1756 | object *key; |
|
|
1757 | |
|
|
1758 | if (door->slaying && is_match_expr (door->slaying)) |
|
|
1759 | { |
|
|
1760 | // for match expressions, we try to find the key by applying the match |
|
|
1761 | // to the op itself, which is supposed to find the "key", instead |
|
|
1762 | // of searching through containers ourselves. |
|
|
1763 | |
|
|
1764 | key = match_one (door->slaying, op, door, op, op); |
|
|
1765 | } |
|
|
1766 | else |
|
|
1767 | key = find_key (op, op, door); |
1812 | object *key = find_key (op, op, door); |
1768 | |
1813 | |
1769 | /* If we found a key, do some extra work */ |
1814 | /* If we found a key, do some extra work */ |
1770 | if (key) |
1815 | if (key) |
1771 | { |
1816 | { |
1772 | object *container = key->env; |
1817 | object *container = key->env; |
… | |
… | |
1973 | } |
2018 | } |
1974 | |
2019 | |
1975 | bool |
2020 | bool |
1976 | move_player (object *op, int dir) |
2021 | move_player (object *op, int dir) |
1977 | { |
2022 | { |
1978 | int pick; |
|
|
1979 | |
|
|
1980 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
2023 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
1981 | return 0; |
2024 | return 0; |
1982 | |
2025 | |
1983 | /* Sanity check: make sure dir is valid */ |
2026 | /* Sanity check: make sure dir is valid */ |
1984 | if ((dir < 0) || (dir >= 9)) |
2027 | if ((dir < 0) || (dir >= 9)) |
… | |
… | |
1995 | |
2038 | |
1996 | if (op->flag [FLAG_HIDDEN]) |
2039 | if (op->flag [FLAG_HIDDEN]) |
1997 | do_hidden_move (op); |
2040 | do_hidden_move (op); |
1998 | |
2041 | |
1999 | bool retval; |
2042 | bool retval; |
|
|
2043 | int pick = 0; |
2000 | |
2044 | |
2001 | if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) |
2045 | if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) |
2002 | retval = RESULT_INT (0); |
2046 | retval = RESULT_INT (0); |
2003 | else if (op->contr->fire_on) |
2047 | else if (op->contr->fire_on) |
2004 | retval = fire (op, dir); |
2048 | retval = fire (op, dir); |
… | |
… | |
2061 | return move_player (op, op->direction); |
2105 | return move_player (op, op->direction); |
2062 | |
2106 | |
2063 | return false; |
2107 | return false; |
2064 | } |
2108 | } |
2065 | |
2109 | |
2066 | int |
2110 | static int |
2067 | save_life (object *op) |
2111 | save_life (object *op) |
2068 | { |
2112 | { |
2069 | if (!QUERY_FLAG (op, FLAG_LIFESAVE)) |
2113 | if (!QUERY_FLAG (op, FLAG_LIFESAVE)) |
2070 | return 0; |
2114 | return 0; |
2071 | |
2115 | |
… | |
… | |
2118 | void |
2162 | void |
2119 | object::drop_unpaid_items () |
2163 | object::drop_unpaid_items () |
2120 | { |
2164 | { |
2121 | if (!flag [FLAG_REMOVED]) |
2165 | if (!flag [FLAG_REMOVED]) |
2122 | ::drop_unpaid_items (inv, this); |
2166 | ::drop_unpaid_items (inv, this); |
2123 | } |
|
|
2124 | |
|
|
2125 | /* |
|
|
2126 | * Returns pointer a static string containing gravestone text |
|
|
2127 | * Moved from apply.c to player.c - player.c is what |
|
|
2128 | * actually uses this function. player.c may not be quite the |
|
|
2129 | * best, a misc file for object actions is probably better, |
|
|
2130 | * but there isn't one in the server directory. |
|
|
2131 | */ |
|
|
2132 | const char * |
|
|
2133 | gravestone_text (object *op) |
|
|
2134 | { |
|
|
2135 | static dynbuf_text buf; |
|
|
2136 | |
|
|
2137 | buf << "---- R.I.P. ----\n\n" |
|
|
2138 | << op->name; |
|
|
2139 | |
|
|
2140 | if (op->type == PLAYER) |
|
|
2141 | buf << " the " << op->contr->title; |
|
|
2142 | |
|
|
2143 | buf << "\n\n"; |
|
|
2144 | |
|
|
2145 | buf << "who was level "; |
|
|
2146 | buf << (sint32)op->level << "\n\n" // OO breakdown |
|
|
2147 | << " when " << (op->contr ? "killed" : "died") << "\n\n"; |
|
|
2148 | |
|
|
2149 | if (op->type == PLAYER) |
|
|
2150 | buf << "by " << op->contr->killer_name () << ".\n\n"; |
|
|
2151 | |
|
|
2152 | { |
|
|
2153 | static char buf2[128]; |
|
|
2154 | time_t now = time (NULL); |
|
|
2155 | strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now)); |
|
|
2156 | buf << buf2; |
|
|
2157 | } |
|
|
2158 | |
|
|
2159 | return buf; |
|
|
2160 | } |
2167 | } |
2161 | |
2168 | |
2162 | void |
2169 | void |
2163 | do_some_living (object *op) |
2170 | do_some_living (object *op) |
2164 | { |
2171 | { |
… | |
… | |
2419 | return; |
2426 | return; |
2420 | |
2427 | |
2421 | dynbuf_text deathtab; |
2428 | dynbuf_text deathtab; |
2422 | |
2429 | |
2423 | /* restore player */ |
2430 | /* restore player */ |
2424 | at = archetype::find ("poisoning"); |
2431 | at = archetype::find (shstr_poisoning); |
2425 | if (object *tmp = present_arch_in_ob (at, op)) |
2432 | if (object *tmp = present_arch_in_ob (at, op)) |
2426 | { |
2433 | { |
2427 | tmp->destroy (); |
2434 | tmp->destroy (); |
2428 | deathtab << "Your body feels cleansed...\r"; |
2435 | deathtab << "Your body feels cleansed...\r"; |
2429 | } |
2436 | } |
2430 | |
2437 | |
2431 | at = archetype::find ("confusion"); |
2438 | at = archetype::find (shstr_confusion); |
2432 | if (object *tmp = present_arch_in_ob (at, op)) |
2439 | if (object *tmp = present_arch_in_ob (at, op)) |
2433 | { |
2440 | { |
2434 | tmp->destroy (); |
2441 | tmp->destroy (); |
2435 | deathtab << "Your mind feels clearer...\r"; |
2442 | deathtab << "Your mind feels clearer...\r"; |
2436 | } |
2443 | } |
… | |
… | |
2463 | if (op_on_battleground (op, &x, &y)) |
2470 | if (op_on_battleground (op, &x, &y)) |
2464 | { |
2471 | { |
2465 | deathtab << "You almost died in combat, but local medics have saved your life...\r"; |
2472 | deathtab << "You almost died in combat, but local medics have saved your life...\r"; |
2466 | |
2473 | |
2467 | /* create a bodypart-trophy to make the winner happy */ |
2474 | /* create a bodypart-trophy to make the winner happy */ |
2468 | if (object *tmp = arch_to_object (archetype::find ("finger"))) |
2475 | if (object *tmp = arch_to_object (archetype::find (shstr_finger))) |
2469 | { |
2476 | { |
2470 | tmp->name = format ("%s's finger" , &op->name); |
2477 | tmp->name = format ("%s's finger" , &op->name); |
2471 | tmp->name_pl = format ("%s's fingers", &op->name); |
2478 | tmp->name_pl = format ("%s's fingers", &op->name); |
2472 | tmp->msg = format ( |
2479 | tmp->msg = format ( |
2473 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
2480 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
… | |
… | |
2548 | lost_a_stat = 1; |
2555 | lost_a_stat = 1; |
2549 | } |
2556 | } |
2550 | else |
2557 | else |
2551 | { |
2558 | { |
2552 | /* deplete a stat */ |
2559 | /* deplete a stat */ |
2553 | archetype *deparch = archetype::find ("depletion"); |
2560 | archetype *deparch = archetype::find (shstr_depletion); |
2554 | object *dep; |
2561 | object *dep; |
2555 | |
2562 | |
2556 | dep = present_arch_in_ob (deparch, op); |
2563 | dep = present_arch_in_ob (deparch, op); |
2557 | if (!dep) |
2564 | if (!dep) |
2558 | { |
2565 | { |
… | |
… | |
2630 | #endif |
2637 | #endif |
2631 | |
2638 | |
2632 | /* Put a gravestone up where the character 'almost' died. List the |
2639 | /* Put a gravestone up where the character 'almost' died. List the |
2633 | * exp loss on the stone. |
2640 | * exp loss on the stone. |
2634 | */ |
2641 | */ |
2635 | tmp = arch_to_object (archetype::find ("gravestone")); |
2642 | tmp = arch_to_object (archetype::find (shstr_gravestone)); |
2636 | tmp->name = format ("%s's gravestone", &op->name); |
2643 | tmp->name = format ("%s's gravestone", &op->name); |
2637 | tmp->name_pl = format ("%s's gravestones", &op->name); |
2644 | tmp->name_pl = format ("%s's gravestones", &op->name); |
2638 | tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", |
2645 | tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", |
2639 | &op->name, op->contr->title, op->contr->killer_name ()); |
2646 | &op->name, op->contr->title, op->contr->killer_name ()); |
2640 | tmp->x = op->x, tmp->y = op->y; |
2647 | tmp->x = op->x, tmp->y = op->y; |
… | |
… | |
2695 | } |
2702 | } |
2696 | |
2703 | |
2697 | op->contr->infobox (MSG_CHANNEL ("death"), deathtab); |
2704 | op->contr->infobox (MSG_CHANNEL ("death"), deathtab); |
2698 | } |
2705 | } |
2699 | |
2706 | |
2700 | void |
2707 | static void |
2701 | loot_object (object *op) |
2708 | loot_object (object *op) |
2702 | { /* Grab and destroy some treasure */ |
2709 | { /* Grab and destroy some treasure */ |
2703 | object *tmp, *tmp2, *next; |
2710 | object *tmp, *tmp2, *next; |
2704 | |
2711 | |
2705 | op->close_container (); /* close open sack first */ |
2712 | op->close_container (); /* close open sack first */ |
… | |
… | |
3007 | } |
3014 | } |
3008 | |
3015 | |
3009 | return 0; |
3016 | return 0; |
3010 | } |
3017 | } |
3011 | |
3018 | |
3012 | /* routine for both players and monsters. We call this when |
|
|
3013 | * there is a possibility for our action distrubing our hiding |
|
|
3014 | * place or invisiblity spell. Artefact invisiblity causes |
|
|
3015 | * "noise" instead. If we arent invisible to begin with, we |
|
|
3016 | * return 0. |
|
|
3017 | */ |
|
|
3018 | int |
|
|
3019 | action_makes_visible (object *op) |
|
|
3020 | { |
|
|
3021 | if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) |
|
|
3022 | { |
|
|
3023 | if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) |
|
|
3024 | { |
|
|
3025 | // artefact invisibility is permanent, but we still make noise |
|
|
3026 | // this is important for game-balance. |
|
|
3027 | if (op->contr) |
|
|
3028 | op->make_noise (); |
|
|
3029 | |
|
|
3030 | return 0; |
|
|
3031 | } |
|
|
3032 | |
|
|
3033 | if (op->contr && op->contr->tmp_invis == 0) |
|
|
3034 | return 0; |
|
|
3035 | |
|
|
3036 | /* If monsters, they should become visible */ |
|
|
3037 | if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis)) |
|
|
3038 | { |
|
|
3039 | new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible"); |
|
|
3040 | return 1; |
|
|
3041 | } |
|
|
3042 | } |
|
|
3043 | |
|
|
3044 | return 0; |
|
|
3045 | } |
|
|
3046 | |
|
|
3047 | /* op_on_battleground - checks if the given object op (usually |
3019 | /* op_on_battleground - checks if the given object op (usually |
3048 | * a player) is standing on a valid battleground-tile, |
3020 | * a player) is standing on a valid battleground-tile, |
3049 | * function returns TRUE/FALSE. If true x, y returns the battleground |
3021 | * function returns TRUE/FALSE. If true x, y returns the battleground |
3050 | * -exit-coord. (and if x, y not NULL) |
3022 | * -exit-coord. (and if x, y not NULL) |
3051 | * 19 March 2005 - josh@woosworld.net modifed to check if the battleground also has slaying, maxhp, and maxsp set |
3023 | * 19 March 2005 - josh@woosworld.net modifed to check if the battleground also has slaying, maxhp, and maxsp set |
… | |
… | |
3271 | |
3243 | |
3272 | if (pl->ranged_ob == ob) |
3244 | if (pl->ranged_ob == ob) |
3273 | pl->ranged_ob = 0; |
3245 | pl->ranged_ob = 0; |
3274 | } |
3246 | } |
3275 | |
3247 | |
|
|
3248 | //-GPL |
|
|
3249 | |
3276 | sint8 |
3250 | sint8 |
3277 | player::darkness_at (maptile *map, int x, int y) const |
3251 | player::darkness_at (maptile *map, int x, int y) const |
3278 | { |
3252 | { |
3279 | if (!ns) |
3253 | if (!ns) |
3280 | return LOS_BLOCKED; |
3254 | return LOS_BLOCKED; |