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.1.1.3 by elmex, Wed Mar 15 14:05:37 2006 UTC vs.
Revision 1.21 by elmex, Fri Aug 11 23:04:50 2006 UTC

1/* 1/*
2 * static char *rcsid_player_c = 2 * static char *rcsid_player_c =
3 * "$Id: player.c,v 1.1.1.3 2006/03/15 14:05:37 elmex Exp $"; 3 * "$Id: player.c,v 1.21 2006/08/11 23:04:50 elmex 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
37#include <living.h> 37#include <living.h>
38#include <object.h> 38#include <object.h>
39#include <spells.h> 39#include <spells.h>
40#include <skills.h> 40#include <skills.h>
41#include <newclient.h> 41#include <newclient.h>
42
43#ifdef COZY_SERVER
44extern int same_party (partylist *a, partylist *b);
45#endif
42 46
43player *find_player(const char *plname) 47player *find_player(const char *plname)
44{ 48{
45 player *pl; 49 player *pl;
46 for(pl=first_player;pl!=NULL;pl=pl->next) 50 for(pl=first_player;pl!=NULL;pl=pl->next)
145 continue; 149 continue;
146 if ( *buf =='%'){ /* send one news */ 150 if ( *buf =='%'){ /* send one news */
147 if (size>0) 151 if (size>0)
148 draw_ext_info_format(NDI_UNIQUE | NDI_GREEN, 0, op, 152 draw_ext_info_format(NDI_UNIQUE | NDI_GREEN, 0, op,
149 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, 153 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS,
150 "!! informations: %s\n%s", 154 "INFORMATION: %s\n%s",
151 "%s\n%s", 155 "%s\n%s",
152 subject, news); /*send previously read news*/ 156 subject, news); /*send previously read news*/
153 strcpy(subject,buf+1); 157 strcpy(subject,buf+1);
154 strip_endline(subject); 158 strip_endline(subject);
155 size=0; 159 size=0;
166 } 170 }
167 } 171 }
168 172
169 draw_ext_info_format(NDI_UNIQUE | NDI_GREEN, 0, op, 173 draw_ext_info_format(NDI_UNIQUE | NDI_GREEN, 0, op,
170 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, 174 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS,
171 "!! informations: %s\n%s\n", 175 "INFORMATION: %s\n%s\n",
172 "%s\n%s", 176 "%s\n%s",
173 subject, news); 177 subject, news);
174 close_and_delete(fp, comp); 178 close_and_delete(fp, comp);
175} 179}
176 180
224 } 228 }
225 229
226 /* Clears basically the entire player structure except 230 /* Clears basically the entire player structure except
227 * for next and socket. 231 * for next and socket.
228 */ 232 */
229 memset((void*)((char*)p + offsetof(player, maplevel)), 0, 233 memset((void*)((char*)p + offsetof(player, ob)), 0,
230 sizeof(player) - offsetof(player, maplevel)); 234 sizeof(player) - offsetof(player, ob));
231 235
232 /* There are some elements we want initialized to non zero value - 236 /* There are some elements we want initialized to non zero value -
233 * we deal with that below this point. 237 * we deal with that below this point.
234 */ 238 */
235 p->party=NULL; 239 p->party=NULL;
260 p->gen_sp_armour=10; 264 p->gen_sp_armour=10;
261 p->last_speed= -1; 265 p->last_speed= -1;
262 p->shoottype=range_none; 266 p->shoottype=range_none;
263 p->bowtype=bow_normal; 267 p->bowtype=bow_normal;
264 p->petmode=pet_normal; 268 p->petmode=pet_normal;
265 p->listening=9; 269 p->listening=10;
270 p->usekeys=containers;
266 p->last_weapon_sp= -1; 271 p->last_weapon_sp= -1;
267 p->peaceful=1; /* default peaceful */ 272 p->peaceful=1; /* default peaceful */
268 p->do_los=1; 273 p->do_los=1;
269 p->explore=0; 274 p->explore=0;
270 p->no_shout=0; /* default can shout */ 275 p->no_shout=0; /* default can shout */
312 317
313int add_player(NewSocket *ns) { 318int add_player(NewSocket *ns) {
314 player *p; 319 player *p;
315 320
316 p=get_player(NULL); 321 p=get_player(NULL);
317 memcpy(&p->socket, ns, sizeof(NewSocket)); 322 p->socket = *ns;
318 p->socket.faces_sent = malloc(p->socket.faces_sent_len*sizeof(*p->socket.faces_sent)); 323 p->socket.faces_sent = malloc(p->socket.faces_sent_len*sizeof(*p->socket.faces_sent));
319 if(p->socket.faces_sent == NULL) 324 if(p->socket.faces_sent == NULL)
320 fatal(OUT_OF_MEMORY); 325 fatal(OUT_OF_MEMORY);
321 memcpy(p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len*sizeof(*p->socket.faces_sent)); 326 memcpy(p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len*sizeof(*p->socket.faces_sent));
322 /* Needed because the socket we just copied over needs to be cleared. 327 /* Needed because the socket we just copied over needs to be cleared.
397 op=ol->ob; 402 op=ol->ob;
398 lastdist=rv.distance; 403 lastdist=rv.distance;
399 } 404 }
400 } 405 }
401 for (pl=first_player; pl != NULL; pl=pl->next) { 406 for (pl=first_player; pl != NULL; pl=pl->next) {
402 if (on_same_map(mon, pl->ob)&& can_detect_enemy(mon, pl->ob,&rv)) { 407 if (can_detect_enemy(mon, pl->ob,&rv)) {
403 408
404 if(lastdist>rv.distance) { 409 if(lastdist>rv.distance) {
405 op=pl->ob; 410 op=pl->ob;
406 lastdist=rv.distance; 411 lastdist=rv.distance;
407 } 412 }
484 489
485 mflags = get_map_flags(m, &m, x, y, &x, &y); 490 mflags = get_map_flags(m, &m, x, y, &x, &y);
486 blocked = (mflags & P_OUT_OF_MAP) ? MOVE_ALL : GET_MAP_MOVE_BLOCK(m, x, y); 491 blocked = (mflags & P_OUT_OF_MAP) ? MOVE_ALL : GET_MAP_MOVE_BLOCK(m, x, y);
487 492
488 /* Space is blocked - try changing direction a little */ 493 /* Space is blocked - try changing direction a little */
489 if ((mflags & P_OUT_OF_MAP) || ((OB_TYPE_MOVE_BLOCK(mon, blocked)) 494 if ((mflags & P_OUT_OF_MAP) || ((OB_TYPE_MOVE_BLOCK(mon, blocked) || (mflags&P_BLOCKSVIEW))
490 && (m == mon->map && blocked_link(mon, m, x, y)))) { 495 && (m == mon->map && blocked_link(mon, m, x, y)))) {
491 /* recalculate direction from last good location. Possible 496 /* recalculate direction from last good location. Possible
492 * we were not traversing ideal location before. 497 * we were not traversing ideal location before.
493 */ 498 */
494 get_rangevector_from_mapcoord(lastmap, lastx, lasty, pl, &rv, 0); 499 get_rangevector_from_mapcoord(lastmap, lastx, lasty, pl, &rv, 0);
528 m = lastmap; 533 m = lastmap;
529 mflags = get_map_flags(m, &m, x, y, &x, &y); 534 mflags = get_map_flags(m, &m, x, y, &x, &y);
530 if (mflags & P_OUT_OF_MAP) continue; 535 if (mflags & P_OUT_OF_MAP) continue;
531 blocked = GET_MAP_MOVE_BLOCK(m, x, y); 536 blocked = GET_MAP_MOVE_BLOCK(m, x, y);
532 if (OB_TYPE_MOVE_BLOCK(mon, blocked)) continue; 537 if (OB_TYPE_MOVE_BLOCK(mon, blocked)) continue;
538 if (mflags & P_BLOCKSVIEW) continue;
533 539
534 if (m == mon->map && blocked_link(mon, m, x, y)) break; 540 if (m == mon->map && blocked_link(mon, m, x, y)) break;
535 } 541 }
536 /* go through entire loop without finding a valid 542 /* go through entire loop without finding a valid
537 * sidestep to take - thus, no valid path. 543 * sidestep to take - thus, no valid path.
946 } 952 }
947 return 0; 953 return 0;
948} 954}
949 955
950/* This function takes the key that is passed, and does the 956/* This function takes the key that is passed, and does the
951 * appropriate action with it (change class, or other things. 957 * appropriate action with it (change race, or other things).
958 * The function name is for historical reasons - now we have
959 * separate race and class; this actually changes the RACE,
960 * not the class.
952 */ 961 */
953 962
954int key_change_class(object *op, char key) 963int key_change_class(object *op, char key)
955{ 964{
956 int tmp_loop; 965 int tmp_loop;
957 966
958 if(key=='q'||key=='Q') { 967 if(key=='q'||key=='Q') {
959 remove_ob(op); 968 remove_ob(op);
960 play_again(op); 969 play_again(op);
961 return 0; 970 return 0;
992 CLEAR_FLAG(op, FLAG_WIZ); 1001 CLEAR_FLAG(op, FLAG_WIZ);
993 give_initial_items(op,op->randomitems); 1002 give_initial_items(op,op->randomitems);
994 link_player_skills(op); 1003 link_player_skills(op);
995 esrv_send_inventory(op, op); 1004 esrv_send_inventory(op, op);
996 fix_player(op); 1005 fix_player(op);
1006
1007 /* This moves the player to a different start map, if there
1008 * is one for this race
1009 */
1010 if(*first_map_ext_path) {
1011 object *tmp;
1012 mapstruct *oldmap = op->map;
1013 char mapname[MAX_BUF];
1014 snprintf(mapname, MAX_BUF-1, "%s/%s",
1015 first_map_ext_path, op->arch->name);
1016 tmp=get_object();
1017 EXIT_PATH(tmp) = add_string(mapname);
1018 EXIT_X(tmp) = op->x;
1019 EXIT_Y(tmp) = op->y;
1020 enter_exit(op,tmp); /* we don't really care if it succeeded;
1021 * if the map isn't there, then stay on the
1022 * default initial map */
1023 free_object(tmp);
1024 } else {
1025 LOG(llevDebug,"first_map_ext_path not set\n");
1026 }
997 return 0; 1027 return 0;
998 } 1028 }
999 1029
1000 /* Following actually changes the class - this is the default command 1030 /* Following actually changes the race - this is the default command
1001 * if we don't match with one of the options above. 1031 * if we don't match with one of the options above.
1002 */ 1032 */
1003 1033
1004 tmp_loop = 0; 1034 tmp_loop = 0;
1005 while(!tmp_loop) { 1035 while(!tmp_loop) {
1020 insert_ob_in_map (op, op->map, op,0); 1050 insert_ob_in_map (op, op->map, op,0);
1021 strncpy(op->contr->title, op->arch->clone.name, sizeof(op->contr->title)-1); 1051 strncpy(op->contr->title, op->arch->clone.name, sizeof(op->contr->title)-1);
1022 op->contr->title[sizeof(op->contr->title)-1] = '\0'; 1052 op->contr->title[sizeof(op->contr->title)-1] = '\0';
1023 add_statbonus(op); 1053 add_statbonus(op);
1024 tmp_loop=allowed_class(op); 1054 tmp_loop=allowed_class(op);
1055
1056 if (!strncmp (op->msg, "Edit me", 7)) tmp_loop = 0; // pippijn fucked it up //D//TODO
1025 } 1057 }
1026 update_object(op,UP_OBJ_FACE); 1058 update_object(op,UP_OBJ_FACE);
1027 esrv_update_item(UPD_FACE,op,op); 1059 esrv_update_item(UPD_FACE,op,op);
1028 fix_player(op); 1060 fix_player(op);
1029 op->stats.hp=op->stats.maxhp; 1061 op->stats.hp=op->stats.maxhp;
2060 2092
2061 /* If the creature is a pet, push it even if the player is not 2093 /* If the creature is a pet, push it even if the player is not
2062 * peaceful. Our assumption is the creature is a pet if the 2094 * peaceful. Our assumption is the creature is a pet if the
2063 * player owns it and it is either friendly or unagressive. 2095 * player owns it and it is either friendly or unagressive.
2064 */ 2096 */
2065 if ((op->type==PLAYER) && get_owner(mon)==op && 2097 if ((op->type==PLAYER)
2098#if COZY_SERVER
2099 &&
2100 (
2101 (get_owner(mon) && get_owner(mon)->contr
2102 && same_party (get_owner(mon)->contr->party, op->contr->party))
2103 || get_owner(mon) == op
2104 )
2105#else
2106 && get_owner(mon)==op
2107#endif
2066 (QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY))) 2108 && (QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)))
2067 { 2109 {
2068 /* If we're braced, we don't want to switch places with it */ 2110 /* If we're braced, we don't want to switch places with it */
2069 if (op->contr->braced) return; 2111 if (op->contr->braced) return;
2070 play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER); 2112 play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER);
2071 (void) push_ob(mon,dir,op); 2113 (void) push_ob(mon,dir,op);
2078 * someone, but put it inside this loop so that you won't 2120 * someone, but put it inside this loop so that you won't
2079 * attack them either. 2121 * attack them either.
2080 */ 2122 */
2081 if ((mon->type==PLAYER || mon->enemy != op) && 2123 if ((mon->type==PLAYER || mon->enemy != op) &&
2082 (mon->type==PLAYER || QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)) && 2124 (mon->type==PLAYER || QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)) &&
2083 (op->contr->peaceful && !on_battleground)) { 2125 (
2126#ifdef PROHIBIT_PLAYERKILL
2127 (op->contr->peaceful || (mon->type == PLAYER && mon->contr->peaceful)) &&
2128#else
2129 op->contr->peaceful &&
2130#endif
2131 !on_battleground
2132 )) {
2084 if (!op->contr->braced) { 2133 if (!op->contr->braced) {
2085 play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER); 2134 play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER);
2086 (void) push_ob(mon,dir,op); 2135 (void) push_ob(mon,dir,op);
2087 } else { 2136 } else {
2088 new_draw_info(0, 0,op,"You withhold your attack"); 2137 new_draw_info(0, 0,op,"You withhold your attack");
2216 */ 2265 */
2217int handle_newcs_player(object *op) 2266int handle_newcs_player(object *op)
2218{ 2267{
2219 if (op->contr->hidden) { 2268 if (op->contr->hidden) {
2220 op->invisible = 1000; 2269 op->invisible = 1000;
2221 /* the socket code flasehs the player visible/invisible 2270 /* the socket code flashes the player visible/invisible
2222 * depending on the value if invisible, so we need to 2271 * depending on the value of invisible, so we need to
2223 * alternate it here for it to work correctly. 2272 * alternate it here for it to work correctly.
2224 */ 2273 */
2225 if (pticks & 2) op->invisible--; 2274 if (pticks & 2) op->invisible--;
2226 } 2275 }
2227 else if(op->invisible&&!(QUERY_FLAG(op,FLAG_MAKE_INVIS))) { 2276 else if(op->invisible&&!(QUERY_FLAG(op,FLAG_MAKE_INVIS))) {
2495 } 2544 }
2496 } 2545 }
2497 2546
2498 /* Digestion */ 2547 /* Digestion */
2499 if(--op->last_eat<0) { 2548 if(--op->last_eat<0) {
2549#ifdef COZY_SERVER
2550 int dg = op->contr->digestion>=0 && op->contr->digestion<2 ? 2 : op->contr->digestion;
2551 int bonus=dg>0?dg:0,
2552 penalty=dg<0?-dg:0;
2553#else
2500 int bonus=op->contr->digestion>0?op->contr->digestion:0, 2554 int bonus=op->contr->digestion>0?op->contr->digestion:0,
2501 penalty=op->contr->digestion<0?-op->contr->digestion:0; 2555 penalty=op->contr->digestion<0?-op->contr->digestion:0;
2556#endif
2557
2502 if(op->contr->gen_hp > 0) 2558 if(op->contr->gen_hp > 0)
2503 op->last_eat=25*(1+bonus)/(op->contr->gen_hp+penalty+1); 2559 op->last_eat=25*(1+bonus)/(op->contr->gen_hp+penalty+1);
2504 else 2560 else
2505 op->last_eat=25*(1+bonus)/(penalty +1); 2561 op->last_eat=25*(1+bonus)/(penalty +1);
2506 /* dms do not consume food */ 2562 /* dms do not consume food */
2619 2675
2620 /* Lauwenmark: Handle for plugin death event */ 2676 /* Lauwenmark: Handle for plugin death event */
2621 if (execute_event(op, EVENT_DEATH,NULL,NULL,NULL,SCRIPT_FIX_ALL) != 0) 2677 if (execute_event(op, EVENT_DEATH,NULL,NULL,NULL,SCRIPT_FIX_ALL) != 0)
2622 return; 2678 return;
2623 2679
2680 command_kill_pets (op, 0);
2681
2624 /* Lauwenmark: Handle for the global death event */ 2682 /* Lauwenmark: Handle for the global death event */
2625 execute_global_event(EVENT_PLAYER_DEATH, op); 2683 execute_global_event(EVENT_PLAYER_DEATH, op);
2626 if(op->stats.food<0) { 2684 if(op->stats.food<0) {
2627 if (op->contr->explore) { 2685 if (op->contr->explore) {
2628 new_draw_info(NDI_UNIQUE, 0,op,"You would have starved, but you are"); 2686 new_draw_info(NDI_UNIQUE, 0,op,"You would have starved, but you are");
2656 2714
2657 /* Basically two ways to go - remove a stat permanently, or just 2715 /* Basically two ways to go - remove a stat permanently, or just
2658 * make it depletion. This bunch of code deals with that aspect 2716 * make it depletion. This bunch of code deals with that aspect
2659 * of death. 2717 * of death.
2660 */ 2718 */
2661 2719#ifndef COZY_SERVER
2662 if (settings.balanced_stat_loss) { 2720 if (settings.balanced_stat_loss) {
2663 /* If stat loss is permanent, lose one stat only. */ 2721 /* If stat loss is permanent, lose one stat only. */
2664 /* Lower level chars don't lose as many stats because they suffer 2722 /* Lower level chars don't lose as many stats because they suffer
2665 more if they do. */ 2723 more if they do. */
2666 /* Higher level characters can afford things such as potions of 2724 /* Higher level characters can afford things such as potions of
2675 num_stats_lose = 1; 2733 num_stats_lose = 1;
2676 } 2734 }
2677 lost_a_stat = 0; 2735 lost_a_stat = 0;
2678 2736
2679 for (z=0; z<num_stats_lose; z++) { 2737 for (z=0; z<num_stats_lose; z++) {
2738 i = RANDOM() % NUM_STATS;
2739
2680 if (settings.stat_loss_on_death) { 2740 if (settings.stat_loss_on_death) {
2681 /* Pick a random stat and take a point off it. Tell the player 2741 /* Pick a random stat and take a point off it. Tell the player
2682 * what he lost. 2742 * what he lost.
2683 */ 2743 */
2684 i = RANDOM() % 7;
2685 change_attr_value(&(op->stats), i,-1); 2744 change_attr_value(&(op->stats), i,-1);
2686 check_stat_bounds(&(op->stats)); 2745 check_stat_bounds(&(op->stats));
2687 change_attr_value(&(op->contr->orig_stats), i,-1); 2746 change_attr_value(&(op->contr->orig_stats), i,-1);
2688 check_stat_bounds(&(op->contr->orig_stats)); 2747 check_stat_bounds(&(op->contr->orig_stats));
2689 new_draw_info(NDI_UNIQUE, 0,op, lose_msg[i]); 2748 new_draw_info(NDI_UNIQUE, 0,op, lose_msg[i]);
2691 } else { 2750 } else {
2692 /* deplete a stat */ 2751 /* deplete a stat */
2693 archetype *deparch=find_archetype("depletion"); 2752 archetype *deparch=find_archetype("depletion");
2694 object *dep; 2753 object *dep;
2695 2754
2696 i = RANDOM() % 7;
2697 dep = present_arch_in_ob(deparch,op); 2755 dep = present_arch_in_ob(deparch,op);
2698 if(!dep) { 2756 if(!dep) {
2699 dep = arch_to_object(deparch); 2757 dep = arch_to_object(deparch);
2700 insert_ob_in_ob(dep, op); 2758 insert_ob_in_ob(dep, op);
2701 } 2759 }
2757 " you.", god); 2815 " you.", god);
2758 else 2816 else
2759 new_draw_info(NDI_UNIQUE, 0, op, "For a brief moment you" 2817 new_draw_info(NDI_UNIQUE, 0, op, "For a brief moment you"
2760 " feel a holy presence protecting you."); 2818 " feel a holy presence protecting you.");
2761 } 2819 }
2820#endif
2821 new_draw_info(NDI_UNIQUE, 0, op, "For a brief moment you"
2822 " feel a holy presence protecting you from losing yourself completely.");
2762 2823
2763 /* Put a gravestone up where the character 'almost' died. List the 2824 /* Put a gravestone up where the character 'almost' died. List the
2764 * exp loss on the stone. 2825 * exp loss on the stone.
2765 */ 2826 */
2766 tmp=arch_to_object(find_archetype("gravestone")); 2827 tmp=arch_to_object(find_archetype("gravestone"));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines