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.53 by root, Fri Dec 22 16:03:21 2006 UTC vs.
Revision 1.54 by root, Fri Dec 22 16:34:00 2006 UTC

28#include <living.h> 28#include <living.h>
29#include <object.h> 29#include <object.h>
30#include <spells.h> 30#include <spells.h>
31#include <skills.h> 31#include <skills.h>
32 32
33#ifdef COZY_SERVER 33#include <algorithm>
34extern int same_party (partylist *a, partylist *b); 34#include <functional>
35#endif
36 35
37player * 36player *
38find_player (const char *plname) 37find_player (const char *plname)
39{ 38{
40 player *pl; 39 player *pl;
41 40
42 for (pl = first_player; pl; pl = pl->next) 41 for (pl = first_player; pl; pl = pl->next)
43 {
44 if (pl->obL && !strcmp (query_name (pl->ob), plname)) 42 if (pl->ob && !strcmp (query_name (pl->ob), plname))
45 return pl; 43 return pl;
46 };
47 44
48 return 0; 45 return 0;
49}
50
51player *
52find_player_partial_name (const char *plname)
53{
54 player *pl;
55 player *found = NULL;
56 size_t namelen = strlen (plname);
57
58 for (pl = first_player; pl; pl = pl->next)
59 {
60 if ((size_t) strlen (pl->ob->name) < namelen)
61 continue;
62
63 if (!strcmp (pl->ob->name, plname))
64 return pl;
65
66 if (!strncasecmp (pl->ob->name, plname, namelen))
67 {
68 if (found)
69 return 0;
70
71 found = pl;
72 }
73 }
74
75 return found;
76} 46}
77 47
78void 48void
79display_motd (const object *op) 49display_motd (const object *op)
80{ 50{
186 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, 156 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op,
187 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s\n", "%s\n%s", subject, news); 157 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s\n", "%s\n%s", subject, news);
188 close_and_delete (fp, comp); 158 close_and_delete (fp, comp);
189} 159}
190 160
191int 161/* This loads the first map an puts the player on it. */
192playername_ok (const char *cp) 162static void
163set_first_map (object *op)
193{ 164{
194 /* Don't allow - or _ as first character in the name */ 165 strcpy (op->contr->maplevel, first_map_path);
195 if (*cp == '-' || *cp == '_') 166 op->x = -1;
196 return 0; 167 op->y = -1;
197 168 enter_exit (op, 0);
198 for (; *cp != '\0'; cp++)
199 if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_')
200 return 0;
201
202 return 1;
203} 169}
204 170
205/* This no longer sets the player map. Also, it now updates 171void
206 * all the pointers so the caller doesn't need to do that. 172player::connect (client *ns)
207 * Caller is responsible for setting the correct map.
208 */
209
210/* Redo this to do both get_player_ob and get_player.
211 * Hopefully this will be less bugfree and simpler.
212 * Returns the player structure. If 'p' is null,
213 * we create a new one. Otherwise, we recycle
214 * the one that is passed.
215 */
216static player *
217get_player (player *p)
218{ 173{
219 object *op = arch_to_object (get_player_archetype (0)); 174 this->ns = ns;
220 int i; 175 ns->pl = this;
221 176
222 /* Clears basically the entire player structure except 177 next = first_player;
223 * for next and socket. 178 first_player = this;
179
180 ns->update_look = 0;
181 ns->look_position = 0;
182
183 clear_los (ob);
184
185 ob->type = PLAYER; // we are paranoid
186 ob->race = ob->arch->clone.race;
187
188 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
189 ob->update_stats ();
190 update_ob_speed (ob);
191
192 ob->carrying = sum_weight (ob);
193 link_player_skills (ob);
194
195 if (!legal_range (ob, shoottype))
196 shoottype = range_none;
197
198 assign (title, ob->arch->clone.name);
199
200 /* can_use_shield is a new flag. However, the can_use.. seems to largely come
201 * from the class, and not race. I don't see any way to get the class information
202 * to then update this. I don't think this will actually break anything - anyone
203 * that can use armour should be able to use a shield. What this may 'break'
204 * are features new characters get, eg, if someone starts up with a Q, they
205 * should be able to use a shield. However, old Q's won't get that advantage.
224 */ 206 */
225 p->clear (); 207 if (QUERY_FLAG (ob, FLAG_USE_ARMOUR))
208 SET_FLAG (ob, FLAG_USE_SHIELD);
226 209
210 /* if it's a dragon player, set the correct title here */
211 if (is_dragon_pl (ob))
212 {
213 object *tmp, *abil = 0, *skin = 0;
214
215 shstr_cmp dragon_ability_force ("dragon_ability_force");
216 shstr_cmp dragon_skin_force ("dragon_skin_force");
217
218 for (tmp = ob->inv; tmp; tmp = tmp->below)
219 if (tmp->type == FORCE)
220 if (tmp->arch->name == dragon_ability_force)
221 abil = tmp;
222 else if (tmp->arch->name == dragon_skin_force)
223 skin = tmp;
224
225 set_dragon_name (ob, abil, skin);
226 }
227
228 CLEAR_FLAG (ob, FLAG_FRIENDLY);
229 add_friendly_object (ob);
230
231 LOG (llevInfo, "LOGIN: Player named %s from ip %s\n", &ob->name, ns->host);
232
233 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
234 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &ob->name);
235
236 ns->floorbox_update ();
237
238 esrv_new_player (this, ob->weight + ob->carrying);
239 esrv_send_inventory (ob, ob);
240 esrv_add_spells (this, 0);
241
242 enter_exit (ob, 0);
243
244// send_rules (ob);//TODO
245// send_news (ob);//TODO
246// display_motd (ob);//TODO
247 INVOKE_PLAYER (LOGIN, this);
248}
249
250// the need for this function can be explained
251// by load_object not returning the object
252void
253player::set_object (object *op)
254{
255 ob = op;
256 ob->contr = this; /* this aren't yet in archetype */
257
258 ob->speed_left = 0.5;
259 ob->speed = 1.0;
260 ob->direction = 5; /* So player faces south */
261 ob->stats.wc = 2;
262 ob->run_away = 25; /* Then we panick... */
263
264 set_first_map (ob);
265
266 ob->roll_stats ();
267}
268
269player::player ()
270{
227 /* There are some elements we want initialized to non zero value - 271 /* There are some elements we want initialized to non zero value -
228 * we deal with that below this point. 272 * we deal with that below this point.
229 */ 273 */
230 p->party = NULL;
231 p->outputs_sync = 16; /* Every 2 seconds */ 274 outputs_sync = 16; /* Every 2 seconds */
232 p->outputs_count = 8; /* Keeps present behaviour */ 275 outputs_count = 8; /* Keeps present behaviour */
233 p->unapply = unapply_nochoice; 276 unapply = unapply_nochoice;
234 p->Swap_First = -1;
235 277
236#ifdef AUTOSAVE
237 p->last_save_tick = 9999999;
238#endif
239
240 strcpy (p->savebed_map, first_map_path); /* Init. respawn position */ 278 assign (savebed_map, first_map_path); /* Init. respawn position */
241 279
242 op->contr = p; /* this aren't yet in archetype */
243 p->ob = op;
244 op->speed_left = 0.5;
245 op->speed = 1.0;
246 op->direction = 5; /* So player faces south */
247 op->stats.wc = 2;
248 op->run_away = 25; /* Then we panick... */
249
250 {
251 int oldmon = p->ns->monitor_spells; // what a hack
252 p->ns->monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */
253 roll_stats (op);
254 p->ns->monitor_spells = oldmon;
255 }
256 p->ns->state = ST_ROLL_STAT;
257 clear_los (op);
258
259 p->gen_sp_armour = 10; 280 gen_sp_armour = 10;
260 p->last_speed = -1; 281 last_speed = -1;
261 p->shoottype = range_none; 282 shoottype = range_none;
262 p->bowtype = bow_normal; 283 bowtype = bow_normal;
263 p->petmode = pet_normal; 284 petmode = pet_normal;
264 p->listening = 10; 285 listening = 10;
265 p->usekeys = containers; 286 usekeys = containers;
266 p->last_weapon_sp = -1; 287 last_weapon_sp = -1;
267 p->peaceful = 1; /* default peaceful */ 288 peaceful = 1; /* default peaceful */
268 p->do_los = 1; 289 do_los = 1;
269 p->explore = 0;
270
271 assign (p->title, op->arch->clone.name);
272 op->race = op->arch->clone.race;
273
274 CLEAR_FLAG (op, FLAG_READY_SKILL);
275 290
276 /* we need to clear these to -1 and not zero - otherwise, 291 /* we need to clear these to -1 and not zero - otherwise,
277 * if a player quits and starts a new character, we wont 292 * if a player quits and starts a new character, we wont
278 * send new values to the client, as things like exp start 293 * send new values to the client, as things like exp start
279 * at zero. 294 * at zero.
280 */ 295 */
281 for (i = 0; i < NUM_SKILLS; i++) 296 for (int i = 0; i < NUM_SKILLS; i++)
282 {
283 p->last_skill_exp[i] = -1; 297 last_skill_exp[i] = -1;
284 p->last_skill_ob[i] = NULL;
285 }
286 298
287 for (i = 0; i < NROFATTACKS; i++) 299 for (int i = 0; i < NROFATTACKS; i++)
288 p->last_resist[i] = -1; 300 last_resist[i] = -1;
289 301
290 p->last_stats.exp = -1; 302 last_stats.exp = -1;
291 p->last_weight = (uint32) - 1; 303 last_weight = (uint32) - 1;
292
293 p->ns->update_look = 0;
294 p->ns->look_position = 0;
295
296 return p;
297} 304}
298 305
299/* This loads the first map an puts the player on it. */ 306player::~player ()
300static void
301set_first_map (object *op)
302{ 307{
303 strcpy (op->contr->maplevel, first_map_path); 308 terminate_all_pets (ob);
304 op->x = -1;
305 op->y = -1;
306 enter_exit (op, 0);
307}
308 309
310 if (first_player != this)
311 {
312 player *prev = first_player;
313
314 while (prev && prev->next && prev->next != this)
315 prev = prev->next;
316
317 if (prev->next != this)
318 {
319 LOG (llevError, "Free_player: Can't find previous player.\n");
320 abort ();
321 }
322
323 prev->next = next;
324 }
325 else
326 first_player = next;
327
328 if (ob)
329 {
330 ob->contr = 0;
331 ob->destroy (1);
332 }
333
334 if (ns)
335 {
336 ns->send_packet ("goodbye");
337 ns->flush ();
338 ns->pl = 0;
339 ns->destroy ();
340 }
341
342 /* Clear item stack */
343 free (stack_items);
344}
345
309/* Tries to add player on the connection passwd in ns. 346/* Tries to add player on the connection passed in ns.
310 * All we can really get in this is some settings like host and display 347 * All we can really get in this is some settings like host and display
311 * mode. 348 * mode.
312 */ 349 */
313 350player *
314int 351player::create ()
315add_player (client *ns)
316{ 352{
317 player *p = new player; 353 player *pl = new player;
318 354
319 p->ns = ns; 355 pl->set_object (arch_to_object (get_player_archetype (0)));
320 ns->pl = p;
321 356
322 p->next = first_player;
323 first_player = p;
324
325 p = get_player (p);
326
327 set_first_map (p->ob);
328
329 CLEAR_FLAG (p->ob, FLAG_FRIENDLY);
330 add_friendly_object (p->ob);
331 send_rules (p->ob);
332 send_news (p->ob);
333 display_motd (p->ob);
334
335 get_name (p->ob);
336
337 return 0; 357 return pl;
338} 358}
339 359
340/* 360/*
341 * get_player_archetype() return next player archetype from archetype 361 * get_player_archetype() return next player archetype from archetype
342 * list. Not very efficient routine, but used only creating new players. 362 * list. Not very efficient routine, but used only creating new players.
448 * circling behaviour. Unfortunately, this function is also used to determined 468 * circling behaviour. Unfortunately, this function is also used to determined
449 * if the creature should cast a spell, so returning a direction in that case 469 * if the creature should cast a spell, so returning a direction in that case
450 * is probably not a good thing. 470 * is probably not a good thing.
451 */ 471 */
452#define MAX_SPACES 50 472#define MAX_SPACES 50
453
454 473
455/* 474/*
456 * Returns the direction to the player, if valid. Returns 0 otherwise. 475 * Returns the direction to the player, if valid. Returns 0 otherwise.
457 * modified to verify there is a path to the player. Does this by stepping towards 476 * modified to verify there is a path to the player. Does this by stepping towards
458 * player and if path is blocked then see if blockage is close enough to player that 477 * player and if path is blocked then see if blockage is close enough to player that
697 /* Need to set up the skill pointers */ 716 /* Need to set up the skill pointers */
698 link_player_skills (pl); 717 link_player_skills (pl);
699} 718}
700 719
701void 720void
702get_name (object *op)
703{
704 op->contr->write_buf[0] = '\0';
705 op->contr->ns->state = ST_GET_NAME;
706 send_query (op->contr->ns, 0, "What is your name?\n:");
707}
708
709void
710get_password (object *op)
711{
712 op->contr->write_buf[0] = '\0';
713 op->contr->ns->state = ST_GET_PASSWORD;
714 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is your password?\n:");
715}
716
717void
718play_again (object *op)
719{
720 op->contr->ns->state = ST_PLAY_AGAIN;
721 op->chosen_skill = NULL;
722 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?");
723 /* a bit of a hack, but there are various places early in th
724 * player creation process that a user can quit (eg, roll
725 * stats) that isn't removing the player. Taking a quick
726 * look, there are many places that call play_again without
727 * removing the player - it probably makes more sense
728 * to leave it to play_again to remove the object in all
729 * cases.
730 */
731 if (!QUERY_FLAG (op, FLAG_REMOVED))
732 op->remove ();
733
734 /* Need to set this to null - otherwise, it could point to garbage,
735 * and draw() doesn't check to see if the player is removed, only if
736 * the map is null or not swapped out.
737 */
738 op->map = NULL;
739}
740
741int
742receive_play_again (object *op, char key)
743{
744 if (key == 'q' || key == 'Q')
745 {
746 remove_friendly_object (op);
747 leave (op->contr, 0); /* ericserver will draw the message */
748 return 2;
749 }
750 else if (key == 'a' || key == 'A')
751 {
752 player *pl = op->contr;
753 shstr name = op->name;
754
755 op->contr = 0;
756 op->type = 0;
757 op->destroy (1);
758 pl = get_player (pl);
759 op = pl->ob;
760 add_friendly_object (op);
761 op->contr->password[0] = '~';
762 op->name = op->name_pl = 0;
763 /* Lets put a space in here */
764 new_draw_info (NDI_UNIQUE, 0, op, "\n");
765 get_name (op);
766 op->name = op->name_pl = name;
767 set_first_map (op);
768 }
769 else
770 /* user pressed something else so just ask again... */
771 play_again (op);
772
773 return 0;
774}
775
776void
777confirm_password (object *op)
778{
779
780 op->contr->write_buf[0] = '\0';
781 op->contr->ns->state = ST_CONFIRM_PASSWORD;
782 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "Please type your password again.\n:");
783}
784
785void
786get_party_password (object *op, partylist *party) 721get_party_password (object *op, partylist *party)
787{ 722{
788 if (party == NULL) 723 if (party == NULL)
789 { 724 {
790 LOG (llevError, "get_party_password(): tried to make player %s join a NULL party", &op->name); 725 LOG (llevError, "get_party_password(): tried to make player %s join a NULL party", &op->name);
791 return; 726 return;
792 } 727 }
728
793 op->contr->write_buf[0] = '\0'; 729 op->contr->write_buf[0] = '\0';
794 op->contr->ns->state = ST_GET_PARTY_PASSWORD; 730 op->contr->ns->state = ST_GET_PARTY_PASSWORD;
795 op->contr->party_to_join = party; 731 op->contr->party_to_join = party;
796 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:"); 732 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:");
797} 733}
798 734
799
800/* This rolls four 1-6 rolls and sums the best 3 of the 4. */ 735/* This rolls four 1-6 rolls and sums the best 3 of the 4. */
801int 736static int
802roll_stat (void) 737roll_stat (void)
803{ 738{
804 int a[4], i, j, k; 739 int a[4], i, j, k;
805 740
806 for (i = 0; i < 4; i++) 741 for (i = 0; i < 4; i++)
809 for (i = 0, j = 0, k = 7; i < 4; i++) 744 for (i = 0, j = 0, k = 7; i < 4; i++)
810 if (a[i] < k) 745 if (a[i] < k)
811 k = a[i], j = i; 746 k = a[i], j = i;
812 747
813 for (i = 0, k = 0; i < 4; i++) 748 for (i = 0, k = 0; i < 4; i++)
814 {
815 if (i != j) 749 if (i != j)
816 k += a[i]; 750 k += a[i];
817 } 751
818 return k; 752 return k;
819} 753}
820 754
821void 755void
822roll_stats (object *op) 756object::roll_stats ()
823{ 757{
824 int sum = 0;
825 int i = 0, j = 0;
826 int statsort[7]; 758 int statsort [7];
827 759
828 do 760 for (;;)
829 {
830 op->stats.Str = roll_stat ();
831 op->stats.Dex = roll_stat ();
832 op->stats.Int = roll_stat ();
833 op->stats.Con = roll_stat ();
834 op->stats.Wis = roll_stat ();
835 op->stats.Pow = roll_stat ();
836 op->stats.Cha = roll_stat ();
837 sum = op->stats.Str + op->stats.Dex + op->stats.Int + op->stats.Con + op->stats.Wis + op->stats.Pow + op->stats.Cha;
838 } 761 {
839 while (sum < 82 || sum > 116); 762 int sum = 0;
763 for (int i = 7; i--; )
764 sum += statsort [i] = roll_stat ();
840 765
766 if (sum >= 82 && sum <= 116)
767 break;
768 }
769
841 /* Sort the stats so that rerolling is easier... */ 770 // Sort the stats so that rerolling is easier...
842 statsort[0] = op->stats.Str; 771 std::sort (statsort, statsort + 7, std::greater<int>());
843 statsort[1] = op->stats.Dex;
844 statsort[2] = op->stats.Int;
845 statsort[3] = op->stats.Con;
846 statsort[4] = op->stats.Wis;
847 statsort[5] = op->stats.Pow;
848 statsort[6] = op->stats.Cha;
849 772
850 /* a quick and dirty bubblesort? */
851 do
852 {
853 if (statsort[i] < statsort[i + 1])
854 {
855 j = statsort[i];
856 statsort[i] = statsort[i + 1];
857 statsort[i + 1] = j;
858 i = 0;
859 }
860 else
861 {
862 i++;
863 }
864 }
865 while (i < 6);
866
867 op->stats.Str = statsort[0]; 773 stats.Str = statsort[0];
868 op->stats.Dex = statsort[1]; 774 stats.Dex = statsort[1];
869 op->stats.Con = statsort[2]; 775 stats.Con = statsort[2];
870 op->stats.Int = statsort[3]; 776 stats.Int = statsort[3];
871 op->stats.Wis = statsort[4]; 777 stats.Wis = statsort[4];
872 op->stats.Pow = statsort[5]; 778 stats.Pow = statsort[5];
873 op->stats.Cha = statsort[6]; 779 stats.Cha = statsort[6];
874 780
875
876 op->contr->orig_stats.Str = op->stats.Str;
877 op->contr->orig_stats.Dex = op->stats.Dex;
878 op->contr->orig_stats.Int = op->stats.Int;
879 op->contr->orig_stats.Con = op->stats.Con;
880 op->contr->orig_stats.Wis = op->stats.Wis;
881 op->contr->orig_stats.Pow = op->stats.Pow;
882 op->contr->orig_stats.Cha = op->stats.Cha;
883
884 op->level = 1;
885 op->stats.exp = 0; 781 stats.exp = 0;
886 op->stats.ac = 0; 782 stats.ac = 0;
887 783
888 op->contr->levhp[1] = 9;
889 op->contr->levsp[1] = 6;
890 op->contr->levgrace[1] = 3;
891
892 fix_player (op);
893 op->stats.hp = op->stats.maxhp; 784 stats.hp = stats.maxhp;
894 op->stats.sp = op->stats.maxsp; 785 stats.sp = stats.maxsp;
895 op->stats.grace = op->stats.maxgrace; 786 stats.grace = stats.maxgrace;
787
788 if (contr)
789 {
790 contr->levhp[1] = 9;
791 contr->levsp[1] = 6;
792 contr->levgrace[1] = 3;
793
896 op->contr->orig_stats = op->stats; 794 contr->orig_stats = stats;
795 }
897} 796}
898 797
899void 798void
900Roll_Again (object *op) 799object::swap_stats (int a, int b)
901{ 800{
902 esrv_new_player (op->contr, 0);
903 send_query (op->contr->ns, CS_QUERY_SINGLECHAR,
904 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? ");
905}
906
907void
908Swap_Stat (object *op, int Swap_Second)
909{
910 signed char tmp;
911 char buf[MAX_BUF];
912
913 if (op->contr->Swap_First == -1)
914 {
915 new_draw_info (NDI_UNIQUE, 0, op, "How the hell did you get here?!?!!!");
916 new_draw_info (NDI_UNIQUE, 0, op, "Error in Swap_Stat code,");
917 new_draw_info (NDI_UNIQUE, 0, op, "mail korg@rdt.monash.edu.au");
918 return;
919 }
920
921 tmp = get_attr_value (&op->contr->orig_stats, op->contr->Swap_First); 801 int tmp = get_attr_value (&contr->orig_stats, a);
922
923 set_attr_value (&op->contr->orig_stats, op->contr->Swap_First, get_attr_value (&op->contr->orig_stats, Swap_Second)); 802 set_attr_value (&contr->orig_stats, a, get_attr_value (&contr->orig_stats, b));
924
925 set_attr_value (&op->contr->orig_stats, Swap_Second, tmp); 803 set_attr_value (&contr->orig_stats, b, tmp);
926 804
927 sprintf (buf, "%s done\n", short_stat_name[Swap_Second]);
928 new_draw_info (NDI_UNIQUE, 0, op, buf);
929 op->stats.Str = op->contr->orig_stats.Str; 805 stats.Str = contr->orig_stats.Str;
930 op->stats.Dex = op->contr->orig_stats.Dex; 806 stats.Dex = contr->orig_stats.Dex;
931 op->stats.Con = op->contr->orig_stats.Con; 807 stats.Con = contr->orig_stats.Con;
932 op->stats.Int = op->contr->orig_stats.Int; 808 stats.Int = contr->orig_stats.Int;
933 op->stats.Wis = op->contr->orig_stats.Wis; 809 stats.Wis = contr->orig_stats.Wis;
934 op->stats.Pow = op->contr->orig_stats.Pow; 810 stats.Pow = contr->orig_stats.Pow;
935 op->stats.Cha = op->contr->orig_stats.Cha; 811 stats.Cha = contr->orig_stats.Cha;
812
813 //TODO: the following code looks so borked and should, at the very least,
814 // be merged with the similar code in roll_stats
936 op->stats.ac = 0; 815 stats.ac = 0;
937 816
938 op->level = 1; 817 level = 1;
939 op->stats.exp = 0; 818 stats.exp = 0;
940 op->stats.ac = 0; 819 stats.ac = 0;
941 820
942 op->contr->levhp[1] = 9;
943 op->contr->levsp[1] = 6;
944 op->contr->levgrace[1] = 3;
945
946 fix_player (op);
947 op->stats.hp = op->stats.maxhp; 821 stats.hp = stats.maxhp;
948 op->stats.sp = op->stats.maxsp; 822 stats.sp = stats.maxsp;
949 op->stats.grace = op->stats.maxgrace; 823 stats.grace = stats.maxgrace;
824
825 if (contr)
826 {
827 contr->levhp[1] = 9;
828 contr->levsp[1] = 6;
829 contr->levgrace[1] = 3;
830
950 op->contr->orig_stats = op->stats; 831 contr->orig_stats = stats;
951 op->contr->Swap_First = -1;
952}
953
954
955/* This code has been greatly reduced, because with set_attr_value
956 * and get_attr_value, the stats can be accessed just numeric
957 * ids. stat_trans is a table that translate the number entered
958 * into the actual stat. It is needed because the order the stats
959 * are displayed in the stat window is not the same as how
960 * the number's access that stat. The table does that translation.
961 */
962int
963key_roll_stat (object *op, char key)
964{
965 int keynum = key - '0';
966 char buf[MAX_BUF];
967 static sint8 stat_trans[] = { -1, STR, DEX, CON, INT, WIS, POW, CHA };
968
969 if (keynum > 0 && keynum <= 7)
970 { 832 }
971 if (op->contr->Swap_First == -1)
972 {
973 op->contr->Swap_First = stat_trans[keynum];
974 sprintf (buf, "%s ->", short_stat_name[stat_trans[keynum]]);
975 new_draw_info (NDI_UNIQUE, 0, op, buf);
976 }
977 else
978 Swap_Stat (op, stat_trans[keynum]);
979
980 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "");
981 return 1;
982 }
983 switch (key)
984 {
985 case 'n':
986 case 'N':
987 {
988 SET_FLAG (op, FLAG_WIZ);
989 if (op->map == NULL)
990 {
991 LOG (llevError, "Map == NULL in state 2\n");
992 break;
993 }
994
995#if 0
996 /* So that enter_exit will put us at startx/starty */
997 op->x = -1;
998
999 enter_exit (op, NULL);
1000#endif
1001 SET_ANIMATION (op, 2); /* So player faces south */
1002 /* Enter exit adds a player otherwise */
1003 add_statbonus (op);
1004 send_query (op->contr->ns, CS_QUERY_SINGLECHAR,
1005 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n");
1006 op->contr->ns->state = ST_CHANGE_CLASS;
1007 if (op->msg)
1008 new_draw_info (NDI_BLUE, 0, op, op->msg);
1009 return 0;
1010 }
1011 case 'y':
1012 case 'Y':
1013 roll_stats (op);
1014 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "");
1015 return 1;
1016
1017 case 'q':
1018 case 'Q':
1019 play_again (op);
1020 return 1;
1021
1022 default:
1023 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1024 return 0;
1025 }
1026 return 0;
1027} 833}
1028 834
1029/* This function takes the key that is passed, and does the 835/* This function takes the key that is passed, and does the
1030 * appropriate action with it (change race, or other things). 836 * appropriate action with it (change race, or other things).
1031 * The function name is for historical reasons - now we have 837 * The function name is for historical reasons - now we have
1032 * separate race and class; this actually changes the RACE, 838 * separate race and class; this actually changes the RACE,
1033 * not the class. 839 * not the class.
1034 */ 840 */
1035
1036int 841int
1037key_change_class (object *op, char key) 842key_change_class (object *op, char key)
1038{ 843{
1039 int tmp_loop; 844 int tmp_loop;
1040 845
1041 if (key == 'q' || key == 'Q')
1042 {
1043 op->remove ();
1044 play_again (op);
1045 return 0;
1046 }
1047 if (key == 'd' || key == 'D') 846 if (key == 'd' || key == 'D')
1048 { 847 {
1049 char buf[MAX_BUF]; 848 char buf[MAX_BUF];
1050 849
1051 /* this must before then initial items are given */ 850 /* this must before then initial items are given */
1075 start_info (op); 874 start_info (op);
1076 CLEAR_FLAG (op, FLAG_WIZ); 875 CLEAR_FLAG (op, FLAG_WIZ);
1077 give_initial_items (op, op->randomitems); 876 give_initial_items (op, op->randomitems);
1078 link_player_skills (op); 877 link_player_skills (op);
1079 esrv_send_inventory (op, op); 878 esrv_send_inventory (op, op);
1080 fix_player (op); 879 op->update_stats ();
1081 880
1082 /* This moves the player to a different start map, if there 881 /* This moves the player to a different start map, if there
1083 * is one for this race 882 * is one for this race
1084 */ 883 */
1085 if (*first_map_ext_path) 884 if (*first_map_ext_path)
1111 while (!tmp_loop) 910 while (!tmp_loop)
1112 { 911 {
1113 shstr name = op->name; 912 shstr name = op->name;
1114 int x = op->x, y = op->y; 913 int x = op->x, y = op->y;
1115 914
1116 remove_statbonus (op); 915 op->remove_statbonus ();
1117 op->remove (); 916 op->remove ();
1118 op->arch = get_player_archetype (op->arch); 917 op->arch = get_player_archetype (op->arch);
1119 op->arch->clone.copy_to (op); 918 op->arch->clone.copy_to (op);
1120 op->instantiate (); 919 op->instantiate ();
1121 op->stats = op->contr->orig_stats; 920 op->stats = op->contr->orig_stats;
1123 op->x = x; 922 op->x = x;
1124 op->y = y; 923 op->y = y;
1125 SET_ANIMATION (op, 2); /* So player faces south */ 924 SET_ANIMATION (op, 2); /* So player faces south */
1126 insert_ob_in_map (op, op->map, op, 0); 925 insert_ob_in_map (op, op->map, op, 0);
1127 assign (op->contr->title, op->arch->clone.name); 926 assign (op->contr->title, op->arch->clone.name);
1128 add_statbonus (op); 927 op->add_statbonus ();
1129 tmp_loop = allowed_class (op); 928 tmp_loop = allowed_class (op);
1130 } 929 }
1131 930
1132 update_object (op, UP_OBJ_FACE); 931 update_object (op, UP_OBJ_FACE);
1133 esrv_update_item (UPD_FACE, op, op); 932 esrv_update_item (UPD_FACE, op, op);
1134 fix_player (op); 933 op->update_stats ();
1135 op->stats.hp = op->stats.maxhp; 934 op->stats.hp = op->stats.maxhp;
1136 op->stats.sp = op->stats.maxsp; 935 op->stats.sp = op->stats.maxsp;
1137 op->stats.grace = 0; 936 op->stats.grace = 0;
1138 937
1139 if (op->msg) 938 if (op->msg)
1144} 943}
1145 944
1146int 945int
1147key_confirm_quit (object *op, char key) 946key_confirm_quit (object *op, char key)
1148{ 947{
1149 char buf[MAX_BUF];
1150
1151 if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q') 948 if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q')
1152 { 949 {
1153 op->contr->ns->state = ST_PLAYING; 950 op->contr->ns->state = ST_PLAYING;
1154 new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play."); 951 new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play.");
1155 return 1; 952 return 1;
1163 op->direction = 0; 960 op->direction = 0;
1164 new_draw_info_format (NDI_UNIQUE | NDI_ALL, 5, NULL, "%s quits the game.", &op->name); 961 new_draw_info_format (NDI_UNIQUE | NDI_ALL, 5, NULL, "%s quits the game.", &op->name);
1165 962
1166 strcpy (op->contr->killer, "quit"); 963 strcpy (op->contr->killer, "quit");
1167 check_score (op); 964 check_score (op);
1168 op->contr->party = NULL; 965 op->contr->party = 0;
1169 if (settings.set_title == TRUE)
1170 op->contr->own_title[0] = '\0'; 966 op->contr->own_title[0] = '\0';
1171 967
1172 if (!QUERY_FLAG (op, FLAG_WAS_WIZ)) 968 object_ptr ob = op;
1173 {
1174 maptile *mp, *next;
1175 969
970 delete ob->contr;
971
1176 /* We need to hunt for any per player unique maps in memory and 972 /* We need to hunt for any per player unique maps in memory and
1177 * get rid of them. The trailing slash in the path is intentional, 973 * get rid of them. The trailing slash in the path is intentional,
1178 * so that players named 'Ab' won't match against players 'Abe' pathname 974 * so that players named 'Ab' won't match against players 'Abe' pathname
1179 */ 975 */
976 char buf[MAX_BUF];
1180 sprintf (buf, "%s/%s/%s/", settings.localdir, settings.playerdir, &op->name); 977 sprintf (buf, "%s/%s/%s/", settings.localdir, settings.playerdir, &op->name);
1181 for (mp = first_map; mp != NULL; mp = next) 978
1182 { 979 for (maptile *next, *mp = first_map; mp; mp = next)
980 {
1183 next = mp->next; 981 next = mp->next;
982
1184 if (!strncmp (mp->path, buf, strlen (buf))) 983 if (!strncmp (mp->path, buf, strlen (buf)))
1185 delete_map (mp); 984 delete_map (mp);
1186 } 985 }
1187 986
1188 delete_character (op->name, 1); 987 delete_character (ob->name, 1);
1189 }
1190 988
1191 play_again (op);
1192 return 1; 989 return 1;
1193} 990}
1194 991
1195void 992void
1196flee_player (object *op) 993flee_player (object *op)
1886 arrow->y = sy; 1683 arrow->y = sy;
1887 1684
1888 if (op->type == PLAYER) 1685 if (op->type == PLAYER)
1889 { 1686 {
1890 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed; 1687 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed;
1891 fix_player (op); 1688 op->update_stats ();
1892 } 1689 }
1893 1690
1894 SET_ANIMATION (arrow, arrow->direction); 1691 SET_ANIMATION (arrow, arrow->direction);
1895 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ 1692 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */
1896 arrow->stats.hp = arrow->stats.dam; 1693 arrow->stats.hp = arrow->stats.dam;
2605 op->stats.hp = op->stats.maxhp; 2402 op->stats.hp = op->stats.maxhp;
2606 2403
2607 if (op->stats.food < 0) 2404 if (op->stats.food < 0)
2608 op->stats.food = 999; 2405 op->stats.food = 999;
2609 2406
2610 fix_player (op); 2407 op->update_stats ();
2611 return 1; 2408 return 1;
2612 } 2409 }
2613 2410
2614 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2411 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2615 CLEAR_FLAG (op, FLAG_LIFESAVE); 2412 CLEAR_FLAG (op, FLAG_LIFESAVE);
3018 x = op->x; 2815 x = op->x;
3019 y = op->y; 2816 y = op->y;
3020 map = op->map; 2817 map = op->map;
3021 2818
3022 2819
3023 if (settings.not_permadeth == TRUE)
3024 {
3025 /* NOT_PERMADEATH code. This basically brings the character back to 2820 /* NOT_PERMADEATH code. This basically brings the character back to
3026 * life if they are dead - it takes some exp and a random stat. 2821 * life if they are dead - it takes some exp and a random stat.
3027 * See the config.h file for a little more in depth detail about this. 2822 * See the config.h file for a little more in depth detail about this.
3028 */ 2823 */
3029 2824
3030 /* Basically two ways to go - remove a stat permanently, or just 2825 /* Basically two ways to go - remove a stat permanently, or just
3031 * make it depletion. This bunch of code deals with that aspect 2826 * make it depletion. This bunch of code deals with that aspect
3032 * of death. 2827 * of death.
3033 */ 2828 */
3034#ifndef COZY_SERVER 2829#ifndef COZY_SERVER
3035 if (settings.balanced_stat_loss) 2830 if (settings.balanced_stat_loss)
3036 { 2831 {
3037 /* If stat loss is permanent, lose one stat only. */ 2832 /* If stat loss is permanent, lose one stat only. */
3038 /* Lower level chars don't lose as many stats because they suffer 2833 /* Lower level chars don't lose as many stats because they suffer
3039 more if they do. */ 2834 more if they do. */
3040 /* Higher level characters can afford things such as potions of 2835 /* Higher level characters can afford things such as potions of
3041 restoration, or better, stat potions. So we slug them that 2836 restoration, or better, stat potions. So we slug them that
3042 little bit harder. */ 2837 little bit harder. */
3043 /* GD */ 2838 /* GD */
3044 if (settings.stat_loss_on_death) 2839 if (settings.stat_loss_on_death)
3045 num_stats_lose = 1; 2840 num_stats_lose = 1;
3046 else
3047 num_stats_lose = 1 + op->level / BALSL_NUMBER_LOSSES_RATIO;
3048 }
3049 else 2841 else
3050 { 2842 num_stats_lose = 1 + op->level / BALSL_NUMBER_LOSSES_RATIO;
2843 }
2844 else
2845 {
3051 num_stats_lose = 1; 2846 num_stats_lose = 1;
3052 } 2847 }
3053 lost_a_stat = 0; 2848 lost_a_stat = 0;
3054 2849
3055 for (z = 0; z < num_stats_lose; z++) 2850 for (z = 0; z < num_stats_lose; z++)
3056 { 2851 {
3057 i = RANDOM () % NUM_STATS; 2852 i = RANDOM () % NUM_STATS;
3058 2853
3059 if (settings.stat_loss_on_death) 2854 if (settings.stat_loss_on_death)
3060 { 2855 {
3061 /* Pick a random stat and take a point off it. Tell the player 2856 /* Pick a random stat and take a point off it. Tell the player
3062 * what he lost. 2857 * what he lost.
3063 */ 2858 */
3064 change_attr_value (&(op->stats), i, -1); 2859 change_attr_value (&(op->stats), i, -1);
3065 check_stat_bounds (&(op->stats)); 2860 check_stat_bounds (&(op->stats));
3066 change_attr_value (&(op->contr->orig_stats), i, -1); 2861 change_attr_value (&(op->contr->orig_stats), i, -1);
3067 check_stat_bounds (&(op->contr->orig_stats)); 2862 check_stat_bounds (&(op->contr->orig_stats));
3068 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]); 2863 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]);
3069 lost_a_stat = 1; 2864 lost_a_stat = 1;
2865 }
2866 else
2867 {
2868 /* deplete a stat */
2869 archetype *deparch = archetype::find ("depletion");
2870 object *dep;
2871
2872 dep = present_arch_in_ob (deparch, op);
2873 if (!dep)
2874 {
2875 dep = arch_to_object (deparch);
2876 insert_ob_in_ob (dep, op);
3070 } 2877 }
3071 else 2878 lose_this_stat = 1;
2879 if (settings.balanced_stat_loss)
3072 { 2880 {
3073 /* deplete a stat */ 2881 /* GD */
3074 archetype *deparch = archetype::find ("depletion"); 2882 /* Get the stat that we're about to deplete. */
3075 object *dep; 2883 this_stat = get_attr_value (&(dep->stats), i);
3076 2884 if (this_stat < 0)
3077 dep = present_arch_in_ob (deparch, op);
3078 if (!dep)
3079 { 2885 {
3080 dep = arch_to_object (deparch); 2886 int loss_chance = 1 + op->level / BALSL_LOSS_CHANCE_RATIO;
3081 insert_ob_in_ob (dep, op); 2887 int keep_chance = this_stat * this_stat;
3082 } 2888
3083 lose_this_stat = 1; 2889 /* Yes, I am paranoid. Sue me. */
3084 if (settings.balanced_stat_loss)
3085 {
3086 /* GD */
3087 /* Get the stat that we're about to deplete. */
3088 this_stat = get_attr_value (&(dep->stats), i);
3089 if (this_stat < 0) 2890 if (keep_chance < 1)
2891 keep_chance = 1;
2892
2893 /* There is a maximum depletion total per level. */
2894 if (this_stat < -1 - op->level / BALSL_MAX_LOSS_RATIO)
3090 { 2895 {
3091 int loss_chance = 1 + op->level / BALSL_LOSS_CHANCE_RATIO;
3092 int keep_chance = this_stat * this_stat;
3093
3094 /* Yes, I am paranoid. Sue me. */
3095 if (keep_chance < 1)
3096 keep_chance = 1;
3097
3098 /* There is a maximum depletion total per level. */
3099 if (this_stat < -1 - op->level / BALSL_MAX_LOSS_RATIO)
3100 {
3101 lose_this_stat = 0; 2896 lose_this_stat = 0;
3102 /* Take loss chance vs keep chance to see if we 2897 /* Take loss chance vs keep chance to see if we
3103 retain the stat. */ 2898 retain the stat. */
3104 }
3105 else
3106 {
3107 if (random_roll (0, loss_chance + keep_chance - 1, op, PREFER_LOW) < keep_chance)
3108 lose_this_stat = 0;
3109 /* LOG(llevDebug, "Determining stat loss. Stat: %d Keep: %d Lose: %d Result: %s.\n",
3110 this_stat, keep_chance, loss_chance,
3111 lose_this_stat?"LOSE":"KEEP"); */
3112 }
3113 } 2899 }
3114 }
3115
3116 if (lose_this_stat)
3117 {
3118 this_stat = get_attr_value (&(dep->stats), i);
3119 /* We could try to do something clever like find another
3120 * stat to reduce if this fails. But chances are, if
3121 * stats have been depleted to -50, all are pretty low
3122 * and should be roughly the same, so it shouldn't make a
3123 * difference.
3124 */ 2900 else
3125 if (this_stat >= -50)
3126 { 2901 {
3127 change_attr_value (&(dep->stats), i, -1); 2902 if (random_roll (0, loss_chance + keep_chance - 1, op, PREFER_LOW) < keep_chance)
3128 SET_FLAG (dep, FLAG_APPLIED);
3129 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]);
3130 fix_player (op);
3131 lost_a_stat = 1; 2903 lose_this_stat = 0;
2904 /* LOG(llevDebug, "Determining stat loss. Stat: %d Keep: %d Lose: %d Result: %s.\n",
2905 this_stat, keep_chance, loss_chance,
2906 lose_this_stat?"LOSE":"KEEP"); */
3132 } 2907 }
3133 } 2908 }
3134 } 2909 }
2910
2911 if (lose_this_stat)
2912 {
2913 this_stat = get_attr_value (&(dep->stats), i);
2914 /* We could try to do something clever like find another
2915 * stat to reduce if this fails. But chances are, if
2916 * stats have been depleted to -50, all are pretty low
2917 * and should be roughly the same, so it shouldn't make a
2918 * difference.
2919 */
2920 if (this_stat >= -50)
2921 {
2922 change_attr_value (&(dep->stats), i, -1);
2923 SET_FLAG (dep, FLAG_APPLIED);
2924 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]);
2925 op->update_stats ();
2926 lost_a_stat = 1;
2927 }
3135 } 2928 }
2929 }
2930 }
3136 /* If no stat lost, tell the player. */ 2931 /* If no stat lost, tell the player. */
3137 if (!lost_a_stat) 2932 if (!lost_a_stat)
3138 { 2933 {
3139 /* determine_god() seems to not work sometimes... why is this? 2934 /* determine_god() seems to not work sometimes... why is this?
3140 Should I be using something else? GD */ 2935 Should I be using something else? GD */
3141 const char *god = determine_god (op); 2936 const char *god = determine_god (op);
3142 2937
3143 if (god && (strcmp (god, "none"))) 2938 if (god && (strcmp (god, "none")))
3144 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god); 2939 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god);
3145 else 2940 else
3146 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); 2941 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
3147 } 2942 }
3148#else 2943#else
3149 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely."); 2944 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3150#endif 2945#endif
3151 2946
3152 /* Put a gravestone up where the character 'almost' died. List the 2947 /* Put a gravestone up where the character 'almost' died. List the
3153 * exp loss on the stone. 2948 * exp loss on the stone.
3154 */ 2949 */
3155 tmp = arch_to_object (archetype::find ("gravestone")); 2950 tmp = arch_to_object (archetype::find ("gravestone"));
3156 sprintf (buf, "%s's gravestone", &op->name); 2951 sprintf (buf, "%s's gravestone", &op->name);
3157 tmp->name = buf; 2952 tmp->name = buf;
3158 sprintf (buf, "%s's gravestones", &op->name); 2953 sprintf (buf, "%s's gravestones", &op->name);
3159 tmp->name_pl = buf; 2954 tmp->name_pl = buf;
3160 sprintf (buf, "RIP\nHere rests the hero %s the %s,\n" "who was killed\n" "by %s.\n", &op->name, op->contr->title, op->contr->killer); 2955 sprintf (buf, "RIP\nHere rests the hero %s the %s,\n" "who was killed\n" "by %s.\n", &op->name, op->contr->title, op->contr->killer);
3161 tmp->msg = buf; 2956 tmp->msg = buf;
3162 tmp->x = op->x, tmp->y = op->y; 2957 tmp->x = op->x, tmp->y = op->y;
3163 insert_ob_in_map (tmp, op->map, NULL, 0); 2958 insert_ob_in_map (tmp, op->map, NULL, 0);
3164 2959
3165 /**************************************/ 2960 /**************************************/
3166 /* */ 2961 /* */
3167 /* Subtract the experience points, */ 2962 /* Subtract the experience points, */
3168 /* if we died cause of food, give us */ 2963 /* if we died cause of food, give us */
3169 /* food, and reset HP's... */ 2964 /* food, and reset HP's... */
3170 /* */ 2965 /* */
3171 /**************************************/ 2966 /**************************************/
3172 2967
3173 /* remove any poisoning and confusion the character may be suffering. */ 2968 /* remove any poisoning and confusion the character may be suffering. */
3174 /* restore player */ 2969 /* restore player */
3175 at = archetype::find ("poisoning"); 2970 at = archetype::find ("poisoning");
3176 tmp = present_arch_in_ob (at, op); 2971 tmp = present_arch_in_ob (at, op);
3177 2972
3178 if (tmp) 2973 if (tmp)
3179 { 2974 {
3180 tmp->destroy (); 2975 tmp->destroy ();
3181 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2976 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3182 } 2977 }
3183 2978
3184 at = archetype::find ("confusion"); 2979 at = archetype::find ("confusion");
3185 tmp = present_arch_in_ob (at, op); 2980 tmp = present_arch_in_ob (at, op);
3186 if (tmp) 2981 if (tmp)
3187 { 2982 {
3188 tmp->destroy (); 2983 tmp->destroy ();
3189 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2984 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3190 } 2985 }
3191 2986
3192 cure_disease (op, 0); /* remove any disease */ 2987 cure_disease (op, 0); /* remove any disease */
3193 2988
3194 /*add_exp(op, (op->stats.exp * -0.20)); */ 2989 /*add_exp(op, (op->stats.exp * -0.20)); */
3195 apply_death_exp_penalty (op); 2990 apply_death_exp_penalty (op);
3196 if (op->stats.food < 100) 2991 if (op->stats.food < 100)
3197 op->stats.food = 900; 2992 op->stats.food = 900;
3198 op->stats.hp = op->stats.maxhp; 2993 op->stats.hp = op->stats.maxhp;
3199 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp); 2994 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp);
3200 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace); 2995 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace);
3201 2996
3202 /* 2997 /*
3203 * Check to see if the player is in a shop. IF so, then check to see if 2998 * Check to see if the player is in a shop. IF so, then check to see if
3204 * the player has any unpaid items. If so, remove them and put them back 2999 * the player has any unpaid items. If so, remove them and put them back
3205 * in the map. 3000 * in the map.
3206 */ 3001 */
3207 3002
3208 if (is_in_shop (op)) 3003 if (is_in_shop (op))
3209 remove_unpaid_objects (op->inv, op); 3004 remove_unpaid_objects (op->inv, op);
3210 3005
3211 /****************************************/ 3006 /****************************************/
3212 /* */ 3007 /* */
3213 /* Move player to his current respawn- */ 3008 /* Move player to his current respawn- */
3214 /* position (usually last savebed) */ 3009 /* position (usually last savebed) */
3215 /* */ 3010 /* */
3216 /****************************************/ 3011 /****************************************/
3217 3012
3218 enter_player_savebed (op); 3013 enter_player_savebed (op);
3219 3014
3220 /* Save the player before inserting the force to reduce 3015 /* Save the player before inserting the force to reduce
3221 * chance of abuse. 3016 * chance of abuse.
3222 */ 3017 */
3223 op->contr->braced = 0; 3018 op->contr->braced = 0;
3224 save_player (op, 1); 3019 op->contr->save ();
3225 3020
3226 /* it is possible that the player has blown something up 3021 /* it is possible that the player has blown something up
3227 * at his savebed location, and that can have long lasting 3022 * at his savebed location, and that can have long lasting
3228 * spell effects. So first see if there is a spell effect 3023 * spell effects. So first see if there is a spell effect
3229 * on the space that might harm the player. 3024 * on the space that might harm the player.
3230 */ 3025 */
3231 will_kill_again = 0; 3026 will_kill_again = 0;
3232 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = tmp->above) 3027 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = tmp->above)
3233 if (tmp->type == SPELL_EFFECT) 3028 if (tmp->type == SPELL_EFFECT)
3234 will_kill_again |= tmp->attacktype; 3029 will_kill_again |= tmp->attacktype;
3235 3030
3236 if (will_kill_again) 3031 if (will_kill_again)
3237 { 3032 {
3238 object *force; 3033 object *force;
3239 int at; 3034 int at;
3240 3035
3241 force = get_archetype (FORCE_NAME); 3036 force = get_archetype (FORCE_NAME);
3242 /* 50 ticks should be enough time for the spell to abate */ 3037 /* 50 ticks should be enough time for the spell to abate */
3243 force->speed = 0.1; 3038 force->speed = 0.1;
3244 force->speed_left = -5.0; 3039 force->speed_left = -5.0;
3245 SET_FLAG (force, FLAG_APPLIED); 3040 SET_FLAG (force, FLAG_APPLIED);
3246 for (at = 0; at < NROFATTACKS; at++) 3041 for (at = 0; at < NROFATTACKS; at++)
3247 if (will_kill_again & (1 << at)) 3042 if (will_kill_again & (1 << at))
3248 force->resist[at] = 100; 3043 force->resist[at] = 100;
3249 3044
3250 insert_ob_in_ob (force, op); 3045 insert_ob_in_ob (force, op);
3251 fix_player (op); 3046 op->update_stats ();
3252 3047
3253 } 3048 }
3254 3049
3255 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); 3050 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED.");
3256 return;
3257 } /* NOT_PERMADETH */
3258 else
3259 {
3260 /* If NOT_PERMADETH is set, then the rest of this is not reachable. This
3261 * should probably be embedded in an else statement.
3262 */
3263
3264 op->contr->party = NULL;
3265 if (settings.set_title == TRUE)
3266 op->contr->own_title[0] = '\0';
3267 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf);
3268 check_score (op);
3269
3270 if (op->contr->ranges[range_golem])
3271 {
3272 remove_friendly_object (op->contr->ranges[range_golem]);
3273 op->contr->ranges[range_golem]->destroy ();
3274 op->contr->ranges[range_golem] = 0;
3275 }
3276
3277 loot_object (op); /* Remove some of the items for good */
3278 op->remove ();
3279 op->direction = 0;
3280
3281 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp)
3282 {
3283 delete_character (op->name, 0);
3284 if (settings.resurrection == TRUE)
3285 {
3286 /* save playerfile sans equipment when player dies
3287 ** then save it as player.pl.dead so that future resurrection
3288 ** type spells will work on them nicely
3289 */
3290 delete_character (op->name, 0);
3291 op->stats.hp = op->stats.maxhp;
3292 op->stats.food = 999;
3293
3294 /* set the location of where the person will reappear when */
3295 /* maybe resurrection code should fix map also */
3296 strcpy (op->contr->maplevel, settings.emergency_mapname);
3297 if (op->map != NULL)
3298 op->map = NULL;
3299 op->x = settings.emergency_x;
3300 op->y = settings.emergency_y;
3301 save_player (op, 0);
3302 op->map = map;
3303 /* please see resurrection.c: peterm */
3304 dead_player (op);
3305 }
3306 else
3307 delete_character (op->name, 1);
3308 }
3309
3310 play_again (op);
3311
3312 /* peterm: added to create a corpse at deathsite. */
3313 tmp = arch_to_object (archetype::find ("corpse_pl"));
3314 sprintf (buf, "%s", &op->name);
3315 tmp->name = tmp->name_pl = buf;
3316 tmp->level = op->level;
3317 tmp->x = x;
3318 tmp->y = y;
3319 tmp->msg = gravestone_text (op);
3320 SET_FLAG (tmp, FLAG_UNIQUE);
3321 insert_ob_in_map (tmp, map, NULL, 0);
3322 }
3323} 3051}
3324
3325 3052
3326void 3053void
3327loot_object (object *op) 3054loot_object (object *op)
3328{ /* Grab and destroy some treasure */ 3055{ /* Grab and destroy some treasure */
3329 object *tmp, *tmp2, *next; 3056 object *tmp, *tmp2, *next;
3330 3057
3331 if (op->container) 3058 if (op->container)
3332 { /* close open sack first */
3333 esrv_apply_container (op, op->container); 3059 esrv_apply_container (op, op->container); /* close open sack first */
3334 }
3335 3060
3336 for (tmp = op->inv; tmp != NULL; tmp = next) 3061 for (tmp = op->inv; tmp; tmp = next)
3337 { 3062 {
3338 next = tmp->below; 3063 next = tmp->below;
3064
3339 if (tmp->invisible) 3065 if (tmp->invisible)
3340 continue; 3066 continue;
3067
3341 tmp->remove (); 3068 tmp->remove ();
3342 tmp->x = op->x, tmp->y = op->y; 3069 tmp->x = op->x, tmp->y = op->y;
3343 if (tmp->type == CONTAINER) 3070 if (tmp->type == CONTAINER)
3344 { /* empty container to ground */ 3071 { /* empty container to ground */
3345 loot_object (tmp); 3072 loot_object (tmp);
3367 */ 3094 */
3368 3095
3369void 3096void
3370fix_weight (void) 3097fix_weight (void)
3371{ 3098{
3372 player *pl;
3373
3374 for (pl = first_player; pl != NULL; pl = pl->next) 3099 for (player *pl = first_player; pl; pl = pl->next)
3375 { 3100 {
3376 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 3101 int old = pl->ob->carrying, sum = sum_weight (pl->ob);
3377 3102
3378 if (old == sum) 3103 if (old == sum)
3379 continue; 3104 continue;
3380 fix_player (pl->ob); 3105 pl->ob->update_stats ();
3381 LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, old, sum); 3106 LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, old, sum);
3382 } 3107 }
3383} 3108}
3384 3109
3385void 3110void
3386fix_luck (void) 3111fix_luck (void)
3387{ 3112{
3388 player *pl;
3389
3390 for (pl = first_player; pl != NULL; pl = pl->next) 3113 for (player *pl = first_player; pl; pl = pl->next)
3391 if (!pl->ob->contr->ns->state) 3114 if (!pl->ob->contr->ns->state)
3392 change_luck (pl->ob, 0); 3115 pl->ob->change_luck (0);
3393} 3116}
3394
3395 3117
3396/* cast_dust() - handles op throwing objects of type 'DUST'. 3118/* cast_dust() - handles op throwing objects of type 'DUST'.
3397 * This is much simpler in the new spell code - we basically 3119 * This is much simpler in the new spell code - we basically
3398 * just treat this as any other spell casting object. 3120 * just treat this as any other spell casting object.
3399 */ 3121 */
3400
3401void 3122void
3402cast_dust (object *op, object *throw_ob, int dir) 3123cast_dust (object *op, object *throw_ob, int dir)
3403{ 3124{
3404 object *skop, *spob; 3125 object *skop, *spob;
3405 3126

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines