ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/player.C
(Generate patch)

Comparing deliantra/server/server/player.C (file contents):
Revision 1.233 by root, Mon Oct 12 14:00:59 2009 UTC vs.
Revision 1.243 by root, Sat Nov 7 18:30:06 2009 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 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
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>
33#include <algorithm> 35#include <algorithm>
34#include <functional> 36#include <functional>
35 37
36playervec players; 38playervec players;
37 39
38void
39display_motd (const object *op)
40{
41 char buf[MAX_BUF];
42 char motd[HUGE_BUF];
43 FILE *fp;
44 int comp;
45 int size;
46
47 sprintf (buf, "%s/%s", settings.confdir, settings.motd);
48 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
49 return;
50
51 motd[0] = '\0';
52 size = 0;
53
54 while (fgets (buf, MAX_BUF, fp))
55 {
56 if (*buf == '#')
57 continue;
58
59 strncat (motd + size, buf, HUGE_BUF - size);
60 size += strlen (buf);
61 }
62
63 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL);
64 close_and_delete (fp, comp);
65}
66
67void
68send_rules (const object *op)
69{
70 char buf[MAX_BUF];
71 char rules[HUGE_BUF];
72 FILE *fp;
73 int comp;
74 int size;
75
76 sprintf (buf, "%s/%s", settings.confdir, settings.rules);
77 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
78 return;
79
80 rules[0] = '\0';
81 size = 0;
82
83 while (fgets (buf, MAX_BUF, fp))
84 {
85 if (*buf == '#')
86 continue;
87
88 if (size + strlen (buf) >= HUGE_BUF)
89 {
90 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF);
91 break;
92 }
93
94 strncat (rules + size, buf, HUGE_BUF - size);
95 size += strlen (buf);
96 }
97
98 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL);
99 close_and_delete (fp, comp);
100}
101
102void
103send_news (const object *op)
104{
105 char buf[MAX_BUF];
106 char news[HUGE_BUF];
107 char subject[MAX_BUF];
108 FILE *fp;
109 int comp;
110 int size;
111
112 sprintf (buf, "%s/%s", settings.confdir, settings.news);
113 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
114 return;
115
116 news[0] = '\0';
117 subject[0] = '\0';
118 size = 0;
119
120 while (fgets (buf, MAX_BUF, fp))
121 {
122 if (*buf == '#')
123 continue;
124
125 if (*buf == '%')
126 { /* send one news */
127 if (size > 0)
128 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op,
129 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS,
130 "INFORMATION: %s\n%s", (char *)"%s\n%s",
131 subject, news); /*send previously read news */
132
133 strcpy (subject, buf + 1);
134 strip_endline (subject);
135 size = 0;
136 news[0] = '\0';
137 }
138 else
139 {
140 if (size + strlen (buf) >= HUGE_BUF)
141 {
142 LOG (llevDebug, "Warning, one news item has size > %d bytes.\n", HUGE_BUF);
143 break;
144 }
145 strncat (news + size, buf, HUGE_BUF - size);
146 size += strlen (buf);
147 }
148 }
149
150 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op,
151 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s\n", (char *)"%s\n%s", subject, news);
152 close_and_delete (fp, comp);
153}
154
155/* This loads the first map an puts the player on it. */ 40/* This loads the first map an puts the player on it. */
156static void 41static void
157set_first_map (object *op) 42set_first_map (object *op)
158{ 43{
159 op->contr->maplevel = first_map_path; 44 op->contr->maplevel = first_map_path;
253 esrv_send_inventory (ob, ob); 138 esrv_send_inventory (ob, ob);
254 esrv_add_spells (this, 0); 139 esrv_add_spells (this, 0);
255 140
256 activate (); 141 activate ();
257 142
258 send_rules (ob);
259 send_news (ob);
260 display_motd (ob);
261
262 INVOKE_PLAYER (CONNECT, this); 143 INVOKE_PLAYER (CONNECT, this);
263 INVOKE_PLAYER (LOGIN, this); 144 INVOKE_PLAYER (LOGIN, this);
264} 145}
265 146
266void 147void
282 ns->reset_stats (); 163 ns->reset_stats ();
283 ns->pl = 0; 164 ns->pl = 0;
284 ns = 0; 165 ns = 0;
285 } 166 }
286 167
287 observe = ob; 168 // this is important for the player scheduler to get the correct refcount
169 // when ns = 0
170 observe = viewpoint = ob;
288 171
289 deactivate (); 172 deactivate ();
290} 173}
174
175//-GPL
291 176
292// the need for this function can be explained 177// the need for this function can be explained
293// by load_object not returning the object 178// by load_object not returning the object
294void 179void
295player::set_object (object *op) 180player::set_object (object *op)
296{ 181{
297 ob = observe = op; 182 ob = observe = viewpoint = op;
298 ob->contr = this; /* this aren't yet in archetype */ 183 ob->contr = this; /* this aren't yet in archetype */
299 184
300 ob->speed = 1.0f; 185 ob->speed = 1.0f;
301 ob->speed_left = 0.5f; 186 ob->speed_left = 0.5f;
302 187
331} 216}
332 217
333void 218void
334player::set_observe (object *op) 219player::set_observe (object *op)
335{ 220{
336 observe = op ? op : ob; 221 observe = viewpoint = op ? op : ob;
337 do_los = 1; 222 do_los = 1;
338} 223}
224
225void
226player::set_viewpoint (object *op)
227{
228 viewpoint = op ? op : (object *)observe;
229 do_los = 1;
230}
231
232//+GPL
339 233
340player::player () 234player::player ()
341{ 235{
342 /* There are some elements we want initialised to non zero value - 236 /* There are some elements we want initialised to non zero value -
343 * we deal with that below this point. 237 * we deal with that below this point.
370 { 264 {
371 ob->destroy_inv (false); 265 ob->destroy_inv (false);
372 ob->destroy (); 266 ob->destroy ();
373 } 267 }
374 268
375 ob = observe = 0; 269 ob = observe = viewpoint = 0;
376} 270}
377 271
378player::~player () 272player::~player ()
379{ 273{
380 /* Clear item stack */ 274 /* Clear item stack */
381 free (stack_items); 275 free (stack_items);
276}
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 */
283static archetype *
284get_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 }
382} 304}
383 305
384/* Tries to add player on the connection passed in ns. 306/* Tries to add player on the connection passed in ns.
385 * 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
386 * mode. 308 * mode.
397 pl->ob->run_away = 25; /* Then we panick... */ 319 pl->ob->run_away = 25; /* Then we panick... */
398 320
399 set_first_map (pl->ob); 321 set_first_map (pl->ob);
400 322
401 return pl; 323 return pl;
402}
403
404/*
405 * get_player_archetype() return next player archetype from archetype
406 * list. Not very efficient routine, but used only creating new players.
407 * Note: there MUST be at least one player archetype!
408 */
409archetype *
410get_player_archetype (archetype *at)
411{
412 // archetypes could have been reloaded
413 archetype *nat = at ? archetype::find (at->archname) : archetypes [0];
414
415 if (!nat)
416 return at;
417
418 archvec::iterator i = archetypes.find (nat);
419
420 for (;;)
421 {
422 if (++i == archetypes.end ())
423 i = archetypes.begin ();
424 else if (*i == at)
425 cleanup ("not a single player archetype found");
426
427 if ((*i)->type == PLAYER)
428 return *i;
429 }
430} 324}
431 325
432object * 326object *
433get_nearest_player (object *mon) 327get_nearest_player (object *mon)
434{ 328{
850player::chargen_race_done () 744player::chargen_race_done ()
851{ 745{
852 /* this must before then initial items are given */ 746 /* this must before then initial items are given */
853 esrv_new_player (ob->contr); 747 esrv_new_player (ob->contr);
854 748
855 treasurelist *tl = treasurelist::find ("starting_wealth"); 749 treasurelist *tl = treasurelist::find (shstr_starting_wealth);
856 if (tl) 750 if (tl)
857 create_treasure (tl, ob, 0, 0, 0); 751 create_treasure (tl, ob, 0, 0, 0);
858 752
859 INVOKE_PLAYER (BIRTH, ob->contr); 753 INVOKE_PLAYER (BIRTH, ob->contr);
860 INVOKE_PLAYER (LOGIN, ob->contr); 754 INVOKE_PLAYER (LOGIN, ob->contr);
913 ob->stats.hp = ob->stats.maxhp; 807 ob->stats.hp = ob->stats.maxhp;
914 ob->stats.sp = ob->stats.maxsp; 808 ob->stats.sp = ob->stats.maxsp;
915 ob->stats.grace = 0; 809 ob->stats.grace = 0;
916} 810}
917 811
918void 812static void
919flee_player (object *op) 813flee_player (object *op)
920{ 814{
921 int dir, diff; 815 int dir, diff;
922 rv_vector rv; 816 rv_vector rv;
923 817
1009 if (op->contr->mode & PU_DEBUG) 903 if (op->contr->mode & PU_DEBUG)
1010 { 904 {
1011 /* some debugging code to figure out item information */ 905 /* some debugging code to figure out item information */
1012 const char *str = tmp->name 906 const char *str = tmp->name
1013 ? format ("item name: %s item type: %d weight/value: %d", 907 ? format ("item name: %s item type: %d weight/value: %d",
1014 &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))))
1015 : format ("item name: %s item type: %d weight/value: %d", 909 : format ("item name: %s item type: %d weight/value: %d",
1016 &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))));
1017 911
1018 new_draw_info (NDI_UNIQUE, 0, op, str); 912 new_draw_info (NDI_UNIQUE, 0, op, str);
1019 } 913 }
1020 914
1021 if (op->contr->mode & PU_INHIBIT) 915 if (op->contr->mode & PU_INHIBIT)
1252 fprintf (stderr, "%s", tmp->name); 1146 fprintf (stderr, "%s", tmp->name);
1253 } 1147 }
1254 else 1148 else
1255 fprintf (stderr, "%s", tmp->arch->archname); 1149 fprintf (stderr, "%s", tmp->arch->archname);
1256 fprintf (stderr, ",%d] = ", tmp->type); 1150 fprintf (stderr, ",%d] = ", tmp->type);
1257 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))));
1258#endif 1152#endif
1259 CHK_PICK_PICKUP; 1153 CHK_PICK_PICKUP;
1260 continue; 1154 continue;
1261 } 1155 }
1262 } /* the new pickup model */ 1156 } /* the new pickup model */
1263 } 1157 }
1264 1158
1265 return !stop; 1159 return !stop;
1266} 1160}
1267 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 */
1168static int
1169action_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
1268/* 1197/*
1269 * Find an arrow in the inventory and after that 1198 * Find an arrow in the inventory and after that
1270 * in the right type container (quiver). Pointer to the 1199 * in the right type container (quiver). Pointer to the
1271 * found object is returned. 1200 * found object is returned.
1272 */ 1201 */
1273object * 1202static object *
1274find_arrow (object *op, const char *type) 1203find_arrow (object *op, const char *type)
1275{ 1204{
1276 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1205 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1277 if (tmp->type == ARROW && !strcmp (&tmp->race, type)) 1206 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1278 return splay (tmp); 1207 return splay (tmp);
1292 * 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
1293 * 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
1294 * 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
1295 * 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.
1296 */ 1225 */
1297object * 1226static object *
1298find_better_arrow (object *op, object *target, shstr_cmp type, int *better) 1227find_better_arrow (object *op, object *target, shstr_cmp type, int *better)
1299{ 1228{
1300 object *tmp = NULL, *arrow, *ntmp; 1229 object *tmp = NULL, *arrow, *ntmp;
1301 int attacknum, attacktype, betterby = 0, i; 1230 int attacknum, attacktype, betterby = 0, i;
1302 1231
1371 * find_better_arrow to find a decent arrow to use. 1300 * find_better_arrow to find a decent arrow to use.
1372 * op = the shooter 1301 * op = the shooter
1373 * type = bow->race 1302 * type = bow->race
1374 * dir = fire direction 1303 * dir = fire direction
1375 */ 1304 */
1376object * 1305static object *
1377pick_arrow_target (object *op, shstr_cmp type, int dir) 1306pick_arrow_target (object *op, shstr_cmp type, int dir)
1378{ 1307{
1379 object *tmp = NULL; 1308 object *tmp = NULL;
1380 maptile *m; 1309 maptile *m;
1381 int i, mflags, found, number; 1310 int i, mflags, found, number;
1596 * but monsters can't. Putting that code here 1525 * but monsters can't. Putting that code here
1597 * makes the fire_bow code much cleaner. 1526 * makes the fire_bow code much cleaner.
1598 * this function should only be called if 'op' is a player, 1527 * this function should only be called if 'op' is a player,
1599 * hence the function name. 1528 * hence the function name.
1600 */ 1529 */
1601int 1530static int
1602player_fire_bow (object *op, int dir) 1531player_fire_bow (object *op, int dir)
1603{ 1532{
1604 int ret; 1533 int ret;
1605 1534
1606 if (op->contr->bowtype == bow_bestarrow) 1535 if (op->contr->bowtype == bow_bestarrow)
1634} 1563}
1635 1564
1636/* Fires a misc (wand/rod/horn) object in 'dir'. 1565/* Fires a misc (wand/rod/horn) object in 'dir'.
1637 * Broken apart from 'fire' to keep it more readable. 1566 * Broken apart from 'fire' to keep it more readable.
1638 */ 1567 */
1639void 1568static void
1640fire_misc_object (object *op, int dir) 1569fire_misc_object (object *op, int dir)
1641{ 1570{
1642 object *item = op->contr->ranged_ob; 1571 object *item = op->contr->ranged_ob;
1643 1572
1644 if (!item) 1573 if (!item)
1666 return; 1595 return;
1667 } 1596 }
1668 } 1597 }
1669 else if (item->type == ROD || item->type == HORN) 1598 else if (item->type == ROD || item->type == HORN)
1670 { 1599 {
1671 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);
1672 1601
1673 // 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
1674 // for a rod or horn, this fixes some broken rods. 1603 // for a rod or horn, this fixes some broken rods.
1675 if (item->stats.hp < MIN (spell_sp, item->stats.maxhp)) 1604 if (item->stats.hp < min (spell_sp, item->stats.maxhp))
1676 { 1605 {
1677 op->contr->play_sound (sound_find ("wand_poof")); 1606 op->contr->play_sound (sound_find ("wand_poof"));
1678 1607
1679 if (item->type == ROD) 1608 if (item->type == ROD)
1680 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));
1767 } 1696 }
1768 1697
1769 return true; 1698 return true;
1770} 1699}
1771 1700
1772/* find_key 1701static object *
1773 * We try to find a key for the door as passed. If we find a key
1774 * and successfully use it, we return the key, otherwise NULL
1775 * This function merges both normal and locked door, since the logic
1776 * for both is the same - just the specific key is different.
1777 * pl is the player,
1778 * inv is the objects inventory to searched
1779 * door is the door we are trying to match against.
1780 * This function can be called recursively to search containers.
1781 */
1782object *
1783find_key (object *pl, object *container, object *door) 1702find_key_ (object *pl, object *container, object *door)
1784{ 1703{
1785 object *tmp, *key; 1704 object *tmp, *key;
1786 1705
1787 /* Should not happen, but sanity checking is never bad */ 1706 /* Should not happen, but sanity checking is never bad */
1788 if (!container->inv) 1707 if (!container->inv)
1809 if (!tmp) 1728 if (!tmp)
1810 { 1729 {
1811 for (tmp = container->inv; tmp; tmp = tmp->below) 1730 for (tmp = container->inv; tmp; tmp = tmp->below)
1812 /* No reason to search empty containers */ 1731 /* No reason to search empty containers */
1813 if (tmp->type == CONTAINER && tmp->inv) 1732 if (tmp->type == CONTAINER && tmp->inv)
1814 if ((key = find_key (pl, tmp, door))) 1733 if ((key = find_key_ (pl, tmp, door)))
1815 return key; 1734 return key;
1816 1735
1817 if (!tmp) 1736 if (!tmp)
1818 return 0; 1737 return 0;
1819 } 1738 }
1838 * inv must have been an container and must have been active. 1757 * inv must have been an container and must have been active.
1839 * 1758 *
1840 * Change the color so that the message doesn't disappear with 1759 * Change the color so that the message doesn't disappear with
1841 * all the others. 1760 * all the others.
1842 */ 1761 */
1843 if (pl->contr->usekeys == key_inventory || 1762 if (pl->contr->usekeys == key_inventory
1844 !QUERY_FLAG (container, FLAG_APPLIED) || 1763 || !QUERY_FLAG (container, FLAG_APPLIED)
1845 (pl->contr->usekeys == keyrings && container->race != shstr_keys)) 1764 || (pl->contr->usekeys == keyrings && container->race != shstr_keys))
1846 { 1765 {
1847 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1766 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl,
1848 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); 1767 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container));
1849 return NULL; 1768 return NULL;
1850 } 1769 }
1851 } 1770 }
1852 1771
1853 return tmp; 1772 return tmp;
1773}
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 */
1785object *
1786find_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);
1854} 1798}
1855 1799
1856/* moved door processing out of move_player_attack. 1800/* moved door processing out of move_player_attack.
1857 * returns 1 if player has opened the door with a key 1801 * returns 1 if player has opened the door with a key
1858 * such that the caller should not do anything more, 1802 * such that the caller should not do anything more,
2074} 2018}
2075 2019
2076bool 2020bool
2077move_player (object *op, int dir) 2021move_player (object *op, int dir)
2078{ 2022{
2079 int pick;
2080
2081 if (!op->map || op->map->in_memory != MAP_ACTIVE) 2023 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2082 return 0; 2024 return 0;
2083 2025
2084 /* Sanity check: make sure dir is valid */ 2026 /* Sanity check: make sure dir is valid */
2085 if ((dir < 0) || (dir >= 9)) 2027 if ((dir < 0) || (dir >= 9))
2096 2038
2097 if (op->flag [FLAG_HIDDEN]) 2039 if (op->flag [FLAG_HIDDEN])
2098 do_hidden_move (op); 2040 do_hidden_move (op);
2099 2041
2100 bool retval; 2042 bool retval;
2043 int pick = 0;
2101 2044
2102 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2045 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2103 retval = RESULT_INT (0); 2046 retval = RESULT_INT (0);
2104 else if (op->contr->fire_on) 2047 else if (op->contr->fire_on)
2105 retval = fire (op, dir); 2048 retval = fire (op, dir);
2162 return move_player (op, op->direction); 2105 return move_player (op, op->direction);
2163 2106
2164 return false; 2107 return false;
2165} 2108}
2166 2109
2167int 2110static int
2168save_life (object *op) 2111save_life (object *op)
2169{ 2112{
2170 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2113 if (!QUERY_FLAG (op, FLAG_LIFESAVE))
2171 return 0; 2114 return 0;
2172 2115
2219void 2162void
2220object::drop_unpaid_items () 2163object::drop_unpaid_items ()
2221{ 2164{
2222 if (!flag [FLAG_REMOVED]) 2165 if (!flag [FLAG_REMOVED])
2223 ::drop_unpaid_items (inv, this); 2166 ::drop_unpaid_items (inv, this);
2224}
2225
2226/*
2227 * Returns pointer a static string containing gravestone text
2228 * Moved from apply.c to player.c - player.c is what
2229 * actually uses this function. player.c may not be quite the
2230 * best, a misc file for object actions is probably better,
2231 * but there isn't one in the server directory.
2232 */
2233const char *
2234gravestone_text (object *op)
2235{
2236 static dynbuf_text buf;
2237
2238 buf << "---- R.I.P. ----\n\n"
2239 << op->name;
2240
2241 if (op->type == PLAYER)
2242 buf << " the " << op->contr->title;
2243
2244 buf << "\n\n";
2245
2246 buf << "who was level ";
2247 buf << (sint32)op->level << "\n\n" // OO breakdown
2248 << " when " << (op->contr ? "killed" : "died") << "\n\n";
2249
2250 if (op->type == PLAYER)
2251 buf << "by " << op->contr->killer_name () << ".\n\n";
2252
2253 {
2254 static char buf2[128];
2255 time_t now = time (NULL);
2256 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2257 buf << buf2;
2258 }
2259
2260 return buf;
2261} 2167}
2262 2168
2263void 2169void
2264do_some_living (object *op) 2170do_some_living (object *op)
2265{ 2171{
2520 return; 2426 return;
2521 2427
2522 dynbuf_text deathtab; 2428 dynbuf_text deathtab;
2523 2429
2524 /* restore player */ 2430 /* restore player */
2525 at = archetype::find ("poisoning"); 2431 at = archetype::find (shstr_poisoning);
2526 if (object *tmp = present_arch_in_ob (at, op)) 2432 if (object *tmp = present_arch_in_ob (at, op))
2527 { 2433 {
2528 tmp->destroy (); 2434 tmp->destroy ();
2529 deathtab << "Your body feels cleansed...\r"; 2435 deathtab << "Your body feels cleansed...\r";
2530 } 2436 }
2531 2437
2532 at = archetype::find ("confusion"); 2438 at = archetype::find (shstr_confusion);
2533 if (object *tmp = present_arch_in_ob (at, op)) 2439 if (object *tmp = present_arch_in_ob (at, op))
2534 { 2440 {
2535 tmp->destroy (); 2441 tmp->destroy ();
2536 deathtab << "Your mind feels clearer...\r"; 2442 deathtab << "Your mind feels clearer...\r";
2537 } 2443 }
2564 if (op_on_battleground (op, &x, &y)) 2470 if (op_on_battleground (op, &x, &y))
2565 { 2471 {
2566 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";
2567 2473
2568 /* create a bodypart-trophy to make the winner happy */ 2474 /* create a bodypart-trophy to make the winner happy */
2569 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2475 if (object *tmp = arch_to_object (archetype::find (shstr_finger)))
2570 { 2476 {
2571 tmp->name = format ("%s's finger" , &op->name); 2477 tmp->name = format ("%s's finger" , &op->name);
2572 tmp->name_pl = format ("%s's fingers", &op->name); 2478 tmp->name_pl = format ("%s's fingers", &op->name);
2573 tmp->msg = format ( 2479 tmp->msg = format (
2574 "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",
2649 lost_a_stat = 1; 2555 lost_a_stat = 1;
2650 } 2556 }
2651 else 2557 else
2652 { 2558 {
2653 /* deplete a stat */ 2559 /* deplete a stat */
2654 archetype *deparch = archetype::find ("depletion"); 2560 archetype *deparch = archetype::find (shstr_depletion);
2655 object *dep; 2561 object *dep;
2656 2562
2657 dep = present_arch_in_ob (deparch, op); 2563 dep = present_arch_in_ob (deparch, op);
2658 if (!dep) 2564 if (!dep)
2659 { 2565 {
2731#endif 2637#endif
2732 2638
2733 /* Put a gravestone up where the character 'almost' died. List the 2639 /* Put a gravestone up where the character 'almost' died. List the
2734 * exp loss on the stone. 2640 * exp loss on the stone.
2735 */ 2641 */
2736 tmp = arch_to_object (archetype::find ("gravestone")); 2642 tmp = arch_to_object (archetype::find (shstr_gravestone));
2737 tmp->name = format ("%s's gravestone", &op->name); 2643 tmp->name = format ("%s's gravestone", &op->name);
2738 tmp->name_pl = format ("%s's gravestones", &op->name); 2644 tmp->name_pl = format ("%s's gravestones", &op->name);
2739 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",
2740 &op->name, op->contr->title, op->contr->killer_name ()); 2646 &op->name, op->contr->title, op->contr->killer_name ());
2741 tmp->x = op->x, tmp->y = op->y; 2647 tmp->x = op->x, tmp->y = op->y;
2796 } 2702 }
2797 2703
2798 op->contr->infobox (MSG_CHANNEL ("death"), deathtab); 2704 op->contr->infobox (MSG_CHANNEL ("death"), deathtab);
2799} 2705}
2800 2706
2801void 2707static void
2802loot_object (object *op) 2708loot_object (object *op)
2803{ /* Grab and destroy some treasure */ 2709{ /* Grab and destroy some treasure */
2804 object *tmp, *tmp2, *next; 2710 object *tmp, *tmp2, *next;
2805 2711
2806 op->close_container (); /* close open sack first */ 2712 op->close_container (); /* close open sack first */
3108 } 3014 }
3109 3015
3110 return 0; 3016 return 0;
3111} 3017}
3112 3018
3113/* routine for both players and monsters. We call this when
3114 * there is a possibility for our action distrubing our hiding
3115 * place or invisiblity spell. Artefact invisiblity causes
3116 * "noise" instead. If we arent invisible to begin with, we
3117 * return 0.
3118 */
3119int
3120action_makes_visible (object *op)
3121{
3122 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3123 {
3124 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3125 {
3126 // artefact invisibility is permanent, but we still make noise
3127 // this is important for game-balance.
3128 if (op->contr)
3129 op->make_noise ();
3130
3131 return 0;
3132 }
3133
3134 if (op->contr && op->contr->tmp_invis == 0)
3135 return 0;
3136
3137 /* If monsters, they should become visible */
3138 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
3139 {
3140 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
3141 return 1;
3142 }
3143 }
3144
3145 return 0;
3146}
3147
3148/* op_on_battleground - checks if the given object op (usually 3019/* op_on_battleground - checks if the given object op (usually
3149 * a player) is standing on a valid battleground-tile, 3020 * a player) is standing on a valid battleground-tile,
3150 * function returns TRUE/FALSE. If true x, y returns the battleground 3021 * function returns TRUE/FALSE. If true x, y returns the battleground
3151 * -exit-coord. (and if x, y not NULL) 3022 * -exit-coord. (and if x, y not NULL)
3152 * 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
3372 3243
3373 if (pl->ranged_ob == ob) 3244 if (pl->ranged_ob == ob)
3374 pl->ranged_ob = 0; 3245 pl->ranged_ob = 0;
3375} 3246}
3376 3247
3248//-GPL
3249
3377sint8 3250sint8
3378player::darkness_at (maptile *map, int x, int y) const 3251player::darkness_at (maptile *map, int x, int y) const
3379{ 3252{
3380 if (!ns) 3253 if (!ns)
3381 return LOS_BLOCKED; 3254 return LOS_BLOCKED;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines