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.235 by root, Wed Nov 4 17:24:00 2009 UTC vs.
Revision 1.250 by root, Sat Dec 12 03:17:21 2009 UTC

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>
105 ob->race = ob->arch->race; 107 ob->race = ob->arch->race;
106 108
107 ob->update_weight (); 109 ob->update_weight ();
108 link_skills (); 110 link_skills ();
109 111
110 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
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 (is_dragon_pl (ob))
116 { 116 {
134 134
135 ns->floorbox_update (); 135 ns->floorbox_update ();
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 activate ();
140
141 INVOKE_PLAYER (CONNECT, this);
142 INVOKE_PLAYER (LOGIN, this);
143}
144
145void
146player::disconnect ()
147{
148 if (ob)
149 {
150 ob->close_container (); //TODO: client-specific
151 ob->drop_unpaid_items ();
152 }
153
154 if (ns)
155 {
156 if (active)
157 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
158
159 INVOKE_PLAYER (DISCONNECT, this);
160
161 ns->reset_stats ();
162 ns->pl = 0;
163 ns = 0;
164 }
165
166 // this is important for the player scheduler to get the correct refcount
167 // when ns = 0
168 observe = viewpoint = ob;
169
170 deactivate ();
171}
172
173// the need for this function can be explained
174// by load_object not returning the object
175void
176player::set_object (object *op)
177{
178 ob = observe = viewpoint = op;
179 ob->contr = this; /* this aren't yet in archetype */
180
181 ob->speed = 1.0f;
182 ob->speed_left = 0.5f;
183
184 ob->direction = 5; /* So player faces south */
185
186 ob->flag [FLAG_READY_WEAPON] = false; 139 ob->flag [FLAG_READY_WEAPON] = false;
187 ob->flag [FLAG_READY_SKILL] = false; 140 ob->flag [FLAG_READY_SKILL] = false;
188 ob->flag [FLAG_READY_BOW] = false; 141 ob->flag [FLAG_READY_BOW] = false;
189 142
190 for (object *op = ob->inv; op; op = op->below) 143 for (object *op = ob->inv; op; op = op->below)
191 if (op->flag [FLAG_APPLIED]) 144 if (op->flag [FLAG_APPLIED])
192 switch (op->type) 145 switch (op->type)
193 { 146 {
194 case SKILL: 147 case SKILL:
195 ob->flag [FLAG_APPLIED] = false; 148 op->flag [FLAG_APPLIED] = false;
196 break; 149 break;
197 150
198 case WAND: 151 case WAND:
199 case ROD: 152 case ROD:
200 case HORN: 153 case HORN:
205 case WEAPON: 158 case WEAPON:
206 combat_ob = op; 159 combat_ob = op;
207 break; 160 break;
208 } 161 }
209 162
163 ob->current_weapon = 0;
210 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 164 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
211 ob->deactivate (); // change_weapon activates, fix this better 165 activate (); // change_weapon also activates, but this doesn't hurt
166
167 INVOKE_PLAYER (CONNECT, this);
168 INVOKE_PLAYER (LOGIN, this);
169}
170
171void
172player::disconnect ()
173{
174 if (ob)
175 {
176 ob->close_container (); //TODO: client-specific
177 ob->drop_unpaid_items ();
178 }
179
180 if (ns)
181 {
182 if (active)
183 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
184
185 INVOKE_PLAYER (DISCONNECT, this);
186
187 ns->reset_stats ();
188 ns->pl = 0;
189 ns = 0;
190 }
191
192 // this is important for the player scheduler to get the correct refcount
193 // when ns = 0
194 observe = viewpoint = ob;
195
196 deactivate ();
197}
198
199//-GPL
200
201// the need for this function can be explained
202// by load_object not returning the object
203void
204player::set_object (object *op)
205{
206 ob = observe = viewpoint = op;
207 ob->contr = this; /* this aren't yet in archetype */
208
209 ob->speed = 1.0f;
210 ob->speed_left = 0.5f;
211
212 ob->direction = 5; /* So player faces south */
212} 213}
213 214
214void 215void
215player::set_observe (object *op) 216player::set_observe (object *op)
216{ 217{
222player::set_viewpoint (object *op) 223player::set_viewpoint (object *op)
223{ 224{
224 viewpoint = op ? op : (object *)observe; 225 viewpoint = op ? op : (object *)observe;
225 do_los = 1; 226 do_los = 1;
226} 227}
228
229//+GPL
227 230
228player::player () 231player::player ()
229{ 232{
230 /* There are some elements we want initialised to non zero value - 233 /* There are some elements we want initialised to non zero value -
231 * we deal with that below this point. 234 * we deal with that below this point.
267{ 270{
268 /* Clear item stack */ 271 /* Clear item stack */
269 free (stack_items); 272 free (stack_items);
270} 273}
271 274
275/*
276 * get_player_archetype() return next player archetype from archetype
277 * list. Not very efficient routine, but used only creating new players.
278 * Note: there MUST be at least one player archetype!
279 */
280static archetype *
281get_player_archetype (archetype *at)
282{
283 // archetypes could have been reloaded
284 archetype *nat = at ? archetype::find (at->archname) : archetypes [0];
285
286 if (!nat)
287 return at;
288
289 archvec::iterator i = archetypes.find (nat);
290
291 for (;;)
292 {
293 if (++i == archetypes.end ())
294 i = archetypes.begin ();
295 else if (*i == at)
296 cleanup ("not a single player archetype found");
297
298 if ((*i)->type == PLAYER)
299 return *i;
300 }
301}
302
272/* Tries to add player on the connection passed in ns. 303/* 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 304 * All we can really get in this is some settings like host and display
274 * mode. 305 * mode.
275 */ 306 */
276player * 307player *
277player::create () 308player::create ()
278{ 309{
279 player *pl = new player; 310 player *pl = new player;
280 311
281 pl->set_object (arch_to_object (get_player_archetype (0))); 312 pl->set_object (get_player_archetype (0)->instance ());
282 313
283 pl->ob->roll_stats (); 314 pl->ob->roll_stats ();
284 pl->ob->stats.wc = 2; 315 pl->ob->stats.wc = 2;
285 pl->ob->run_away = 25; /* Then we panick... */ 316 pl->ob->run_away = 25; /* Then we panick... */
286 317
287 set_first_map (pl->ob); 318 set_first_map (pl->ob);
288 319
289 return pl; 320 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 */
297archetype *
298get_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} 321}
319 322
320object * 323object *
321get_nearest_player (object *mon) 324get_nearest_player (object *mon)
322{ 325{
631 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:"); 634 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:");
632} 635}
633 636
634/* This rolls four 1-6 rolls and sums the best 3 of the 4. */ 637/* This rolls four 1-6 rolls and sums the best 3 of the 4. */
635static int 638static int
636roll_stat (void) 639roll_stat ()
637{ 640{
638 int a[4], i, j, k; 641 int a[4], i, j, k;
639 642
640 for (i = 0; i < 4; i++) 643 for (i = 0; i < 4; i++)
641 a[i] = (int) rndm (6) + 1; 644 a[i] = (int) rndm (6) + 1;
738player::chargen_race_done () 741player::chargen_race_done ()
739{ 742{
740 /* this must before then initial items are given */ 743 /* this must before then initial items are given */
741 esrv_new_player (ob->contr); 744 esrv_new_player (ob->contr);
742 745
743 treasurelist *tl = treasurelist::find ("starting_wealth"); 746 treasurelist *tl = treasurelist::find (shstr_starting_wealth);
744 if (tl) 747 if (tl)
745 create_treasure (tl, ob, 0, 0, 0); 748 create_treasure (tl, ob, 0, 0, 0);
746 749
747 INVOKE_PLAYER (BIRTH, ob->contr); 750 INVOKE_PLAYER (BIRTH, ob->contr);
748 INVOKE_PLAYER (LOGIN, ob->contr); 751 INVOKE_PLAYER (LOGIN, ob->contr);
801 ob->stats.hp = ob->stats.maxhp; 804 ob->stats.hp = ob->stats.maxhp;
802 ob->stats.sp = ob->stats.maxsp; 805 ob->stats.sp = ob->stats.maxsp;
803 ob->stats.grace = 0; 806 ob->stats.grace = 0;
804} 807}
805 808
806void 809static void
807flee_player (object *op) 810flee_player (object *op)
808{ 811{
809 int dir, diff; 812 int dir, diff;
810 rv_vector rv; 813 rv_vector rv;
811 814
861 if (op->move_type & MOVE_FLYING) 864 if (op->move_type & MOVE_FLYING)
862 return 1; 865 return 1;
863 866
864 next = op->below; 867 next = op->below;
865 868
866 int cnt = MAX_ITEM_PER_DROP; 869 int cnt = MAX_ITEM_PER_ACTION;
867#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0) 870#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0)
868 871
869 /* loop while there are items on the floor that are not marked as 872 /* loop while there are items on the floor that are not marked as
870 * destroyed */ 873 * destroyed */
871 while (next && !next->destroyed ()) 874 while (next && !next->destroyed ())
897 if (op->contr->mode & PU_DEBUG) 900 if (op->contr->mode & PU_DEBUG)
898 { 901 {
899 /* some debugging code to figure out item information */ 902 /* some debugging code to figure out item information */
900 const char *str = tmp->name 903 const char *str = tmp->name
901 ? format ("item name: %s item type: %d weight/value: %d", 904 ? 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)))) 905 &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", 906 : 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)))); 907 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1))));
905 908
906 new_draw_info (NDI_UNIQUE, 0, op, str); 909 new_draw_info (NDI_UNIQUE, 0, op, str);
907 } 910 }
908 911
909 if (op->contr->mode & PU_INHIBIT) 912 if (op->contr->mode & PU_INHIBIT)
996 continue; 999 continue;
997 } 1000 }
998 1001
999 /* wands/staves/rods/horns */ 1002 /* wands/staves/rods/horns */
1000 if (op->contr->mode & PU_MAGIC_DEVICE) 1003 if (op->contr->mode & PU_MAGIC_DEVICE)
1001 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1004 if (tmp->type == WAND
1005 || tmp->type == ROD
1006 || tmp->type == HORN
1007 || tmp->type == POWER_CRYSTAL)
1002 { 1008 {
1003 CHK_PICK_PICKUP; 1009 CHK_PICK_PICKUP;
1004 continue; 1010 continue;
1005 } 1011 }
1006 1012
1007 /* pick up all magical items */ 1013 /* pick up all magical items */
1008 if (op->contr->mode & PU_MAGICAL) 1014 if (op->contr->mode & PU_MAGICAL)
1009 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1015 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL)
1016 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1010 { 1017 {
1011 CHK_PICK_PICKUP; 1018 CHK_PICK_PICKUP;
1012 continue; 1019 continue;
1013 } 1020 }
1014 1021
1021 } 1028 }
1022 } 1029 }
1023 1030
1024 /* rings & amulets - talismans seems to be typed AMULET */ 1031 /* rings & amulets - talismans seems to be typed AMULET */
1025 if (op->contr->mode & PU_JEWELS) 1032 if (op->contr->mode & PU_JEWELS)
1026 if (tmp->type == RING || tmp->type == AMULET) 1033 if (tmp->type == RING
1034 || tmp->type == AMULET
1035 || tmp->type == GIRDLE
1036 || tmp->type == SKILL_TOOL)
1027 { 1037 {
1028 CHK_PICK_PICKUP; 1038 CHK_PICK_PICKUP;
1029 continue; 1039 continue;
1030 } 1040 }
1031 1041
1080 CHK_PICK_PICKUP; 1090 CHK_PICK_PICKUP;
1081 continue; 1091 continue;
1082 } 1092 }
1083 1093
1084 if (op->contr->mode & PU_GLOVES) 1094 if (op->contr->mode & PU_GLOVES)
1085 if (tmp->type == GLOVES) 1095 if (tmp->type == GLOVES || tmp->type == BRACERS)
1086 { 1096 {
1087 CHK_PICK_PICKUP; 1097 CHK_PICK_PICKUP;
1088 continue; 1098 continue;
1089 } 1099 }
1090 1100
1140 fprintf (stderr, "%s", tmp->name); 1150 fprintf (stderr, "%s", tmp->name);
1141 } 1151 }
1142 else 1152 else
1143 fprintf (stderr, "%s", tmp->arch->archname); 1153 fprintf (stderr, "%s", tmp->arch->archname);
1144 fprintf (stderr, ",%d] = ", tmp->type); 1154 fprintf (stderr, ",%d] = ", tmp->type);
1145 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1155 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1))));
1146#endif 1156#endif
1147 CHK_PICK_PICKUP; 1157 CHK_PICK_PICKUP;
1148 continue; 1158 continue;
1149 } 1159 }
1150 } /* the new pickup model */ 1160 } /* the new pickup model */
1151 } 1161 }
1152 1162
1153 return !stop; 1163 return !stop;
1154} 1164}
1155 1165
1166/* routine for both players and monsters. We call this when
1167 * there is a possibility for our action distrubing our hiding
1168 * place or invisiblity spell. Artefact invisiblity causes
1169 * "noise" instead. If we arent invisible to begin with, we
1170 * return 0.
1171 */
1172static int
1173action_makes_visible (object *op)
1174{
1175 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
1176 {
1177 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
1178 {
1179 // artefact invisibility is permanent, but we still make noise
1180 // this is important for game-balance.
1181 if (op->contr)
1182 op->make_noise ();
1183
1184 return 0;
1185 }
1186
1187 if (op->contr && op->contr->tmp_invis == 0)
1188 return 0;
1189
1190 /* If monsters, they should become visible */
1191 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
1192 {
1193 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
1194 return 1;
1195 }
1196 }
1197
1198 return 0;
1199}
1200
1156/* 1201/*
1157 * Find an arrow in the inventory and after that 1202 * Find an arrow in the inventory and after that
1158 * in the right type container (quiver). Pointer to the 1203 * in the right type container (quiver). Pointer to the
1159 * found object is returned. 1204 * found object is returned.
1160 */ 1205 */
1161object * 1206static object *
1162find_arrow (object *op, const char *type) 1207find_arrow (object *op, const char *type)
1163{ 1208{
1164 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1209 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1165 if (tmp->type == ARROW && !strcmp (&tmp->race, type)) 1210 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1166 return splay (tmp); 1211 return splay (tmp);
1180 * Similar to find_arrow, but looks for (roughly) the best arrow to use 1225 * 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 1226 * 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 1227 * 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. 1228 * the hall. Failing that it does it's best to pick the highest plus arrow.
1184 */ 1229 */
1185object * 1230static object *
1186find_better_arrow (object *op, object *target, shstr_cmp type, int *better) 1231find_better_arrow (object *op, object *target, shstr_cmp type, int *better)
1187{ 1232{
1188 object *tmp = NULL, *arrow, *ntmp; 1233 object *tmp = NULL, *arrow, *ntmp;
1189 int attacknum, attacktype, betterby = 0, i; 1234 int attacknum, attacktype, betterby = 0, i;
1190 1235
1259 * find_better_arrow to find a decent arrow to use. 1304 * find_better_arrow to find a decent arrow to use.
1260 * op = the shooter 1305 * op = the shooter
1261 * type = bow->race 1306 * type = bow->race
1262 * dir = fire direction 1307 * dir = fire direction
1263 */ 1308 */
1264object * 1309static object *
1265pick_arrow_target (object *op, shstr_cmp type, int dir) 1310pick_arrow_target (object *op, shstr_cmp type, int dir)
1266{ 1311{
1267 object *tmp = NULL; 1312 object *tmp = NULL;
1268 maptile *m; 1313 maptile *m;
1269 int i, mflags, found, number; 1314 int i, mflags, found, number;
1484 * but monsters can't. Putting that code here 1529 * but monsters can't. Putting that code here
1485 * makes the fire_bow code much cleaner. 1530 * makes the fire_bow code much cleaner.
1486 * this function should only be called if 'op' is a player, 1531 * this function should only be called if 'op' is a player,
1487 * hence the function name. 1532 * hence the function name.
1488 */ 1533 */
1489int 1534static int
1490player_fire_bow (object *op, int dir) 1535player_fire_bow (object *op, int dir)
1491{ 1536{
1492 int ret; 1537 int ret;
1493 1538
1494 if (op->contr->bowtype == bow_bestarrow) 1539 if (op->contr->bowtype == bow_bestarrow)
1522} 1567}
1523 1568
1524/* Fires a misc (wand/rod/horn) object in 'dir'. 1569/* Fires a misc (wand/rod/horn) object in 'dir'.
1525 * Broken apart from 'fire' to keep it more readable. 1570 * Broken apart from 'fire' to keep it more readable.
1526 */ 1571 */
1527void 1572static void
1528fire_misc_object (object *op, int dir) 1573fire_misc_object (object *op, int dir)
1529{ 1574{
1530 object *item = op->contr->ranged_ob; 1575 object *item = op->contr->ranged_ob;
1531 1576
1532 if (!item) 1577 if (!item)
1554 return; 1599 return;
1555 } 1600 }
1556 } 1601 }
1557 else if (item->type == ROD || item->type == HORN) 1602 else if (item->type == ROD || item->type == HORN)
1558 { 1603 {
1559 sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace); 1604 sint16 spell_sp = max (item->inv->stats.sp, item->inv->stats.grace);
1560 1605
1561 // using the maximum of the rods charge allows at least one spell cast 1606 // using the maximum of the rods charge allows at least one spell cast
1562 // for a rod or horn, this fixes some broken rods. 1607 // for a rod or horn, this fixes some broken rods.
1563 if (item->stats.hp < MIN (spell_sp, item->stats.maxhp)) 1608 if (item->stats.hp < min (spell_sp, item->stats.maxhp))
1564 { 1609 {
1565 op->contr->play_sound (sound_find ("wand_poof")); 1610 op->contr->play_sound (sound_find ("wand_poof"));
1566 1611
1567 if (item->type == ROD) 1612 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)); 1613 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0));
1655 } 1700 }
1656 1701
1657 return true; 1702 return true;
1658} 1703}
1659 1704
1660/* find_key 1705static 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 */
1670object *
1671find_key (object *pl, object *container, object *door) 1706find_key_ (object *pl, object *container, object *door)
1672{ 1707{
1673 object *tmp, *key; 1708 object *tmp, *key;
1674 1709
1675 /* Should not happen, but sanity checking is never bad */ 1710 /* Should not happen, but sanity checking is never bad */
1676 if (!container->inv) 1711 if (!container->inv)
1697 if (!tmp) 1732 if (!tmp)
1698 { 1733 {
1699 for (tmp = container->inv; tmp; tmp = tmp->below) 1734 for (tmp = container->inv; tmp; tmp = tmp->below)
1700 /* No reason to search empty containers */ 1735 /* No reason to search empty containers */
1701 if (tmp->type == CONTAINER && tmp->inv) 1736 if (tmp->type == CONTAINER && tmp->inv)
1702 if ((key = find_key (pl, tmp, door))) 1737 if ((key = find_key_ (pl, tmp, door)))
1703 return key; 1738 return key;
1704 1739
1705 if (!tmp) 1740 if (!tmp)
1706 return 0; 1741 return 0;
1707 } 1742 }
1726 * inv must have been an container and must have been active. 1761 * inv must have been an container and must have been active.
1727 * 1762 *
1728 * Change the color so that the message doesn't disappear with 1763 * Change the color so that the message doesn't disappear with
1729 * all the others. 1764 * all the others.
1730 */ 1765 */
1731 if (pl->contr->usekeys == key_inventory || 1766 if (pl->contr->usekeys == key_inventory
1732 !QUERY_FLAG (container, FLAG_APPLIED) || 1767 || !QUERY_FLAG (container, FLAG_APPLIED)
1733 (pl->contr->usekeys == keyrings && container->race != shstr_keys)) 1768 || (pl->contr->usekeys == keyrings && container->race != shstr_keys))
1734 { 1769 {
1735 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1770 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl,
1736 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); 1771 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container));
1737 return NULL; 1772 return NULL;
1738 } 1773 }
1739 } 1774 }
1740 1775
1741 return tmp; 1776 return tmp;
1777}
1778
1779/* find_key
1780 * We try to find a key for the door as passed. If we find a key
1781 * and successfully use it, we return the key, otherwise NULL
1782 * This function merges both normal and locked door, since the logic
1783 * for both is the same - just the specific key is different.
1784 * pl is the player,
1785 * inv is the objects inventory to searched
1786 * door is the door we are trying to match against.
1787 * This function can be called recursively to search containers.
1788 */
1789object *
1790find_key (object *pl, object *container, object *door)
1791{
1792 if (door->slaying && is_match_expr (door->slaying))
1793 {
1794 // for match expressions, we try to find the key by applying the match
1795 // to the op itself, which is supposed to find the "key", instead
1796 // of searching through containers ourselves.
1797
1798 return match_one (door->slaying, container, door, pl, pl);
1799 }
1800 else
1801 return find_key_ (pl, container, door);
1742} 1802}
1743 1803
1744/* moved door processing out of move_player_attack. 1804/* moved door processing out of move_player_attack.
1745 * returns 1 if player has opened the door with a key 1805 * returns 1 if player has opened the door with a key
1746 * such that the caller should not do anything more, 1806 * such that the caller should not do anything more,
1962} 2022}
1963 2023
1964bool 2024bool
1965move_player (object *op, int dir) 2025move_player (object *op, int dir)
1966{ 2026{
1967 int pick;
1968
1969 if (!op->map || op->map->in_memory != MAP_ACTIVE) 2027 if (!op->map || op->map->in_memory != MAP_ACTIVE)
1970 return 0; 2028 return 0;
1971 2029
1972 /* Sanity check: make sure dir is valid */ 2030 /* Sanity check: make sure dir is valid */
1973 if ((dir < 0) || (dir >= 9)) 2031 if ((dir < 0) || (dir >= 9))
1984 2042
1985 if (op->flag [FLAG_HIDDEN]) 2043 if (op->flag [FLAG_HIDDEN])
1986 do_hidden_move (op); 2044 do_hidden_move (op);
1987 2045
1988 bool retval; 2046 bool retval;
2047 int pick = 0;
1989 2048
1990 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2049 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
1991 retval = RESULT_INT (0); 2050 retval = RESULT_INT (0);
1992 else if (op->contr->fire_on) 2051 else if (op->contr->fire_on)
1993 retval = fire (op, dir); 2052 retval = fire (op, dir);
2050 return move_player (op, op->direction); 2109 return move_player (op, op->direction);
2051 2110
2052 return false; 2111 return false;
2053} 2112}
2054 2113
2055int 2114static int
2056save_life (object *op) 2115save_life (object *op)
2057{ 2116{
2058 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2117 if (!QUERY_FLAG (op, FLAG_LIFESAVE))
2059 return 0; 2118 return 0;
2060 2119
2107void 2166void
2108object::drop_unpaid_items () 2167object::drop_unpaid_items ()
2109{ 2168{
2110 if (!flag [FLAG_REMOVED]) 2169 if (!flag [FLAG_REMOVED])
2111 ::drop_unpaid_items (inv, this); 2170 ::drop_unpaid_items (inv, this);
2112}
2113
2114/*
2115 * Returns pointer a static string containing gravestone text
2116 * Moved from apply.c to player.c - player.c is what
2117 * actually uses this function. player.c may not be quite the
2118 * best, a misc file for object actions is probably better,
2119 * but there isn't one in the server directory.
2120 */
2121const char *
2122gravestone_text (object *op)
2123{
2124 static dynbuf_text buf;
2125
2126 buf << "---- R.I.P. ----\n\n"
2127 << op->name;
2128
2129 if (op->type == PLAYER)
2130 buf << " the " << op->contr->title;
2131
2132 buf << "\n\n";
2133
2134 buf << "who was level ";
2135 buf << (sint32)op->level << "\n\n" // OO breakdown
2136 << " when " << (op->contr ? "killed" : "died") << "\n\n";
2137
2138 if (op->type == PLAYER)
2139 buf << "by " << op->contr->killer_name () << ".\n\n";
2140
2141 {
2142 static char buf2[128];
2143 time_t now = time (NULL);
2144 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2145 buf << buf2;
2146 }
2147
2148 return buf;
2149} 2171}
2150 2172
2151void 2173void
2152do_some_living (object *op) 2174do_some_living (object *op)
2153{ 2175{
2408 return; 2430 return;
2409 2431
2410 dynbuf_text deathtab; 2432 dynbuf_text deathtab;
2411 2433
2412 /* restore player */ 2434 /* restore player */
2413 at = archetype::find ("poisoning"); 2435 at = archetype::find (shstr_poisoning);
2414 if (object *tmp = present_arch_in_ob (at, op)) 2436 if (object *tmp = present_arch_in_ob (at, op))
2415 { 2437 {
2416 tmp->destroy (); 2438 tmp->destroy ();
2417 deathtab << "Your body feels cleansed...\r"; 2439 deathtab << "Your body feels cleansed...\r";
2418 } 2440 }
2419 2441
2420 at = archetype::find ("confusion"); 2442 at = archetype::find (shstr_confusion);
2421 if (object *tmp = present_arch_in_ob (at, op)) 2443 if (object *tmp = present_arch_in_ob (at, op))
2422 { 2444 {
2423 tmp->destroy (); 2445 tmp->destroy ();
2424 deathtab << "Your mind feels clearer...\r"; 2446 deathtab << "Your mind feels clearer...\r";
2425 } 2447 }
2452 if (op_on_battleground (op, &x, &y)) 2474 if (op_on_battleground (op, &x, &y))
2453 { 2475 {
2454 deathtab << "You almost died in combat, but local medics have saved your life...\r"; 2476 deathtab << "You almost died in combat, but local medics have saved your life...\r";
2455 2477
2456 /* create a bodypart-trophy to make the winner happy */ 2478 /* create a bodypart-trophy to make the winner happy */
2457 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2479 object *tmp = archetype::find (shstr_finger)->instance ();
2458 { 2480
2459 tmp->name = format ("%s's finger" , &op->name); 2481 tmp->name = format ("%s's finger" , &op->name);
2460 tmp->name_pl = format ("%s's fingers", &op->name); 2482 tmp->name_pl = format ("%s's fingers", &op->name);
2461 tmp->msg = format ( 2483 tmp->msg = format (
2462 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", 2484 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n",
2463 &op->name, op->contr->title, 2485 &op->name, op->contr->title,
2464 (int)op->level, 2486 (int)op->level,
2465 op->contr->killer_name () 2487 op->contr->killer_name ()
2466 ); 2488 );
2467 tmp->value = 0, tmp->type = 0; 2489 tmp->value = 0, tmp->type = 0;
2468 tmp->materialname = "organics"; 2490 tmp->material = name_to_material (shstr_organic);
2469 tmp->insert_at (op, tmp); 2491 tmp->insert_at (op, tmp);
2470 }
2471 2492
2472 /* teleport defeated player to new destination */ 2493 /* teleport defeated player to new destination */
2473 transfer_ob (op, x, y, 0, NULL); 2494 transfer_ob (op, x, y, 0, NULL);
2474 op->contr->braced = 0; 2495 op->contr->braced = 0;
2475 2496
2537 lost_a_stat = 1; 2558 lost_a_stat = 1;
2538 } 2559 }
2539 else 2560 else
2540 { 2561 {
2541 /* deplete a stat */ 2562 /* deplete a stat */
2542 archetype *deparch = archetype::find ("depletion"); 2563 archetype *deparch = archetype::find (shstr_depletion);
2543 object *dep; 2564 object *dep;
2544 2565
2545 dep = present_arch_in_ob (deparch, op); 2566 dep = present_arch_in_ob (deparch, op);
2546 if (!dep) 2567 if (!dep)
2547 { 2568 {
2548 dep = arch_to_object (deparch); 2569 dep = deparch->instance ();
2549 insert_ob_in_ob (dep, op); 2570 insert_ob_in_ob (dep, op);
2550 } 2571 }
2551 lose_this_stat = 1; 2572 lose_this_stat = 1;
2552 if (settings.balanced_stat_loss) 2573 if (settings.balanced_stat_loss)
2553 { 2574 {
2619#endif 2640#endif
2620 2641
2621 /* Put a gravestone up where the character 'almost' died. List the 2642 /* Put a gravestone up where the character 'almost' died. List the
2622 * exp loss on the stone. 2643 * exp loss on the stone.
2623 */ 2644 */
2624 tmp = arch_to_object (archetype::find ("gravestone")); 2645 tmp = archetype::find (shstr_gravestone)->instance ();
2625 tmp->name = format ("%s's gravestone", &op->name); 2646 tmp->name = format ("%s's gravestone", &op->name);
2626 tmp->name_pl = format ("%s's gravestones", &op->name); 2647 tmp->name_pl = format ("%s's gravestones", &op->name);
2627 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", 2648 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n",
2628 &op->name, op->contr->title, op->contr->killer_name ()); 2649 &op->name, op->contr->title, op->contr->killer_name ());
2629 tmp->x = op->x, tmp->y = op->y; 2650 tmp->x = op->x, tmp->y = op->y;
2684 } 2705 }
2685 2706
2686 op->contr->infobox (MSG_CHANNEL ("death"), deathtab); 2707 op->contr->infobox (MSG_CHANNEL ("death"), deathtab);
2687} 2708}
2688 2709
2689void 2710static void
2690loot_object (object *op) 2711loot_object (object *op)
2691{ /* Grab and destroy some treasure */ 2712{ /* Grab and destroy some treasure */
2692 object *tmp, *tmp2, *next; 2713 object *tmp, *tmp2, *next;
2693 2714
2694 op->close_container (); /* close open sack first */ 2715 op->close_container (); /* close open sack first */
2725 * fix_weight(): Check recursively the weight of all players, and fix 2746 * fix_weight(): Check recursively the weight of all players, and fix
2726 * what needs to be fixed. Refresh windows and fix speed if anything 2747 * what needs to be fixed. Refresh windows and fix speed if anything
2727 * was changed. 2748 * was changed.
2728 */ 2749 */
2729void 2750void
2730fix_weight (void) 2751fix_weight ()
2731{ 2752{
2732 for_all_players (pl) 2753 for_all_players (pl)
2733 { 2754 {
2734 sint32 old = pl->ob->carrying; 2755 sint32 old = pl->ob->carrying;
2735 2756
2742 } 2763 }
2743 } 2764 }
2744} 2765}
2745 2766
2746void 2767void
2747fix_luck (void) 2768fix_luck ()
2748{ 2769{
2749 for_all_players (pl) 2770 for_all_players (pl)
2750 if (!pl->ob->contr->ns->state) 2771 if (!pl->ob->contr->ns->state)
2751 pl->ob->change_luck (0); 2772 pl->ob->change_luck (0);
2752} 2773}
2996 } 3017 }
2997 3018
2998 return 0; 3019 return 0;
2999} 3020}
3000 3021
3001/* routine for both players and monsters. We call this when
3002 * there is a possibility for our action distrubing our hiding
3003 * place or invisiblity spell. Artefact invisiblity causes
3004 * "noise" instead. If we arent invisible to begin with, we
3005 * return 0.
3006 */
3007int
3008action_makes_visible (object *op)
3009{
3010 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3011 {
3012 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3013 {
3014 // artefact invisibility is permanent, but we still make noise
3015 // this is important for game-balance.
3016 if (op->contr)
3017 op->make_noise ();
3018
3019 return 0;
3020 }
3021
3022 if (op->contr && op->contr->tmp_invis == 0)
3023 return 0;
3024
3025 /* If monsters, they should become visible */
3026 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
3027 {
3028 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
3029 return 1;
3030 }
3031 }
3032
3033 return 0;
3034}
3035
3036/* op_on_battleground - checks if the given object op (usually 3022/* op_on_battleground - checks if the given object op (usually
3037 * a player) is standing on a valid battleground-tile, 3023 * a player) is standing on a valid battleground-tile,
3038 * function returns TRUE/FALSE. If true x, y returns the battleground 3024 * function returns TRUE/FALSE. If true x, y returns the battleground
3039 * -exit-coord. (and if x, y not NULL) 3025 * -exit-coord. (and if x, y not NULL)
3040 * 19 March 2005 - josh@woosworld.net modifed to check if the battleground also has slaying, maxhp, and maxsp set 3026 * 19 March 2005 - josh@woosworld.net modifed to check if the battleground also has slaying, maxhp, and maxsp set
3237 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); 3223 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg);
3238 } 3224 }
3239 else 3225 else
3240 { 3226 {
3241 /* generate misc. treasure */ 3227 /* generate misc. treasure */
3242 tmp = arch_to_object (tr->item); 3228 tmp = tr->item->instance ();
3243 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); 3229 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp));
3244 who->insert (tmp); 3230 who->insert (tmp);
3245 } 3231 }
3246} 3232}
3247 3233
3260 3246
3261 if (pl->ranged_ob == ob) 3247 if (pl->ranged_ob == ob)
3262 pl->ranged_ob = 0; 3248 pl->ranged_ob = 0;
3263} 3249}
3264 3250
3251//-GPL
3252
3265sint8 3253sint8
3266player::darkness_at (maptile *map, int x, int y) const 3254player::darkness_at (maptile *map, int x, int y) const
3267{ 3255{
3268 if (!ns) 3256 if (!ns)
3269 return LOS_BLOCKED; 3257 return LOS_BLOCKED;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines