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.12 by elmex, Tue Aug 29 10:51:43 2006 UTC vs.
Revision 1.17 by pippijn, Thu Sep 7 10:01:58 2006 UTC

1/* 1/*
2 * static char *rcsid_player_c = 2 * static char *rcsid_player_c =
3 * "$Id: player.C,v 1.12 2006/08/29 10:51:43 elmex Exp $"; 3 * "$Id: player.C,v 1.17 2006/09/07 10:01:58 pippijn Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
60 player* pl; 60 player* pl;
61 player* found = NULL; 61 player* found = NULL;
62 size_t namelen = strlen( plname ); 62 size_t namelen = strlen( plname );
63 for ( pl = first_player; pl != NULL; pl = pl->next ) 63 for ( pl = first_player; pl != NULL; pl = pl->next )
64 { 64 {
65 if ( strlen( pl->ob->name ) < namelen ) 65 if ( (size_t) strlen( pl->ob->name ) < namelen )
66 continue; 66 continue;
67 67
68 if ( !strcmp( pl->ob->name, plname) ) 68 if ( !strcmp( pl->ob->name, plname) )
69 return pl; 69 return pl;
70 70
197 * Hopefully this will be less bugfree and simpler. 197 * Hopefully this will be less bugfree and simpler.
198 * Returns the player structure. If 'p' is null, 198 * Returns the player structure. If 'p' is null,
199 * we create a new one. Otherwise, we recycle 199 * we create a new one. Otherwise, we recycle
200 * the one that is passed. 200 * the one that is passed.
201 */ 201 */
202static player* get_player(player *p) { 202static player *
203get_player (player * p)
204{
203 object *op=arch_to_object(get_player_archetype(NULL)); 205 object *op = arch_to_object (get_player_archetype (NULL));
204 int i; 206 int i;
205 207
206 if (!p) { 208 if (!p)
207 p = (player *) malloc(sizeof(player)); 209 {
208 if(p==NULL) 210 p = new player;
209 fatal(OUT_OF_MEMORY);
210 211
211 /* This adds the player in the linked list. There is extra 212 /* This adds the player in the linked list. There is extra
212 * complexity here because we want to add the new player at the 213 * complexity here because we want to add the new player at the
213 * end of the list - there is in fact no compelling reason that 214 * end of the list - there is in fact no compelling reason that
214 * that needs to be done except for things like output of 215 * that needs to be done except for things like output of
215 * 'who'. 216 * 'who'.
216 */ 217 */
217 player *tmp = first_player; 218 player *tmp = first_player;
218 while(tmp!=NULL&&tmp->next!=NULL) 219 while (tmp != NULL && tmp->next != NULL)
219 tmp=tmp->next; 220 tmp = tmp->next;
220 if(tmp!=NULL) 221 if (tmp != NULL)
221 tmp->next=p; 222 tmp->next = p;
222 else 223 else
223 first_player=p; 224 first_player = p;
224 225
225 p->next = NULL; 226 p->next = NULL;
226 } 227 }
227 228
228 /* Clears basically the entire player structure except 229 /* Clears basically the entire player structure except
229 * for next and socket. 230 * for next and socket.
230 */ 231 */
231 memset (static_cast<player_memset *>(p), 0, sizeof (player_memset)); 232 p->clear ();
232 p->attachable_init (); //HACK
233 233
234 /* There are some elements we want initialized to non zero value - 234 /* There are some elements we want initialized to non zero value -
235 * we deal with that below this point. 235 * we deal with that below this point.
236 */ 236 */
237 p->party=NULL; 237 p->party = NULL;
238 p->outputs_sync=16; /* Every 2 seconds */ 238 p->outputs_sync = 16; /* Every 2 seconds */
239 p->outputs_count=1; /* Keeps present behaviour */ 239 p->outputs_count = 8; /* Keeps present behaviour */
240 p->unapply = unapply_nochoice; 240 p->unapply = unapply_nochoice;
241 p->Swap_First = -1; 241 p->Swap_First = -1;
242 242
243#ifdef AUTOSAVE 243#ifdef AUTOSAVE
244 p->last_save_tick = 9999999; 244 p->last_save_tick = 9999999;
245#endif 245#endif
246 246
247 strcpy(p->savebed_map, first_map_path); /* Init. respawn position */ 247 strcpy (p->savebed_map, first_map_path); /* Init. respawn position */
248 248
249 op->contr=p; /* this aren't yet in archetype */ 249 op->contr = p; /* this aren't yet in archetype */
250 p->ob = op; 250 p->ob = op;
251 op->speed_left=0.5; 251 op->speed_left = 0.5;
252 op->speed=1.0; 252 op->speed = 1.0;
253 op->direction=5; /* So player faces south */ 253 op->direction = 5; /* So player faces south */
254 op->stats.wc=2; 254 op->stats.wc = 2;
255 op->run_away = 25; /* Then we panick... */ 255 op->run_away = 25; /* Then we panick... */
256 p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ 256 p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */
257 257
258 roll_stats(op); 258 roll_stats (op);
259 p->state=ST_ROLL_STAT; 259 p->state = ST_ROLL_STAT;
260 clear_los(op); 260 clear_los (op);
261 261
262 p->gen_sp_armour=10; 262 p->gen_sp_armour = 10;
263 p->last_speed= -1; 263 p->last_speed = -1;
264 p->shoottype=range_none; 264 p->shoottype = range_none;
265 p->bowtype=bow_normal; 265 p->bowtype = bow_normal;
266 p->petmode=pet_normal; 266 p->petmode = pet_normal;
267 p->listening=10; 267 p->listening = 10;
268 p->usekeys=containers; 268 p->usekeys = containers;
269 p->last_weapon_sp= -1; 269 p->last_weapon_sp = -1;
270 p->peaceful=1; /* default peaceful */ 270 p->peaceful = 1; /* default peaceful */
271 p->do_los=1; 271 p->do_los = 1;
272 p->explore=0; 272 p->explore = 0;
273 p->no_shout=0; /* default can shout */ 273 p->no_shout = 0; /* default can shout */
274 274
275 strncpy(p->title, op->arch->clone.name, sizeof(p->title)-1); 275 strncpy (p->title, op->arch->clone.name, sizeof (p->title) - 1);
276 p->title[sizeof(p->title)-1] = '\0'; 276 p->title[sizeof (p->title) - 1] = '\0';
277 op->race = add_string (op->arch->clone.race); 277 op->race = op->arch->clone.race;
278 278
279 CLEAR_FLAG(op,FLAG_READY_SKILL); 279 CLEAR_FLAG (op, FLAG_READY_SKILL);
280 280
281 /* we need to clear these to -1 and not zero - otherwise, 281 /* we need to clear these to -1 and not zero - otherwise,
282 * if a player quits and starts a new character, we wont 282 * if a player quits and starts a new character, we wont
283 * send new values to the client, as things like exp start 283 * send new values to the client, as things like exp start
284 * at zero. 284 * at zero.
285 */ 285 */
286 for (i=0; i < NUM_SKILLS; i++) { 286 for (i = 0; i < NUM_SKILLS; i++)
287 {
287 p->last_skill_exp[i] = -1; 288 p->last_skill_exp[i] = -1;
288 p->last_skill_ob[i] = NULL; 289 p->last_skill_ob[i] = NULL;
289 } 290 }
290 for (i=0; i < NROFATTACKS; i++) { 291 for (i = 0; i < NROFATTACKS; i++)
292 {
291 p->last_resist[i] = -1; 293 p->last_resist[i] = -1;
292 } 294 }
293 p->last_stats.exp = -1; 295 p->last_stats.exp = -1;
294 p->last_weight = (uint32)-1; 296 p->last_weight = (uint32) - 1;
295 297
296 p->socket.update_look=0; 298 p->socket.update_look = 0;
297 p->socket.look_position=0; 299 p->socket.look_position = 0;
298 return p; 300 return p;
299} 301}
300
301 302
302/* This loads the first map an puts the player on it. */ 303/* This loads the first map an puts the player on it. */
303static void set_first_map(object *op) 304static void set_first_map(object *op)
304{ 305{
305 strcpy(op->contr->maplevel, first_map_path); 306 strcpy(op->contr->maplevel, first_map_path);
409 lastdist=rv.distance; 410 lastdist=rv.distance;
410 } 411 }
411 } 412 }
412 } 413 }
413#if 0 414#if 0
414 LOG(llevDebug,"get_nearest_player() finds player: %s\n",op?op->name:"(null)"); 415 LOG(llevDebug,"get_nearest_player() finds player: %s\n",op?&op->name:"(null)");
415#endif 416#endif
416 return op; 417 return op;
417} 418}
418 419
419/* I believe this can safely go to 2, 3 is questionable, 4 will likely 420/* I believe this can safely go to 2, 3 is questionable, 4 will likely
615 616
616 if (tmp) { 617 if (tmp) {
617 remove_ob(op); 618 remove_ob(op);
618 free_object(op); 619 free_object(op);
619 LOG(llevError,"give_initial_items: Removing duplicate object %s\n", 620 LOG(llevError,"give_initial_items: Removing duplicate object %s\n",
620 tmp->name); 621 &tmp->name);
621 continue; 622 continue;
622 } 623 }
623 if (op->nrof > 1) op->nrof = 1; 624 if (op->nrof > 1) op->nrof = 1;
624 } 625 }
625 626
696 leave(op->contr,0); /* ericserver will draw the message */ 697 leave(op->contr,0); /* ericserver will draw the message */
697 return 2; 698 return 2;
698 } 699 }
699 else if(key=='a'||key=='A') { 700 else if(key=='a'||key=='A') {
700 player *pl = op->contr; 701 player *pl = op->contr;
701 const char *name = op->name; 702 shstr name = op->name;
702 703
703 add_refcount(name);
704 remove_friendly_object(op); 704 remove_friendly_object(op);
705 free_object(op); 705 free_object(op);
706 pl = get_player(pl); 706 pl = get_player(pl);
707 op = pl->ob; 707 op = pl->ob;
708 add_friendly_object(op); 708 add_friendly_object(op);
709 op->contr->password[0]='~'; 709 op->contr->password[0]='~';
710 FREE_AND_CLEAR_STR(op->name); 710 op->name = op->name_pl = 0;
711 FREE_AND_CLEAR_STR(op->name_pl);
712
713 /* Lets put a space in here */ 711 /* Lets put a space in here */
714 new_draw_info(NDI_UNIQUE, 0, op, "\n"); 712 new_draw_info(NDI_UNIQUE, 0, op, "\n");
715 get_name(op); 713 get_name(op);
716 op->name = name; /* Alrady added a refcount above */ 714 op->name = op->name_pl = name;
717 op->name_pl = add_string(name);
718 set_first_map(op); 715 set_first_map(op);
719 } else { 716 } else {
720 /* user pressed something else so just ask again... */ 717 /* user pressed something else so just ask again... */
721 play_again(op); 718 play_again(op);
722 } 719 }
730 send_query(&op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); 727 send_query(&op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:");
731} 728}
732 729
733void get_party_password(object *op, partylist *party) { 730void get_party_password(object *op, partylist *party) {
734 if (party == NULL) { 731 if (party == NULL) {
735 LOG(llevError, "get_party_password(): tried to make player %s join a NULL party", op->name); 732 LOG(llevError, "get_party_password(): tried to make player %s join a NULL party", &op->name);
736 return; 733 return;
737 } 734 }
738 op->contr->write_buf[0]='\0'; 735 op->contr->write_buf[0]='\0';
739 op->contr->state=ST_GET_PARTY_PASSWORD; 736 op->contr->state=ST_GET_PARTY_PASSWORD;
740 op->contr->party_to_join = party; 737 op->contr->party_to_join = party;
977 INVOKE_PLAYER (BIRTH, op->contr); 974 INVOKE_PLAYER (BIRTH, op->contr);
978 INVOKE_PLAYER (LOGIN, op->contr); 975 INVOKE_PLAYER (LOGIN, op->contr);
979 976
980 op->contr->state=ST_PLAYING; 977 op->contr->state=ST_PLAYING;
981 978
982 if (op->msg) { 979 if (op->msg)
983 free_string(op->msg);
984 op->msg=NULL; 980 op->msg=NULL;
985 }
986 981
987 /* We create this now because some of the unique maps will need it 982 /* We create this now because some of the unique maps will need it
988 * to save here. 983 * to save here.
989 */ 984 */
990 sprintf(buf,"%s/%s/%s",settings.localdir,settings.playerdir,op->name); 985 sprintf(buf,"%s/%s/%s",settings.localdir,settings.playerdir,&op->name);
991 make_path_to_file(buf); 986 make_path_to_file(buf);
992 987
993#ifdef AUTOSAVE 988#ifdef AUTOSAVE
994 op->contr->last_save_tick = pticks; 989 op->contr->last_save_tick = pticks;
995#endif 990#endif
1003 /* This moves the player to a different start map, if there 998 /* This moves the player to a different start map, if there
1004 * is one for this race 999 * is one for this race
1005 */ 1000 */
1006 if(*first_map_ext_path) { 1001 if(*first_map_ext_path) {
1007 object *tmp; 1002 object *tmp;
1008 mapstruct *oldmap = op->map;
1009 char mapname[MAX_BUF]; 1003 char mapname[MAX_BUF];
1010 snprintf(mapname, MAX_BUF-1, "%s/%s", 1004 snprintf(mapname, MAX_BUF-1, "%s/%s",
1011 first_map_ext_path, op->arch->name); 1005 first_map_ext_path, &op->arch->name);
1012 tmp=get_object(); 1006 tmp=get_object();
1013 EXIT_PATH(tmp) = add_string(mapname); 1007 EXIT_PATH(tmp) = mapname;
1014 EXIT_X(tmp) = op->x; 1008 EXIT_X(tmp) = op->x;
1015 EXIT_Y(tmp) = op->y; 1009 EXIT_Y(tmp) = op->y;
1016 enter_exit(op,tmp); /* we don't really care if it succeeded; 1010 enter_exit(op,tmp); /* we don't really care if it succeeded;
1017 * if the map isn't there, then stay on the 1011 * if the map isn't there, then stay on the
1018 * default initial map */ 1012 * default initial map */
1027 * if we don't match with one of the options above. 1021 * if we don't match with one of the options above.
1028 */ 1022 */
1029 1023
1030 tmp_loop = 0; 1024 tmp_loop = 0;
1031 while(!tmp_loop) { 1025 while(!tmp_loop) {
1032 const char *name = add_string (op->name); 1026 shstr name = op->name;
1033 int x = op->x, y = op->y; 1027 int x = op->x, y = op->y;
1034 remove_statbonus(op); 1028 remove_statbonus(op);
1035 remove_ob (op); 1029 remove_ob (op);
1036 op->arch = get_player_archetype(op->arch); 1030 op->arch = get_player_archetype(op->arch);
1037 copy_object (&op->arch->clone, op); 1031 copy_object (&op->arch->clone, op);
1038 op->instantiate (); 1032 op->instantiate ();
1039 op->stats = op->contr->orig_stats; 1033 op->stats = op->contr->orig_stats;
1040 free_string (op->name);
1041 op->name = name; 1034 op->name = op->name_pl = name;
1042 free_string(op->name_pl);
1043 op->name_pl = add_string(name);
1044 op->x = x; 1035 op->x = x;
1045 op->y = y; 1036 op->y = y;
1046 SET_ANIMATION(op, 2); /* So player faces south */ 1037 SET_ANIMATION(op, 2); /* So player faces south */
1047 insert_ob_in_map (op, op->map, op,0); 1038 insert_ob_in_map (op, op->map, op,0);
1048 strncpy(op->contr->title, op->arch->clone.name, sizeof(op->contr->title)-1); 1039 strncpy(op->contr->title, op->arch->clone.name, sizeof(op->contr->title)-1);
1049 op->contr->title[sizeof(op->contr->title)-1] = '\0'; 1040 op->contr->title[sizeof(op->contr->title)-1] = '\0';
1050 add_statbonus(op); 1041 add_statbonus(op);
1051 tmp_loop=allowed_class(op); 1042 tmp_loop=allowed_class(op);
1052
1053 if (!strncmp (op->msg, "Edit me", 7)) tmp_loop = 0; // pippijn fucked it up //D//TODO
1054 } 1043 }
1055 update_object(op,UP_OBJ_FACE); 1044 update_object(op,UP_OBJ_FACE);
1056 esrv_update_item(UPD_FACE,op,op); 1045 esrv_update_item(UPD_FACE,op,op);
1057 fix_player(op); 1046 fix_player(op);
1058 op->stats.hp=op->stats.maxhp; 1047 op->stats.hp=op->stats.maxhp;
1079 1068
1080 terminate_all_pets(op); 1069 terminate_all_pets(op);
1081 leave_map(op); 1070 leave_map(op);
1082 op->direction=0; 1071 op->direction=0;
1083 new_draw_info_format(NDI_UNIQUE | NDI_ALL, 5, NULL, 1072 new_draw_info_format(NDI_UNIQUE | NDI_ALL, 5, NULL,
1084 "%s quits the game.",op->name); 1073 "%s quits the game.", &op->name);
1085 1074
1086 strcpy(op->contr->killer,"quit"); 1075 strcpy(op->contr->killer,"quit");
1087 check_score(op); 1076 check_score(op);
1088 op->contr->party=NULL; 1077 op->contr->party=NULL;
1089 if (settings.set_title == TRUE) 1078 if (settings.set_title == TRUE)
1094 1083
1095 /* We need to hunt for any per player unique maps in memory and 1084 /* We need to hunt for any per player unique maps in memory and
1096 * get rid of them. The trailing slash in the path is intentional, 1085 * get rid of them. The trailing slash in the path is intentional,
1097 * so that players named 'Ab' won't match against players 'Abe' pathname 1086 * so that players named 'Ab' won't match against players 'Abe' pathname
1098 */ 1087 */
1099 sprintf(buf,"%s/%s/%s/", settings.localdir, settings.playerdir, op->name); 1088 sprintf(buf,"%s/%s/%s/", settings.localdir, settings.playerdir, &op->name);
1100 for (mp=first_map; mp!=NULL; mp=next) { 1089 for (mp=first_map; mp!=NULL; mp=next) {
1101 next = mp->next; 1090 next = mp->next;
1102 if (!strncmp(mp->path, buf, strlen(buf))) 1091 if (!strncmp(mp->path, buf, strlen(buf)))
1103 delete_map(mp); 1092 delete_map(mp);
1104 } 1093 }
1239 if(op->contr->mode & PU_DEBUG) 1228 if(op->contr->mode & PU_DEBUG)
1240 { 1229 {
1241 /* some debugging code to figure out item information */ 1230 /* some debugging code to figure out item information */
1242 if(tmp->name!=NULL) 1231 if(tmp->name!=NULL)
1243 sprintf(putstring,"item name: %s item type: %d weight/value: %d", 1232 sprintf(putstring,"item name: %s item type: %d weight/value: %d",
1244 tmp->name, tmp->type, 1233 &tmp->name, tmp->type,
1245 (int)(query_cost(tmp, op, F_TRUE)*100 / (tmp->weight * MAX(tmp->nrof,1)))); 1234 (int)(query_cost(tmp, op, F_TRUE)*100 / (tmp->weight * MAX(tmp->nrof,1))));
1246 else 1235 else
1247 sprintf(putstring,"item name: %s item type: %d weight/value: %d", 1236 sprintf(putstring,"item name: %s item type: %d weight/value: %d",
1248 tmp->arch->name, tmp->type, 1237 &tmp->arch->name, tmp->type,
1249 (int)(query_cost(tmp, op, F_TRUE)*100 / (tmp->weight * MAX(tmp->nrof,1)))); 1238 (int)(query_cost(tmp, op, F_TRUE)*100 / (tmp->weight * MAX(tmp->nrof,1))));
1250 new_draw_info(NDI_UNIQUE, 0,op,putstring); 1239 new_draw_info(NDI_UNIQUE, 0,op,putstring);
1251 1240
1252 sprintf(putstring,"...flags: "); 1241 sprintf(putstring,"...flags: ");
1253 for(k=0;k<4;k++) 1242 for(k=0;k<4;k++)
1419 { 1408 {
1420 /* use value density to decide what else to grab */ 1409 /* use value density to decide what else to grab */
1421 /* >=7 was >= op->contr->mode */ 1410 /* >=7 was >= op->contr->mode */
1422 /* >=7 is the old standard setting. Now we take the last 4 bits 1411 /* >=7 is the old standard setting. Now we take the last 4 bits
1423 * and multiply them by 5, giving 0..15*5== 5..75 */ 1412 * and multiply them by 5, giving 0..15*5== 5..75 */
1424 wvratio=(op->contr->mode & PU_RATIO) * 5; 1413 wvratio = (op->contr->mode & PU_RATIO) * 5;
1425 if ((query_cost(tmp, op, F_TRUE)*100 / (tmp->weight * MAX(tmp->nrof, 1))) >= wvratio) 1414 if ((query_cost(tmp, op, F_TRUE) * 100 / (tmp->weight * MAX(tmp->nrof, 1))) >= (unsigned int) wvratio)
1426 { 1415 {
1427 pick_up(op, tmp); 1416 pick_up(op, tmp);
1428#if 0 1417#if 0
1429 fprintf(stderr,"HIGH WEIGHT/VALUE ["); 1418 fprintf(stderr,"HIGH WEIGHT/VALUE [");
1430 if(tmp->name!=NULL) { 1419 if(tmp->name!=NULL) {
1613 */ 1602 */
1614 if(bow->type==BOW) 1603 if(bow->type==BOW)
1615 break; 1604 break;
1616 1605
1617 if (!bow) { 1606 if (!bow) {
1618 LOG (llevError, "Range: bow without activated bow (%s).\n", op->name); 1607 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name);
1619 return 0; 1608 return 0;
1620 } 1609 }
1621 } 1610 }
1622 if( !bow->race || !bow->skill) { 1611 if( !bow->race || !bow->skill) {
1623 new_draw_info_format(NDI_UNIQUE, 0, op, "Your %s is broken.", bow->name); 1612 new_draw_info_format(NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1624 return 0; 1613 return 0;
1625 } 1614 }
1626 1615
1627 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex]; 1616 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex];
1628 1617
1634 1623
1635 if (arrow == NULL) { 1624 if (arrow == NULL) {
1636 if ((arrow=find_arrow(op, bow->race)) == NULL) { 1625 if ((arrow=find_arrow(op, bow->race)) == NULL) {
1637 if (op->type == PLAYER) 1626 if (op->type == PLAYER)
1638 new_draw_info_format(NDI_UNIQUE, 0, op, 1627 new_draw_info_format(NDI_UNIQUE, 0, op,
1639 "You have no %s left.", bow->race); 1628 "You have no %s left.", &bow->race);
1640 /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */ 1629 /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */
1641 else 1630 else
1642 CLEAR_FLAG(op, FLAG_READY_BOW); 1631 CLEAR_FLAG(op, FLAG_READY_BOW);
1643 return 0; 1632 return 0;
1644 } 1633 }
1661 1650
1662 left = arrow; /* these are arrows left to the player */ 1651 left = arrow; /* these are arrows left to the player */
1663 left_tag = left->count; 1652 left_tag = left->count;
1664 arrow = get_split_ob(arrow, 1); 1653 arrow = get_split_ob(arrow, 1);
1665 if (arrow == NULL) { 1654 if (arrow == NULL) {
1666 new_draw_info_format(NDI_UNIQUE, 0, op, "You have no %s left.", 1655 new_draw_info_format(NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1667 bow->race);
1668 return 0; 1656 return 0;
1669 } 1657 }
1670 set_owner(arrow, op); 1658 set_owner(arrow, op);
1671 if (arrow->skill) free_string(arrow->skill);
1672 arrow->skill = add_refcount(bow->skill); 1659 arrow->skill = bow->skill;
1673 1660
1674 arrow->direction=dir; 1661 arrow->direction=dir;
1675 arrow->x = sx; 1662 arrow->x = sx;
1676 arrow->y = sy; 1663 arrow->y = sy;
1677 1664
1720 arrow->level = op->level; 1707 arrow->level = op->level;
1721 } 1708 }
1722 if (arrow->attacktype == AT_PHYSICAL) 1709 if (arrow->attacktype == AT_PHYSICAL)
1723 arrow->attacktype |= bow->attacktype; 1710 arrow->attacktype |= bow->attacktype;
1724 if (bow->slaying != NULL) 1711 if (bow->slaying != NULL)
1725 arrow->slaying = add_string(bow->slaying); 1712 arrow->slaying = bow->slaying;
1726 1713
1727 arrow->map = m; 1714 arrow->map = m;
1728 arrow->move_type = MOVE_FLY_LOW; 1715 arrow->move_type = MOVE_FLY_LOW;
1729 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1716 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1730 1717
1793 return; 1780 return;
1794 } 1781 }
1795 1782
1796 item = op->contr->ranges[range_misc]; 1783 item = op->contr->ranges[range_misc];
1797 if (!item->inv) { 1784 if (!item->inv) {
1798 LOG(llevError,"Object %s lacks a spell\n", item->name); 1785 LOG(llevError,"Object %s lacks a spell\n", &item->name);
1799 return; 1786 return;
1800 } 1787 }
1801 if (item->type == WAND) { 1788 if (item->type == WAND) {
1802 if(item->stats.food<=0) { 1789 if(item->stats.food<=0) {
1803 play_sound_player_only(op->contr, SOUND_WAND_POOF,0,0); 1790 play_sound_player_only(op->contr, SOUND_WAND_POOF,0,0);
2368 char buf[MAX_BUF]; 2355 char buf[MAX_BUF];
2369 time_t now = time (NULL); 2356 time_t now = time (NULL);
2370 2357
2371 strcpy (buf2, " R.I.P.\n\n"); 2358 strcpy (buf2, " R.I.P.\n\n");
2372 if (op->type == PLAYER) 2359 if (op->type == PLAYER)
2373 sprintf (buf, "%s the %s\n", op->name, op->contr->title); 2360 sprintf (buf, "%s the %s\n", &op->name, op->contr->title);
2374 else 2361 else
2375 sprintf (buf, "%s\n", op->name); 2362 sprintf (buf, "%s\n", &op->name);
2376 strncat (buf2, " ", 20 - strlen (buf) / 2); 2363 strncat (buf2, " ", 20 - strlen (buf) / 2);
2377 strcat (buf2, buf); 2364 strcat (buf2, buf);
2378 if (op->type == PLAYER) 2365 if (op->type == PLAYER)
2379 sprintf (buf, "who was in level %d when killed\n", op->level); 2366 sprintf (buf, "who was in level %d when killed\n", op->level);
2380 else 2367 else
2404 int rate_grace = 2000; 2391 int rate_grace = 2000;
2405 const int max_hp = 1; 2392 const int max_hp = 1;
2406 const int max_sp = 1; 2393 const int max_sp = 1;
2407 const int max_grace = 1; 2394 const int max_grace = 1;
2408 2395
2409 if (op->contr->outputs_sync) { 2396 if (op->contr->outputs_sync)
2397 {
2410 for (i=0; i<NUM_OUTPUT_BUFS; i++) 2398 for (i=0; i<NUM_OUTPUT_BUFS; i++)
2411 if (op->contr->outputs[i].buf!=NULL && 2399 if (op->contr->outputs[i].buf!=NULL &&
2412 (op->contr->outputs[i].first_update+op->contr->outputs_sync)<pticks) 2400 (op->contr->outputs[i].first_update + op->contr->outputs_sync) < (uint16) pticks)
2413 flush_output_element(op, &op->contr->outputs[i]); 2401 flush_output_element(op, &op->contr->outputs[i]);
2414 } 2402 }
2415 2403
2416 if(op->contr->state==ST_PLAYING) { 2404 if(op->contr->state==ST_PLAYING) {
2417 2405
2418 /* these next three if clauses make it possible to SLOW DOWN 2406 /* these next three if clauses make it possible to SLOW DOWN
2419 hp/grace/spellpoint regeneration. */ 2407 hp/grace/spellpoint regeneration. */
2576 * file. 2564 * file.
2577 */ 2565 */
2578void kill_player(object *op) 2566void kill_player(object *op)
2579{ 2567{
2580 char buf[MAX_BUF]; 2568 char buf[MAX_BUF];
2581 int x,y,i; 2569 int x, y;
2570 //int i;
2582 mapstruct *map; /* this is for resurrection */ 2571 mapstruct *map; /* this is for resurrection */
2583 int z; 2572 /* int z;
2584 int num_stats_lose; 2573 int num_stats_lose;
2585 int lost_a_stat; 2574 int lost_a_stat;
2586 int lose_this_stat; 2575 int lose_this_stat;
2587 int this_stat; 2576 int this_stat; */
2588 int will_kill_again; 2577 int will_kill_again;
2589 archetype *at; 2578 archetype *at;
2590 object *tmp; 2579 object *tmp;
2591 2580
2592 if(save_life(op)) 2581 if(save_life(op))
2626 2615
2627 /* create a bodypart-trophy to make the winner happy */ 2616 /* create a bodypart-trophy to make the winner happy */
2628 tmp=arch_to_object(find_archetype("finger")); 2617 tmp=arch_to_object(find_archetype("finger"));
2629 if (tmp != NULL) 2618 if (tmp != NULL)
2630 { 2619 {
2631 sprintf(buf,"%s's finger",op->name); 2620 sprintf(buf,"%s's finger", &op->name);
2632 tmp->name = add_string(buf); 2621 tmp->name = buf;
2633 sprintf(buf," This finger has been cut off %s\n" 2622 sprintf(buf," This finger has been cut off %s\n"
2634 " the %s, when he was defeated at\n level %d by %s.\n", 2623 " the %s, when he was defeated at\n level %d by %s.\n",
2635 op->name, op->contr->title, (int)(op->level), 2624 &op->name, op->contr->title, (int)(op->level),
2636 op->contr->killer); 2625 op->contr->killer);
2637 tmp->msg=add_string(buf); 2626 tmp->msg=buf;
2638 tmp->value=0, tmp->material=0, tmp->type=0; 2627 tmp->value=0, tmp->material=0, tmp->type=0;
2639 tmp->materialname = NULL; 2628 tmp->materialname = NULL;
2640 tmp->x = op->x, tmp->y = op->y; 2629 tmp->x = op->x, tmp->y = op->y;
2641 insert_ob_in_map(tmp,op->map,op,0); 2630 insert_ob_in_map(tmp,op->map,op,0);
2642 } 2631 }
2656 new_draw_info(NDI_UNIQUE, 0,op,"You would have starved, but you are"); 2645 new_draw_info(NDI_UNIQUE, 0,op,"You would have starved, but you are");
2657 new_draw_info(NDI_UNIQUE, 0,op,"in explore mode, so..."); 2646 new_draw_info(NDI_UNIQUE, 0,op,"in explore mode, so...");
2658 op->stats.food=999; 2647 op->stats.food=999;
2659 return; 2648 return;
2660 } 2649 }
2661 sprintf(buf,"%s starved to death.",op->name); 2650 sprintf(buf,"%s starved to death.",&op->name);
2662 strcpy(op->contr->killer,"starvation"); 2651 strcpy(op->contr->killer,"starvation");
2663 } 2652 }
2664 else { 2653 else {
2665 if (op->contr->explore) { 2654 if (op->contr->explore) {
2666 new_draw_info(NDI_UNIQUE, 0,op,"You would have died, but you are"); 2655 new_draw_info(NDI_UNIQUE, 0,op,"You would have died, but you are");
2667 new_draw_info(NDI_UNIQUE, 0,op,"in explore mode, so..."); 2656 new_draw_info(NDI_UNIQUE, 0,op,"in explore mode, so...");
2668 op->stats.hp=op->stats.maxhp; 2657 op->stats.hp=op->stats.maxhp;
2669 return; 2658 return;
2670 } 2659 }
2671 sprintf(buf,"%s died.",op->name); 2660 sprintf(buf,"%s died.", &op->name);
2672 } 2661 }
2673 play_sound_player_only(op->contr, SOUND_PLAYER_DIES,0,0); 2662 play_sound_player_only(op->contr, SOUND_PLAYER_DIES,0,0);
2674 2663
2675 /* save the map location for corpse, gravestone*/ 2664 /* save the map location for corpse, gravestone*/
2676 x=op->x;y=op->y;map=op->map; 2665 x=op->x;y=op->y;map=op->map;
2793 2782
2794 /* Put a gravestone up where the character 'almost' died. List the 2783 /* Put a gravestone up where the character 'almost' died. List the
2795 * exp loss on the stone. 2784 * exp loss on the stone.
2796 */ 2785 */
2797 tmp=arch_to_object(find_archetype("gravestone")); 2786 tmp=arch_to_object(find_archetype("gravestone"));
2798 sprintf(buf,"%s's gravestone",op->name); 2787 sprintf(buf,"%s's gravestone",&op->name); tmp->name = buf;
2799 FREE_AND_COPY(tmp->name, buf);
2800 sprintf(buf,"%s's gravestones",op->name); 2788 sprintf(buf,"%s's gravestones",&op->name); tmp->name_pl = buf;
2801 FREE_AND_COPY(tmp->name_pl, buf);
2802 sprintf(buf,"RIP\nHere rests the hero %s the %s,\n" 2789 sprintf(buf,"RIP\nHere rests the hero %s the %s,\n"
2803 "who was killed\n" 2790 "who was killed\n"
2804 "by %s.\n", 2791 "by %s.\n",
2805 op->name, op->contr->title, 2792 &op->name, op->contr->title,
2806 op->contr->killer); 2793 op->contr->killer);
2807 tmp->msg = add_string(buf); 2794 tmp->msg = buf;
2808 tmp->x=op->x,tmp->y=op->y; 2795 tmp->x=op->x,tmp->y=op->y;
2809 insert_ob_in_map (tmp, op->map, NULL,0); 2796 insert_ob_in_map (tmp, op->map, NULL,0);
2810 2797
2811 /**************************************/ 2798 /**************************************/
2812 /* */ 2799 /* */
2952 } 2939 }
2953 play_again(op); 2940 play_again(op);
2954 2941
2955 /* peterm: added to create a corpse at deathsite. */ 2942 /* peterm: added to create a corpse at deathsite. */
2956 tmp=arch_to_object(find_archetype("corpse_pl")); 2943 tmp=arch_to_object(find_archetype("corpse_pl"));
2957 sprintf(buf,"%s", op->name); 2944 sprintf(buf,"%s", &op->name);
2958 FREE_AND_COPY(tmp->name, buf); 2945 tmp->name = tmp->name_pl = buf;
2959 FREE_AND_COPY(tmp->name_pl, buf);
2960 tmp->level=op->level; 2946 tmp->level=op->level;
2961 tmp->x=x;tmp->y=y; 2947 tmp->x=x;tmp->y=y;
2962 if (tmp->msg)
2963 free_string(tmp->msg);
2964 tmp->msg = add_string (gravestone_text(op)); 2948 tmp->msg = gravestone_text(op);
2965 SET_FLAG (tmp, FLAG_UNIQUE); 2949 SET_FLAG (tmp, FLAG_UNIQUE);
2966 insert_ob_in_map (tmp, map, NULL,0); 2950 insert_ob_in_map (tmp, map, NULL,0);
2967 } 2951 }
2968} 2952}
2969 2953
3008 int old = pl->ob->carrying, sum = sum_weight(pl->ob); 2992 int old = pl->ob->carrying, sum = sum_weight(pl->ob);
3009 if(old == sum) 2993 if(old == sum)
3010 continue; 2994 continue;
3011 fix_player(pl->ob); 2995 fix_player(pl->ob);
3012 LOG(llevDebug,"Fixed inventory in %s (%d -> %d)\n", 2996 LOG(llevDebug,"Fixed inventory in %s (%d -> %d)\n",
3013 pl->ob->name, old, sum); 2997 &pl->ob->name, old, sum);
3014 } 2998 }
3015} 2999}
3016 3000
3017void fix_luck(void) { 3001void fix_luck(void) {
3018 player *pl; 3002 player *pl;
3036 3020
3037 /* casting POTION 'dusts' is really a use_magic_item skill */ 3021 /* casting POTION 'dusts' is really a use_magic_item skill */
3038 if (op->type == PLAYER && throw_ob->type == POTION && !skop) 3022 if (op->type == PLAYER && throw_ob->type == POTION && !skop)
3039 { 3023 {
3040 LOG (llevError, "Player %s lacks critical skill use_magic_item!\n", 3024 LOG (llevError, "Player %s lacks critical skill use_magic_item!\n",
3041 op->name); 3025 &op->name);
3042 return; 3026 return;
3043 } 3027 }
3044 3028
3045 spob = throw_ob->inv; 3029 spob = throw_ob->inv;
3046 3030
3048 // not pass NULL to cast_spell (which did indeed check itself, but 3032 // not pass NULL to cast_spell (which did indeed check itself, but
3049 // errors should be reported as early as possible IMHO) 3033 // errors should be reported as early as possible IMHO)
3050 if (!spob) 3034 if (!spob)
3051 { 3035 {
3052 LOG (llevError, "cast_dust: thrown object %s (by %s) had no spell in it!", 3036 LOG (llevError, "cast_dust: thrown object %s (by %s) had no spell in it!",
3053 throw_ob->name, op->name); 3037 &throw_ob->name, &op->name);
3054 return; 3038 return;
3055 } 3039 }
3056 3040
3057 if (op->type == PLAYER) 3041 if (op->type == PLAYER)
3058 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", spob->name); 3042 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name);
3059 3043
3060 cast_spell (op, throw_ob, dir, spob, NULL); 3044 cast_spell (op, throw_ob, dir, spob, NULL);
3061 3045
3062 if (!QUERY_FLAG (throw_ob, FLAG_REMOVED)) 3046 if (!QUERY_FLAG (throw_ob, FLAG_REMOVED))
3063 remove_ob (throw_ob); 3047 remove_ob (throw_ob);
3067void make_visible (object *op) { 3051void make_visible (object *op) {
3068 op->hide = 0; 3052 op->hide = 0;
3069 op->invisible = 0; 3053 op->invisible = 0;
3070 if(op->type==PLAYER) { 3054 if(op->type==PLAYER) {
3071 op->contr->tmp_invis = 0; 3055 op->contr->tmp_invis = 0;
3072 if (op->contr->invis_race) FREE_AND_CLEAR_STR(op->contr->invis_race); 3056 op->contr->invis_race = 0;
3073 } 3057 }
3074 update_object(op,UP_OBJ_FACE); 3058 update_object(op,UP_OBJ_FACE);
3075} 3059}
3076 3060
3077int is_true_undead(object *op) { 3061int is_true_undead(object *op) {
3356 3340
3357 if (item->type == SPELL) { 3341 if (item->type == SPELL) {
3358 if (check_spell_known (who, item->name)) 3342 if (check_spell_known (who, item->name))
3359 return; 3343 return;
3360 3344
3361 new_draw_info_format(NDI_UNIQUE|NDI_BLUE, 0, who, "You gained the ability of %s", item->name); 3345 new_draw_info_format(NDI_UNIQUE|NDI_BLUE, 0, who, "You gained the ability of %s", &item->name);
3362 do_learn_spell (who, item, 0); 3346 do_learn_spell (who, item, 0);
3363 return; 3347 return;
3364 } 3348 }
3365 3349
3366 /* grant direct spell */ 3350 /* grant direct spell */
3367 if (item->type == SPELLBOOK) { 3351 if (item->type == SPELLBOOK) {
3368 if (!item->inv) { 3352 if (!item->inv) {
3369 LOG(llevDebug,"dragon_ability_gain: Broken spellbook %s\n", 3353 LOG(llevDebug,"dragon_ability_gain: Broken spellbook %s\n", &item->name);
3370 item->name);
3371 return; 3354 return;
3372 } 3355 }
3373 if (check_spell_known (who, item->inv->name)) 3356 if (check_spell_known (who, item->inv->name))
3374 return; 3357 return;
3375 if (item->invisible) { 3358 if (item->invisible) {
3376 new_draw_info_format(NDI_UNIQUE|NDI_BLUE, 0, who, "You gained the ability of %s", item->inv->name); 3359 new_draw_info_format(NDI_UNIQUE|NDI_BLUE, 0, who, "You gained the ability of %s", &item->inv->name);
3377 do_learn_spell (who, item->inv, 0); 3360 do_learn_spell (who, item->inv, 0);
3378 return; 3361 return;
3379 } 3362 }
3380 } 3363 }
3381 else if (item->type == SKILL_TOOL && item->invisible) { 3364 else if (item->type == SKILL_TOOL && item->invisible) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines