1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_player_c = |
|
|
4 | * "$Id: player.C,v 1.19 2006/09/11 23:53:30 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | The author can be reached via e-mail to crossfire-devel@real-time.com |
21 | The author can be reached via e-mail to <crossfire@schmorp.de> |
28 | */ |
22 | */ |
29 | |
23 | |
30 | #include <global.h> |
24 | #include <global.h> |
31 | #ifndef WIN32 /* ---win32 remove headers */ |
25 | #ifndef WIN32 /* ---win32 remove headers */ |
32 | # include <pwd.h> |
26 | # include <pwd.h> |
… | |
… | |
285 | p->peaceful = 1; /* default peaceful */ |
279 | p->peaceful = 1; /* default peaceful */ |
286 | p->do_los = 1; |
280 | p->do_los = 1; |
287 | p->explore = 0; |
281 | p->explore = 0; |
288 | p->no_shout = 0; /* default can shout */ |
282 | p->no_shout = 0; /* default can shout */ |
289 | |
283 | |
290 | strncpy (p->title, op->arch->clone.name, sizeof (p->title) - 1); |
284 | assign (p->title, op->arch->clone.name); |
291 | p->title[sizeof (p->title) - 1] = '\0'; |
|
|
292 | op->race = op->arch->clone.race; |
285 | op->race = op->arch->clone.race; |
293 | |
286 | |
294 | CLEAR_FLAG (op, FLAG_READY_SKILL); |
287 | CLEAR_FLAG (op, FLAG_READY_SKILL); |
295 | |
288 | |
296 | /* we need to clear these to -1 and not zero - otherwise, |
289 | /* we need to clear these to -1 and not zero - otherwise, |
… | |
… | |
1000 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
993 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
1001 | return 1; |
994 | return 1; |
1002 | } |
995 | } |
1003 | switch (key) |
996 | switch (key) |
1004 | { |
997 | { |
1005 | case 'n': |
998 | case 'n': |
1006 | case 'N': |
999 | case 'N': |
1007 | { |
1000 | { |
1008 | SET_FLAG (op, FLAG_WIZ); |
1001 | SET_FLAG (op, FLAG_WIZ); |
1009 | if (op->map == NULL) |
1002 | if (op->map == NULL) |
1010 | { |
1003 | { |
1011 | LOG (llevError, "Map == NULL in state 2\n"); |
1004 | LOG (llevError, "Map == NULL in state 2\n"); |
1012 | break; |
1005 | break; |
1013 | } |
1006 | } |
1014 | |
1007 | |
1015 | #if 0 |
1008 | #if 0 |
1016 | /* So that enter_exit will put us at startx/starty */ |
1009 | /* So that enter_exit will put us at startx/starty */ |
1017 | op->x = -1; |
1010 | op->x = -1; |
1018 | |
1011 | |
1019 | enter_exit (op, NULL); |
1012 | enter_exit (op, NULL); |
1020 | #endif |
1013 | #endif |
1021 | SET_ANIMATION (op, 2); /* So player faces south */ |
1014 | SET_ANIMATION (op, 2); /* So player faces south */ |
1022 | /* Enter exit adds a player otherwise */ |
1015 | /* Enter exit adds a player otherwise */ |
1023 | add_statbonus (op); |
1016 | add_statbonus (op); |
1024 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, |
1017 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, |
1025 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); |
1018 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); |
1026 | op->contr->state = ST_CHANGE_CLASS; |
1019 | op->contr->state = ST_CHANGE_CLASS; |
1027 | if (op->msg) |
1020 | if (op->msg) |
1028 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1021 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1029 | return 0; |
|
|
1030 | } |
|
|
1031 | case 'y': |
|
|
1032 | case 'Y': |
|
|
1033 | roll_stats (op); |
|
|
1034 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
|
|
1035 | return 1; |
|
|
1036 | |
|
|
1037 | case 'q': |
|
|
1038 | case 'Q': |
|
|
1039 | play_again (op); |
|
|
1040 | return 1; |
|
|
1041 | |
|
|
1042 | default: |
|
|
1043 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); |
|
|
1044 | return 0; |
1022 | return 0; |
|
|
1023 | } |
|
|
1024 | case 'y': |
|
|
1025 | case 'Y': |
|
|
1026 | roll_stats (op); |
|
|
1027 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
|
|
1028 | return 1; |
|
|
1029 | |
|
|
1030 | case 'q': |
|
|
1031 | case 'Q': |
|
|
1032 | play_again (op); |
|
|
1033 | return 1; |
|
|
1034 | |
|
|
1035 | default: |
|
|
1036 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); |
|
|
1037 | return 0; |
1045 | } |
1038 | } |
1046 | return 0; |
1039 | return 0; |
1047 | } |
1040 | } |
1048 | |
1041 | |
1049 | /* This function takes the key that is passed, and does the |
1042 | /* This function takes the key that is passed, and does the |
… | |
… | |
1140 | op->name = op->name_pl = name; |
1133 | op->name = op->name_pl = name; |
1141 | op->x = x; |
1134 | op->x = x; |
1142 | op->y = y; |
1135 | op->y = y; |
1143 | SET_ANIMATION (op, 2); /* So player faces south */ |
1136 | SET_ANIMATION (op, 2); /* So player faces south */ |
1144 | insert_ob_in_map (op, op->map, op, 0); |
1137 | insert_ob_in_map (op, op->map, op, 0); |
1145 | strncpy (op->contr->title, op->arch->clone.name, sizeof (op->contr->title) - 1); |
1138 | assign (op->contr->title, op->arch->clone.name); |
1146 | op->contr->title[sizeof (op->contr->title) - 1] = '\0'; |
|
|
1147 | add_statbonus (op); |
1139 | add_statbonus (op); |
1148 | tmp_loop = allowed_class (op); |
1140 | tmp_loop = allowed_class (op); |
1149 | } |
1141 | } |
1150 | |
1142 | |
1151 | update_object (op, UP_OBJ_FACE); |
1143 | update_object (op, UP_OBJ_FACE); |
1152 | esrv_update_item (UPD_FACE, op, op); |
1144 | esrv_update_item (UPD_FACE, op, op); |
1153 | fix_player (op); |
1145 | fix_player (op); |
1154 | op->stats.hp = op->stats.maxhp; |
1146 | op->stats.hp = op->stats.maxhp; |
1155 | op->stats.sp = op->stats.maxsp; |
1147 | op->stats.sp = op->stats.maxsp; |
1156 | op->stats.grace = 0; |
1148 | op->stats.grace = 0; |
|
|
1149 | |
1157 | if (op->msg) |
1150 | if (op->msg) |
1158 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1151 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
|
|
1152 | |
1159 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
1153 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
1160 | return 0; |
1154 | return 0; |
1161 | } |
1155 | } |
1162 | |
1156 | |
1163 | int |
1157 | int |
… | |
… | |
1313 | /* high not bit set? We're using the old autopickup model */ |
1307 | /* high not bit set? We're using the old autopickup model */ |
1314 | if (!(op->contr->mode & PU_NEWMODE)) |
1308 | if (!(op->contr->mode & PU_NEWMODE)) |
1315 | { |
1309 | { |
1316 | switch (op->contr->mode) |
1310 | switch (op->contr->mode) |
1317 | { |
1311 | { |
1318 | case 0: |
1312 | case 0: |
1319 | return 1; /* don't pick up */ |
1313 | return 1; /* don't pick up */ |
1320 | case 1: |
1314 | case 1: |
|
|
1315 | pick_up (op, tmp); |
|
|
1316 | return 1; |
|
|
1317 | case 2: |
|
|
1318 | pick_up (op, tmp); |
|
|
1319 | return 0; |
|
|
1320 | case 3: |
|
|
1321 | return 0; /* stop before pickup */ |
|
|
1322 | case 4: |
|
|
1323 | pick_up (op, tmp); |
|
|
1324 | break; |
|
|
1325 | case 5: |
|
|
1326 | pick_up (op, tmp); |
|
|
1327 | stop = 1; |
|
|
1328 | break; |
|
|
1329 | case 6: |
|
|
1330 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
1321 | pick_up (op, tmp); |
1331 | pick_up (op, tmp); |
1322 | return 1; |
1332 | break; |
|
|
1333 | |
1323 | case 2: |
1334 | case 7: |
|
|
1335 | if (tmp->type == MONEY || tmp->type == GEM) |
1324 | pick_up (op, tmp); |
1336 | pick_up (op, tmp); |
1325 | return 0; |
1337 | break; |
1326 | case 3: |
1338 | |
1327 | return 0; /* stop before pickup */ |
1339 | default: |
1328 | case 4: |
1340 | /* use value density */ |
|
|
1341 | if (!QUERY_FLAG (tmp, FLAG_UNPAID) |
|
|
1342 | && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode) |
1329 | pick_up (op, tmp); |
1343 | pick_up (op, tmp); |
1330 | break; |
|
|
1331 | case 5: |
|
|
1332 | pick_up (op, tmp); |
|
|
1333 | stop = 1; |
|
|
1334 | break; |
|
|
1335 | case 6: |
|
|
1336 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
|
|
1337 | pick_up (op, tmp); |
|
|
1338 | break; |
|
|
1339 | |
|
|
1340 | case 7: |
|
|
1341 | if (tmp->type == MONEY || tmp->type == GEM) |
|
|
1342 | pick_up (op, tmp); |
|
|
1343 | break; |
|
|
1344 | |
|
|
1345 | default: |
|
|
1346 | /* use value density */ |
|
|
1347 | if (!QUERY_FLAG (tmp, FLAG_UNPAID) |
|
|
1348 | && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode) |
|
|
1349 | pick_up (op, tmp); |
|
|
1350 | } |
1344 | } |
1351 | } |
1345 | } |
1352 | else |
1346 | else |
1353 | { /* old model */ |
1347 | { /* old model */ |
1354 | /* NEW pickup handling */ |
1348 | /* NEW pickup handling */ |
… | |
… | |
2126 | if (action_makes_visible (op)) |
2120 | if (action_makes_visible (op)) |
2127 | make_visible (op); |
2121 | make_visible (op); |
2128 | |
2122 | |
2129 | switch (op->contr->shoottype) |
2123 | switch (op->contr->shoottype) |
2130 | { |
2124 | { |
2131 | case range_none: |
2125 | case range_none: |
2132 | return; |
2126 | return; |
2133 | |
2127 | |
2134 | case range_bow: |
2128 | case range_bow: |
2135 | player_fire_bow (op, dir); |
2129 | player_fire_bow (op, dir); |
2136 | return; |
2130 | return; |
2137 | |
2131 | |
2138 | case range_magic: /* Casting spells */ |
2132 | case range_magic: /* Casting spells */ |
2139 | spellcost = (cast_spell (op, op, dir, op->contr->ranges[range_magic], op->contr->spellparam[0] ? op->contr->spellparam : NULL)); |
2133 | spellcost = (cast_spell (op, op, dir, op->contr->ranges[range_magic], op->contr->spellparam[0] ? op->contr->spellparam : 0)); |
2140 | return; |
2134 | return; |
2141 | |
2135 | |
2142 | case range_misc: |
2136 | case range_misc: |
2143 | fire_misc_object (op, dir); |
2137 | fire_misc_object (op, dir); |
2144 | return; |
2138 | return; |
2145 | |
2139 | |
2146 | case range_golem: /* Control summoned monsters from scrolls */ |
2140 | case range_golem: /* Control summoned monsters from scrolls */ |
2147 | if (op->contr->ranges[range_golem] == NULL || op->contr->golem_count != op->contr->ranges[range_golem]->count) |
2141 | if (op->contr->ranges[range_golem] == NULL || op->contr->golem_count != op->contr->ranges[range_golem]->count) |
2148 | { |
2142 | { |
2149 | op->contr->ranges[range_golem] = NULL; |
2143 | op->contr->ranges[range_golem] = NULL; |
2150 | op->contr->shoottype = range_none; |
2144 | op->contr->shoottype = range_none; |
2151 | op->contr->golem_count = 0; |
2145 | op->contr->golem_count = 0; |
2152 | } |
2146 | } |
2153 | else |
2147 | else |
2154 | control_golem (op->contr->ranges[range_golem], dir); |
2148 | control_golem (op->contr->ranges[range_golem], dir); |
2155 | return; |
2149 | return; |
2156 | |
2150 | |
2157 | case range_skill: |
2151 | case range_skill: |
2158 | if (!op->chosen_skill) |
2152 | if (!op->chosen_skill) |
2159 | { |
2153 | { |
2160 | if (op->type == PLAYER) |
2154 | if (op->type == PLAYER) |
2161 | new_draw_info (NDI_UNIQUE, 0, op, "You have no applicable skill to use."); |
2155 | new_draw_info (NDI_UNIQUE, 0, op, "You have no applicable skill to use."); |
2162 | return; |
2156 | return; |
2163 | } |
2157 | } |
2164 | (void) do_skill (op, op, op->chosen_skill, dir, NULL); |
2158 | (void) do_skill (op, op, op->chosen_skill, dir, NULL); |
2165 | return; |
2159 | return; |
2166 | case range_builder: |
2160 | case range_builder: |
2167 | apply_map_builder (op, dir); |
2161 | apply_map_builder (op, dir); |
2168 | return; |
2162 | return; |
2169 | default: |
2163 | default: |
2170 | new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type."); |
2164 | new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type."); |
2171 | return; |
2165 | return; |
2172 | } |
2166 | } |
2173 | } |
2167 | } |
2174 | |
2168 | |
2175 | |
2169 | |
2176 | |
2170 | |
… | |
… | |
2983 | { |
2977 | { |
2984 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); |
2978 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); |
2985 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life..."); |
2979 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life..."); |
2986 | |
2980 | |
2987 | /* restore player */ |
2981 | /* restore player */ |
2988 | at = find_archetype ("poisoning"); |
2982 | at = archetype::find ("poisoning"); |
2989 | tmp = present_arch_in_ob (at, op); |
2983 | tmp = present_arch_in_ob (at, op); |
2990 | if (tmp) |
2984 | if (tmp) |
2991 | { |
2985 | { |
2992 | remove_ob (tmp); |
2986 | remove_ob (tmp); |
2993 | free_object (tmp); |
2987 | free_object (tmp); |
2994 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
2988 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
2995 | } |
2989 | } |
2996 | |
2990 | |
2997 | at = find_archetype ("confusion"); |
2991 | at = archetype::find ("confusion"); |
2998 | tmp = present_arch_in_ob (at, op); |
2992 | tmp = present_arch_in_ob (at, op); |
2999 | if (tmp) |
2993 | if (tmp) |
3000 | { |
2994 | { |
3001 | remove_ob (tmp); |
2995 | remove_ob (tmp); |
3002 | free_object (tmp); |
2996 | free_object (tmp); |
… | |
… | |
3007 | op->stats.hp = op->stats.maxhp; |
3001 | op->stats.hp = op->stats.maxhp; |
3008 | if (op->stats.food <= 0) |
3002 | if (op->stats.food <= 0) |
3009 | op->stats.food = 999; |
3003 | op->stats.food = 999; |
3010 | |
3004 | |
3011 | /* create a bodypart-trophy to make the winner happy */ |
3005 | /* create a bodypart-trophy to make the winner happy */ |
3012 | tmp = arch_to_object (find_archetype ("finger")); |
3006 | tmp = arch_to_object (archetype::find ("finger")); |
3013 | if (tmp != NULL) |
3007 | if (tmp != NULL) |
3014 | { |
3008 | { |
3015 | sprintf (buf, "%s's finger", &op->name); |
3009 | sprintf (buf, "%s's finger", &op->name); |
3016 | tmp->name = buf; |
3010 | tmp->name = buf; |
3017 | sprintf (buf, " This finger has been cut off %s\n" |
3011 | sprintf (buf, " This finger has been cut off %s\n" |
… | |
… | |
3114 | lost_a_stat = 1; |
3108 | lost_a_stat = 1; |
3115 | } |
3109 | } |
3116 | else |
3110 | else |
3117 | { |
3111 | { |
3118 | /* deplete a stat */ |
3112 | /* deplete a stat */ |
3119 | archetype *deparch = find_archetype ("depletion"); |
3113 | archetype *deparch = archetype::find ("depletion"); |
3120 | object *dep; |
3114 | object *dep; |
3121 | |
3115 | |
3122 | dep = present_arch_in_ob (deparch, op); |
3116 | dep = present_arch_in_ob (deparch, op); |
3123 | if (!dep) |
3117 | if (!dep) |
3124 | { |
3118 | { |
… | |
… | |
3194 | new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely."); |
3188 | new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely."); |
3195 | |
3189 | |
3196 | /* Put a gravestone up where the character 'almost' died. List the |
3190 | /* Put a gravestone up where the character 'almost' died. List the |
3197 | * exp loss on the stone. |
3191 | * exp loss on the stone. |
3198 | */ |
3192 | */ |
3199 | tmp = arch_to_object (find_archetype ("gravestone")); |
3193 | tmp = arch_to_object (archetype::find ("gravestone")); |
3200 | sprintf (buf, "%s's gravestone", &op->name); |
3194 | sprintf (buf, "%s's gravestone", &op->name); |
3201 | tmp->name = buf; |
3195 | tmp->name = buf; |
3202 | sprintf (buf, "%s's gravestones", &op->name); |
3196 | sprintf (buf, "%s's gravestones", &op->name); |
3203 | tmp->name_pl = buf; |
3197 | tmp->name_pl = buf; |
3204 | 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); |
3198 | 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); |
… | |
… | |
3215 | |
3209 | |
3216 | /**************************************/ |
3210 | /**************************************/ |
3217 | |
3211 | |
3218 | /* remove any poisoning and confusion the character may be suffering. */ |
3212 | /* remove any poisoning and confusion the character may be suffering. */ |
3219 | /* restore player */ |
3213 | /* restore player */ |
3220 | at = find_archetype ("poisoning"); |
3214 | at = archetype::find ("poisoning"); |
3221 | tmp = present_arch_in_ob (at, op); |
3215 | tmp = present_arch_in_ob (at, op); |
3222 | if (tmp) |
3216 | if (tmp) |
3223 | { |
3217 | { |
3224 | remove_ob (tmp); |
3218 | remove_ob (tmp); |
3225 | free_object (tmp); |
3219 | free_object (tmp); |
3226 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
3220 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
3227 | } |
3221 | } |
3228 | |
3222 | |
3229 | at = find_archetype ("confusion"); |
3223 | at = archetype::find ("confusion"); |
3230 | tmp = present_arch_in_ob (at, op); |
3224 | tmp = present_arch_in_ob (at, op); |
3231 | if (tmp) |
3225 | if (tmp) |
3232 | { |
3226 | { |
3233 | remove_ob (tmp); |
3227 | remove_ob (tmp); |
3234 | free_object (tmp); |
3228 | free_object (tmp); |
… | |
… | |
3356 | } |
3350 | } |
3357 | |
3351 | |
3358 | play_again (op); |
3352 | play_again (op); |
3359 | |
3353 | |
3360 | /* peterm: added to create a corpse at deathsite. */ |
3354 | /* peterm: added to create a corpse at deathsite. */ |
3361 | tmp = arch_to_object (find_archetype ("corpse_pl")); |
3355 | tmp = arch_to_object (archetype::find ("corpse_pl")); |
3362 | sprintf (buf, "%s", &op->name); |
3356 | sprintf (buf, "%s", &op->name); |
3363 | tmp->name = tmp->name_pl = buf; |
3357 | tmp->name = tmp->name_pl = buf; |
3364 | tmp->level = op->level; |
3358 | tmp->level = op->level; |
3365 | tmp->x = x; |
3359 | tmp->x = x; |
3366 | tmp->y = y; |
3360 | tmp->y = y; |