1 | /* |
1 | /* |
2 | * static char *rcsid_player_c = |
2 | * static char *rcsid_player_c = |
3 | * "$Id: player.c,v 1.1.1.2 2006/02/22 18:03:23 elmex Exp $"; |
3 | * "$Id: player.c,v 1.13 2006/04/21 14:40:31 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 | |
… | |
… | |
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 |
|
|
44 | extern int same_party (partylist *a, partylist *b); |
|
|
45 | #endif |
42 | |
46 | |
43 | player *find_player(const char *plname) |
47 | player *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) |
… | |
… | |
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; |
… | |
… | |
249 | op->speed_left=0.5; |
253 | op->speed_left=0.5; |
250 | op->speed=1.0; |
254 | op->speed=1.0; |
251 | op->direction=5; /* So player faces south */ |
255 | op->direction=5; /* So player faces south */ |
252 | op->stats.wc=2; |
256 | op->stats.wc=2; |
253 | op->run_away = 25; /* Then we panick... */ |
257 | op->run_away = 25; /* Then we panick... */ |
|
|
258 | p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ |
254 | |
259 | |
255 | roll_stats(op); |
260 | roll_stats(op); |
256 | p->state=ST_ROLL_STAT; |
261 | p->state=ST_ROLL_STAT; |
257 | clear_los(op); |
262 | clear_los(op); |
258 | |
263 | |
… | |
… | |
396 | op=ol->ob; |
401 | op=ol->ob; |
397 | lastdist=rv.distance; |
402 | lastdist=rv.distance; |
398 | } |
403 | } |
399 | } |
404 | } |
400 | for (pl=first_player; pl != NULL; pl=pl->next) { |
405 | for (pl=first_player; pl != NULL; pl=pl->next) { |
401 | if (on_same_map(mon, pl->ob)&& can_detect_enemy(mon, pl->ob,&rv)) { |
406 | if (can_detect_enemy(mon, pl->ob,&rv)) { |
402 | |
407 | |
403 | if(lastdist>rv.distance) { |
408 | if(lastdist>rv.distance) { |
404 | op=pl->ob; |
409 | op=pl->ob; |
405 | lastdist=rv.distance; |
410 | lastdist=rv.distance; |
406 | } |
411 | } |
… | |
… | |
945 | } |
950 | } |
946 | return 0; |
951 | return 0; |
947 | } |
952 | } |
948 | |
953 | |
949 | /* This function takes the key that is passed, and does the |
954 | /* This function takes the key that is passed, and does the |
950 | * appropriate action with it (change class, or other things. |
955 | * appropriate action with it (change race, or other things). |
|
|
956 | * The function name is for historical reasons - now we have |
|
|
957 | * separate race and class; this actually changes the RACE, |
|
|
958 | * not the class. |
951 | */ |
959 | */ |
952 | |
960 | |
953 | int key_change_class(object *op, char key) |
961 | int key_change_class(object *op, char key) |
954 | { |
962 | { |
955 | int tmp_loop; |
963 | int tmp_loop; |
956 | |
964 | |
957 | if(key=='q'||key=='Q') { |
965 | if(key=='q'||key=='Q') { |
958 | remove_ob(op); |
966 | remove_ob(op); |
959 | play_again(op); |
967 | play_again(op); |
960 | return 0; |
968 | return 0; |
… | |
… | |
991 | CLEAR_FLAG(op, FLAG_WIZ); |
999 | CLEAR_FLAG(op, FLAG_WIZ); |
992 | give_initial_items(op,op->randomitems); |
1000 | give_initial_items(op,op->randomitems); |
993 | link_player_skills(op); |
1001 | link_player_skills(op); |
994 | esrv_send_inventory(op, op); |
1002 | esrv_send_inventory(op, op); |
995 | fix_player(op); |
1003 | fix_player(op); |
|
|
1004 | |
|
|
1005 | /* This moves the player to a different start map, if there |
|
|
1006 | * is one for this race |
|
|
1007 | */ |
|
|
1008 | if(*first_map_ext_path) { |
|
|
1009 | object *tmp; |
|
|
1010 | mapstruct *oldmap = op->map; |
|
|
1011 | char mapname[MAX_BUF]; |
|
|
1012 | snprintf(mapname, MAX_BUF-1, "%s/%s", |
|
|
1013 | first_map_ext_path, op->arch->name); |
|
|
1014 | printf("%s\n", mapname); |
|
|
1015 | tmp=get_object(); |
|
|
1016 | EXIT_PATH(tmp) = add_string(mapname); |
|
|
1017 | EXIT_X(tmp) = op->x; |
|
|
1018 | EXIT_Y(tmp) = op->y; |
|
|
1019 | enter_exit(op,tmp); /* we don't really care if it succeeded; |
|
|
1020 | * if the map isn't there, then stay on the |
|
|
1021 | * default initial map */ |
|
|
1022 | free_object(tmp); |
|
|
1023 | } else { |
|
|
1024 | LOG(llevDebug,"first_map_ext_path not set\n"); |
|
|
1025 | } |
996 | return 0; |
1026 | return 0; |
997 | } |
1027 | } |
998 | |
1028 | |
999 | /* Following actually changes the class - this is the default command |
1029 | /* Following actually changes the race - this is the default command |
1000 | * if we don't match with one of the options above. |
1030 | * if we don't match with one of the options above. |
1001 | */ |
1031 | */ |
1002 | |
1032 | |
1003 | tmp_loop = 0; |
1033 | tmp_loop = 0; |
1004 | while(!tmp_loop) { |
1034 | while(!tmp_loop) { |
… | |
… | |
2059 | |
2089 | |
2060 | /* If the creature is a pet, push it even if the player is not |
2090 | /* If the creature is a pet, push it even if the player is not |
2061 | * peaceful. Our assumption is the creature is a pet if the |
2091 | * peaceful. Our assumption is the creature is a pet if the |
2062 | * player owns it and it is either friendly or unagressive. |
2092 | * player owns it and it is either friendly or unagressive. |
2063 | */ |
2093 | */ |
2064 | if ((op->type==PLAYER) && get_owner(mon)==op && |
2094 | if ((op->type==PLAYER) |
|
|
2095 | #if COZY_SERVER |
|
|
2096 | && |
|
|
2097 | ( |
|
|
2098 | (get_owner(mon) && get_owner(mon)->contr |
|
|
2099 | && same_party (get_owner(mon)->contr->party, op->contr->party)) |
|
|
2100 | || get_owner(mon) == op |
|
|
2101 | ) |
|
|
2102 | #else |
|
|
2103 | && get_owner(mon)==op |
|
|
2104 | #endif |
2065 | (QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY))) |
2105 | && (QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY))) |
2066 | { |
2106 | { |
2067 | /* If we're braced, we don't want to switch places with it */ |
2107 | /* If we're braced, we don't want to switch places with it */ |
2068 | if (op->contr->braced) return; |
2108 | if (op->contr->braced) return; |
2069 | play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER); |
2109 | play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER); |
2070 | (void) push_ob(mon,dir,op); |
2110 | (void) push_ob(mon,dir,op); |
… | |
… | |
2077 | * someone, but put it inside this loop so that you won't |
2117 | * someone, but put it inside this loop so that you won't |
2078 | * attack them either. |
2118 | * attack them either. |
2079 | */ |
2119 | */ |
2080 | if ((mon->type==PLAYER || mon->enemy != op) && |
2120 | if ((mon->type==PLAYER || mon->enemy != op) && |
2081 | (mon->type==PLAYER || QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)) && |
2121 | (mon->type==PLAYER || QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)) && |
2082 | (op->contr->peaceful && !on_battleground)) { |
2122 | ( |
|
|
2123 | #ifdef PROHIBIT_PLAYERKILL |
|
|
2124 | (op->contr->peaceful || (mon->type == PLAYER && mon->contr->peaceful)) && |
|
|
2125 | #else |
|
|
2126 | op->contr->peaceful && |
|
|
2127 | #endif |
|
|
2128 | !on_battleground |
|
|
2129 | )) { |
2083 | if (!op->contr->braced) { |
2130 | if (!op->contr->braced) { |
2084 | play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER); |
2131 | play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER); |
2085 | (void) push_ob(mon,dir,op); |
2132 | (void) push_ob(mon,dir,op); |
2086 | } else { |
2133 | } else { |
2087 | new_draw_info(0, 0,op,"You withhold your attack"); |
2134 | new_draw_info(0, 0,op,"You withhold your attack"); |
… | |
… | |
2215 | */ |
2262 | */ |
2216 | int handle_newcs_player(object *op) |
2263 | int handle_newcs_player(object *op) |
2217 | { |
2264 | { |
2218 | if (op->contr->hidden) { |
2265 | if (op->contr->hidden) { |
2219 | op->invisible = 1000; |
2266 | op->invisible = 1000; |
2220 | /* the socket code flasehs the player visible/invisible |
2267 | /* the socket code flashes the player visible/invisible |
2221 | * depending on the value if invisible, so we need to |
2268 | * depending on the value of invisible, so we need to |
2222 | * alternate it here for it to work correctly. |
2269 | * alternate it here for it to work correctly. |
2223 | */ |
2270 | */ |
2224 | if (pticks & 2) op->invisible--; |
2271 | if (pticks & 2) op->invisible--; |
2225 | } |
2272 | } |
2226 | else if(op->invisible&&!(QUERY_FLAG(op,FLAG_MAKE_INVIS))) { |
2273 | else if(op->invisible&&!(QUERY_FLAG(op,FLAG_MAKE_INVIS))) { |
… | |
… | |
2494 | } |
2541 | } |
2495 | } |
2542 | } |
2496 | |
2543 | |
2497 | /* Digestion */ |
2544 | /* Digestion */ |
2498 | if(--op->last_eat<0) { |
2545 | if(--op->last_eat<0) { |
|
|
2546 | #ifdef COZY_SERVER |
|
|
2547 | int dg = op->contr->digestion>=0 && op->contr->digestion<2 ? 2 : op->contr->digestion; |
|
|
2548 | int bonus=dg>0?dg:0, |
|
|
2549 | penalty=dg<0?-dg:0; |
|
|
2550 | #else |
2499 | int bonus=op->contr->digestion>0?op->contr->digestion:0, |
2551 | int bonus=op->contr->digestion>0?op->contr->digestion:0, |
2500 | penalty=op->contr->digestion<0?-op->contr->digestion:0; |
2552 | penalty=op->contr->digestion<0?-op->contr->digestion:0; |
|
|
2553 | #endif |
|
|
2554 | |
2501 | if(op->contr->gen_hp > 0) |
2555 | if(op->contr->gen_hp > 0) |
2502 | op->last_eat=25*(1+bonus)/(op->contr->gen_hp+penalty+1); |
2556 | op->last_eat=25*(1+bonus)/(op->contr->gen_hp+penalty+1); |
2503 | else |
2557 | else |
2504 | op->last_eat=25*(1+bonus)/(penalty +1); |
2558 | op->last_eat=25*(1+bonus)/(penalty +1); |
2505 | /* dms do not consume food */ |
2559 | /* dms do not consume food */ |
… | |
… | |
2655 | |
2709 | |
2656 | /* Basically two ways to go - remove a stat permanently, or just |
2710 | /* Basically two ways to go - remove a stat permanently, or just |
2657 | * make it depletion. This bunch of code deals with that aspect |
2711 | * make it depletion. This bunch of code deals with that aspect |
2658 | * of death. |
2712 | * of death. |
2659 | */ |
2713 | */ |
2660 | |
2714 | #ifndef COZY_SERVER |
2661 | if (settings.balanced_stat_loss) { |
2715 | if (settings.balanced_stat_loss) { |
2662 | /* If stat loss is permanent, lose one stat only. */ |
2716 | /* If stat loss is permanent, lose one stat only. */ |
2663 | /* Lower level chars don't lose as many stats because they suffer |
2717 | /* Lower level chars don't lose as many stats because they suffer |
2664 | more if they do. */ |
2718 | more if they do. */ |
2665 | /* Higher level characters can afford things such as potions of |
2719 | /* Higher level characters can afford things such as potions of |
… | |
… | |
2674 | num_stats_lose = 1; |
2728 | num_stats_lose = 1; |
2675 | } |
2729 | } |
2676 | lost_a_stat = 0; |
2730 | lost_a_stat = 0; |
2677 | |
2731 | |
2678 | for (z=0; z<num_stats_lose; z++) { |
2732 | for (z=0; z<num_stats_lose; z++) { |
|
|
2733 | i = RANDOM() % NUM_STATS; |
|
|
2734 | |
2679 | if (settings.stat_loss_on_death) { |
2735 | if (settings.stat_loss_on_death) { |
2680 | /* Pick a random stat and take a point off it. Tell the player |
2736 | /* Pick a random stat and take a point off it. Tell the player |
2681 | * what he lost. |
2737 | * what he lost. |
2682 | */ |
2738 | */ |
2683 | i = RANDOM() % 7; |
|
|
2684 | change_attr_value(&(op->stats), i,-1); |
2739 | change_attr_value(&(op->stats), i,-1); |
2685 | check_stat_bounds(&(op->stats)); |
2740 | check_stat_bounds(&(op->stats)); |
2686 | change_attr_value(&(op->contr->orig_stats), i,-1); |
2741 | change_attr_value(&(op->contr->orig_stats), i,-1); |
2687 | check_stat_bounds(&(op->contr->orig_stats)); |
2742 | check_stat_bounds(&(op->contr->orig_stats)); |
2688 | new_draw_info(NDI_UNIQUE, 0,op, lose_msg[i]); |
2743 | new_draw_info(NDI_UNIQUE, 0,op, lose_msg[i]); |
… | |
… | |
2690 | } else { |
2745 | } else { |
2691 | /* deplete a stat */ |
2746 | /* deplete a stat */ |
2692 | archetype *deparch=find_archetype("depletion"); |
2747 | archetype *deparch=find_archetype("depletion"); |
2693 | object *dep; |
2748 | object *dep; |
2694 | |
2749 | |
2695 | i = RANDOM() % 7; |
|
|
2696 | dep = present_arch_in_ob(deparch,op); |
2750 | dep = present_arch_in_ob(deparch,op); |
2697 | if(!dep) { |
2751 | if(!dep) { |
2698 | dep = arch_to_object(deparch); |
2752 | dep = arch_to_object(deparch); |
2699 | insert_ob_in_ob(dep, op); |
2753 | insert_ob_in_ob(dep, op); |
2700 | } |
2754 | } |
… | |
… | |
2756 | " you.", god); |
2810 | " you.", god); |
2757 | else |
2811 | else |
2758 | new_draw_info(NDI_UNIQUE, 0, op, "For a brief moment you" |
2812 | new_draw_info(NDI_UNIQUE, 0, op, "For a brief moment you" |
2759 | " feel a holy presence protecting you."); |
2813 | " feel a holy presence protecting you."); |
2760 | } |
2814 | } |
|
|
2815 | #endif |
|
|
2816 | new_draw_info(NDI_UNIQUE, 0, op, "For a brief moment you" |
|
|
2817 | " feel a holy presence protecting you from losing yourself completely."); |
2761 | |
2818 | |
2762 | /* Put a gravestone up where the character 'almost' died. List the |
2819 | /* Put a gravestone up where the character 'almost' died. List the |
2763 | * exp loss on the stone. |
2820 | * exp loss on the stone. |
2764 | */ |
2821 | */ |
2765 | tmp=arch_to_object(find_archetype("gravestone")); |
2822 | tmp=arch_to_object(find_archetype("gravestone")); |