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.20 by root, Tue Sep 12 17:54:41 2006 UTC vs.
Revision 1.27 by root, Wed Sep 27 00:36:09 2006 UTC

16 16
17 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
18 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 20
21 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>
22*/ 22*/
23 23
24#include <global.h> 24#include <global.h>
25#ifndef WIN32 /* ---win32 remove headers */ 25#ifndef WIN32 /* ---win32 remove headers */
26# include <pwd.h> 26# include <pwd.h>
279 p->peaceful = 1; /* default peaceful */ 279 p->peaceful = 1; /* default peaceful */
280 p->do_los = 1; 280 p->do_los = 1;
281 p->explore = 0; 281 p->explore = 0;
282 p->no_shout = 0; /* default can shout */ 282 p->no_shout = 0; /* default can shout */
283 283
284 strncpy (p->title, op->arch->clone.name, sizeof (p->title) - 1); 284 assign (p->title, op->arch->clone.name);
285 p->title[sizeof (p->title) - 1] = '\0';
286 op->race = op->arch->clone.race; 285 op->race = op->arch->clone.race;
287 286
288 CLEAR_FLAG (op, FLAG_READY_SKILL); 287 CLEAR_FLAG (op, FLAG_READY_SKILL);
289 288
290 /* we need to clear these to -1 and not zero - otherwise, 289 /* we need to clear these to -1 and not zero - otherwise,
330 player *p; 329 player *p;
331 330
332 p = get_player (NULL); 331 p = get_player (NULL);
333 p->socket = *ns; 332 p->socket = *ns;
334 p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 333 p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent));
334
335 if (p->socket.faces_sent == NULL) 335 if (p->socket.faces_sent == NULL)
336 fatal (OUT_OF_MEMORY); 336 fatal (OUT_OF_MEMORY);
337
337 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 338 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent));
338 /* Needed because the socket we just copied over needs to be cleared. 339 /* Needed because the socket we just copied over needs to be cleared.
339 * Note that this can result in a client reset if there is partial data 340 * Note that this can result in a client reset if there is partial data
340 * on the uncoming socket. 341 * on the uncoming socket.
341 */ 342 */
346 add_friendly_object (p->ob); 347 add_friendly_object (p->ob);
347 send_rules (p->ob); 348 send_rules (p->ob);
348 send_news (p->ob); 349 send_news (p->ob);
349 display_motd (p->ob); 350 display_motd (p->ob);
350 get_name (p->ob); 351 get_name (p->ob);
352
351 return 0; 353 return 0;
352} 354}
353 355
354/* 356/*
355 * get_player_archetype() return next player archetype from archetype 357 * get_player_archetype() return next player archetype from archetype
490path_to_player (object *mon, object *pl, unsigned mindiff) 492path_to_player (object *mon, object *pl, unsigned mindiff)
491{ 493{
492 rv_vector rv; 494 rv_vector rv;
493 sint16 x, y; 495 sint16 x, y;
494 int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked; 496 int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked;
495 mapstruct *m, *lastmap; 497 maptile *m, *lastmap;
496 498
497 get_rangevector (mon, pl, &rv, 0); 499 get_rangevector (mon, pl, &rv, 0);
498 500
499 if (rv.distance < mindiff) 501 if (rv.distance < mindiff)
500 return 0; 502 return 0;
766 player *pl = op->contr; 768 player *pl = op->contr;
767 shstr name = op->name; 769 shstr name = op->name;
768 770
769 op->contr = 0; 771 op->contr = 0;
770 op->type = 0; 772 op->type = 0;
771 op->free (1); 773 op->destroy (1);
772 pl = get_player (pl); 774 pl = get_player (pl);
773 op = pl->ob; 775 op = pl->ob;
774 add_friendly_object (op); 776 add_friendly_object (op);
775 op->contr->password[0] = '~'; 777 op->contr->password[0] = '~';
776 op->name = op->name_pl = 0; 778 op->name = op->name_pl = 0;
1134 op->name = op->name_pl = name; 1136 op->name = op->name_pl = name;
1135 op->x = x; 1137 op->x = x;
1136 op->y = y; 1138 op->y = y;
1137 SET_ANIMATION (op, 2); /* So player faces south */ 1139 SET_ANIMATION (op, 2); /* So player faces south */
1138 insert_ob_in_map (op, op->map, op, 0); 1140 insert_ob_in_map (op, op->map, op, 0);
1139 strncpy (op->contr->title, op->arch->clone.name, sizeof (op->contr->title) - 1); 1141 assign (op->contr->title, op->arch->clone.name);
1140 op->contr->title[sizeof (op->contr->title) - 1] = '\0';
1141 add_statbonus (op); 1142 add_statbonus (op);
1142 tmp_loop = allowed_class (op); 1143 tmp_loop = allowed_class (op);
1143 } 1144 }
1144 1145
1145 update_object (op, UP_OBJ_FACE); 1146 update_object (op, UP_OBJ_FACE);
1146 esrv_update_item (UPD_FACE, op, op); 1147 esrv_update_item (UPD_FACE, op, op);
1147 fix_player (op); 1148 fix_player (op);
1148 op->stats.hp = op->stats.maxhp; 1149 op->stats.hp = op->stats.maxhp;
1149 op->stats.sp = op->stats.maxsp; 1150 op->stats.sp = op->stats.maxsp;
1150 op->stats.grace = 0; 1151 op->stats.grace = 0;
1152
1151 if (op->msg) 1153 if (op->msg)
1152 new_draw_info (NDI_BLUE, 0, op, op->msg); 1154 new_draw_info (NDI_BLUE, 0, op, op->msg);
1155
1153 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); 1156 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n");
1154 return 0; 1157 return 0;
1155} 1158}
1156 1159
1157int 1160int
1180 if (settings.set_title == TRUE) 1183 if (settings.set_title == TRUE)
1181 op->contr->own_title[0] = '\0'; 1184 op->contr->own_title[0] = '\0';
1182 1185
1183 if (!QUERY_FLAG (op, FLAG_WAS_WIZ)) 1186 if (!QUERY_FLAG (op, FLAG_WAS_WIZ))
1184 { 1187 {
1185 mapstruct *mp, *next; 1188 maptile *mp, *next;
1186 1189
1187 /* We need to hunt for any per player unique maps in memory and 1190 /* We need to hunt for any per player unique maps in memory and
1188 * get rid of them. The trailing slash in the path is intentional, 1191 * get rid of them. The trailing slash in the path is intentional,
1189 * so that players named 'Ab' won't match against players 'Abe' pathname 1192 * so that players named 'Ab' won't match against players 'Abe' pathname
1190 */ 1193 */
1264 */ 1267 */
1265int 1268int
1266check_pick (object *op) 1269check_pick (object *op)
1267{ 1270{
1268 object *tmp, *next; 1271 object *tmp, *next;
1269 tag_t next_tag = 0, op_tag;
1270 int stop = 0; 1272 int stop = 0;
1271 int j, k, wvratio; 1273 int j, k, wvratio;
1272 char putstring[128], tmpstr[16]; 1274 char putstring[128], tmpstr[16];
1273 1275
1274
1275 /* if you're flying, you cna't pick up anything */ 1276 /* if you're flying, you cna't pick up anything */
1276 if (op->move_type & MOVE_FLYING) 1277 if (op->move_type & MOVE_FLYING)
1277 return 1; 1278 return 1;
1278 1279
1279 op_tag = op->count;
1280
1281 next = op->below; 1280 next = op->below;
1282 if (next)
1283 next_tag = next->count;
1284 1281
1285 /* loop while there are items on the floor that are not marked as 1282 /* loop while there are items on the floor that are not marked as
1286 * destroyed */ 1283 * destroyed */
1287 while (next && !was_destroyed (next, next_tag)) 1284 while (next && !next->destroyed ())
1288 { 1285 {
1289 tmp = next; 1286 tmp = next;
1290 next = tmp->below; 1287 next = tmp->below;
1291 if (next)
1292 next_tag = next->count;
1293 1288
1294 if (was_destroyed (op, op_tag)) 1289 if (op->destroyed ())
1295 return 0; 1290 return 0;
1296 1291
1297 if (!can_pick (op, tmp)) 1292 if (!can_pick (op, tmp))
1298 continue; 1293 continue;
1299 1294
1770 1765
1771object * 1766object *
1772pick_arrow_target (object *op, const char *type, int dir) 1767pick_arrow_target (object *op, const char *type, int dir)
1773{ 1768{
1774 object *tmp = NULL; 1769 object *tmp = NULL;
1775 mapstruct *m; 1770 maptile *m;
1776 int i, mflags, found, number; 1771 int i, mflags, found, number;
1777 sint16 x, y; 1772 sint16 x, y;
1778 1773
1779 if (op->map == NULL) 1774 if (op->map == NULL)
1780 return find_arrow (op, type); 1775 return find_arrow (op, type);
1840 */ 1835 */
1841int 1836int
1842fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy) 1837fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy)
1843{ 1838{
1844 object *left, *bow; 1839 object *left, *bow;
1845 tag_t left_tag, tag;
1846 int bowspeed, mflags; 1840 int bowspeed, mflags;
1847 mapstruct *m; 1841 maptile *m;
1848 1842
1849 if (!dir) 1843 if (!dir)
1850 { 1844 {
1851 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); 1845 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!");
1852 return 0; 1846 return 0;
1912 free_object (arrow); 1906 free_object (arrow);
1913 return 0; 1907 return 0;
1914 } 1908 }
1915 1909
1916 left = arrow; /* these are arrows left to the player */ 1910 left = arrow; /* these are arrows left to the player */
1917 left_tag = left->count;
1918 arrow = get_split_ob (arrow, 1); 1911 arrow = get_split_ob (arrow, 1);
1919 if (arrow == NULL) 1912 if (arrow == NULL)
1920 { 1913 {
1921 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1914 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1922 return 0; 1915 return 0;
1965 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level; 1958 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
1966 } 1959 }
1967 else 1960 else
1968 { 1961 {
1969 arrow->stats.wc = op->stats.wc - bow->magic - arrow->magic - arrow->stats.wc + wc_mod; 1962 arrow->stats.wc = op->stats.wc - bow->magic - arrow->magic - arrow->stats.wc + wc_mod;
1970
1971 arrow->level = op->level; 1963 arrow->level = op->level;
1972 } 1964 }
1965
1973 if (arrow->attacktype == AT_PHYSICAL) 1966 if (arrow->attacktype == AT_PHYSICAL)
1974 arrow->attacktype |= bow->attacktype; 1967 arrow->attacktype |= bow->attacktype;
1968
1975 if (bow->slaying != NULL) 1969 if (bow->slaying != NULL)
1976 arrow->slaying = bow->slaying; 1970 arrow->slaying = bow->slaying;
1977 1971
1978 arrow->map = m; 1972 arrow->map = m;
1979 arrow->move_type = MOVE_FLY_LOW; 1973 arrow->move_type = MOVE_FLY_LOW;
1980 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1974 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1981 1975
1982 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1976 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW);
1983 tag = arrow->count;
1984 insert_ob_in_map (arrow, m, op, 0); 1977 insert_ob_in_map (arrow, m, op, 0);
1985 1978
1986 if (!was_destroyed (arrow, tag)) 1979 if (!arrow->destroyed ())
1987 move_arrow (arrow); 1980 move_arrow (arrow);
1988 1981
1989 if (op->type == PLAYER) 1982 if (op->type == PLAYER)
1990 { 1983 {
1991 if (was_destroyed (left, left_tag)) 1984 if (left->destroyed ())
1992 esrv_del_item (op->contr, left_tag); 1985 esrv_del_item (op->contr, left->count);
1993 else 1986 else
1994 esrv_send_item (op, left); 1987 esrv_send_item (op, left);
1995 } 1988 }
1989
1996 return 1; 1990 return 1;
1997} 1991}
1998 1992
1999/* Special fire code for players - this takes into 1993/* Special fire code for players - this takes into
2000 * account the special fire modes players can have 1994 * account the special fire modes players can have
2312move_player_attack (object *op, int dir) 2306move_player_attack (object *op, int dir)
2313{ 2307{
2314 object *tmp, *mon; 2308 object *tmp, *mon;
2315 sint16 nx, ny; 2309 sint16 nx, ny;
2316 int on_battleground; 2310 int on_battleground;
2317 mapstruct *m; 2311 maptile *m;
2318 2312
2319 nx = freearr_x[dir] + op->x; 2313 nx = freearr_x[dir] + op->x;
2320 ny = freearr_y[dir] + op->y; 2314 ny = freearr_y[dir] + op->y;
2321 2315
2322 on_battleground = op_on_battleground (op, NULL, NULL); 2316 on_battleground = op_on_battleground (op, NULL, NULL);
2358 if (tmp == op) 2352 if (tmp == op)
2359 { 2353 {
2360 tmp = tmp->above; 2354 tmp = tmp->above;
2361 continue; 2355 continue;
2362 } 2356 }
2357
2363 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 2358 if (QUERY_FLAG (tmp, FLAG_ALIVE))
2364 { 2359 {
2365 mon = tmp; 2360 mon = tmp;
2366 break; 2361 break;
2367 } 2362 }
2363
2368 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL)) 2364 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL))
2369 mon = tmp; 2365 mon = tmp;
2366
2370 tmp = tmp->above; 2367 tmp = tmp->above;
2371 } 2368 }
2372 2369
2373 if (mon == NULL) /* This happens anytime the player tries to move */ 2370 if (mon == NULL) /* This happens anytime the player tries to move */
2374 return; /* into a wall */ 2371 return; /* into a wall */
2952{ 2949{
2953 char buf[MAX_BUF]; 2950 char buf[MAX_BUF];
2954 int x, y; 2951 int x, y;
2955 2952
2956 //int i; 2953 //int i;
2957 mapstruct *map; /* this is for resurrection */ 2954 maptile *map; /* this is for resurrection */
2958 2955
2959 /* int z; 2956 /* int z;
2960 int num_stats_lose; 2957 int num_stats_lose;
2961 int lost_a_stat; 2958 int lost_a_stat;
2962 int lose_this_stat; 2959 int lose_this_stat;
2977 { 2974 {
2978 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); 2975 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!");
2979 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life..."); 2976 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life...");
2980 2977
2981 /* restore player */ 2978 /* restore player */
2982 at = find_archetype ("poisoning"); 2979 at = archetype::find ("poisoning");
2983 tmp = present_arch_in_ob (at, op); 2980 tmp = present_arch_in_ob (at, op);
2984 if (tmp) 2981 if (tmp)
2985 { 2982 {
2986 remove_ob (tmp); 2983 remove_ob (tmp);
2987 free_object (tmp); 2984 free_object (tmp);
2988 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2985 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2989 } 2986 }
2990 2987
2991 at = find_archetype ("confusion"); 2988 at = archetype::find ("confusion");
2992 tmp = present_arch_in_ob (at, op); 2989 tmp = present_arch_in_ob (at, op);
2993 if (tmp) 2990 if (tmp)
2994 { 2991 {
2995 remove_ob (tmp); 2992 remove_ob (tmp);
2996 free_object (tmp); 2993 free_object (tmp);
3001 op->stats.hp = op->stats.maxhp; 2998 op->stats.hp = op->stats.maxhp;
3002 if (op->stats.food <= 0) 2999 if (op->stats.food <= 0)
3003 op->stats.food = 999; 3000 op->stats.food = 999;
3004 3001
3005 /* create a bodypart-trophy to make the winner happy */ 3002 /* create a bodypart-trophy to make the winner happy */
3006 tmp = arch_to_object (find_archetype ("finger")); 3003 tmp = arch_to_object (archetype::find ("finger"));
3007 if (tmp != NULL) 3004 if (tmp != NULL)
3008 { 3005 {
3009 sprintf (buf, "%s's finger", &op->name); 3006 sprintf (buf, "%s's finger", &op->name);
3010 tmp->name = buf; 3007 tmp->name = buf;
3011 sprintf (buf, " This finger has been cut off %s\n" 3008 sprintf (buf, " This finger has been cut off %s\n"
3108 lost_a_stat = 1; 3105 lost_a_stat = 1;
3109 } 3106 }
3110 else 3107 else
3111 { 3108 {
3112 /* deplete a stat */ 3109 /* deplete a stat */
3113 archetype *deparch = find_archetype ("depletion"); 3110 archetype *deparch = archetype::find ("depletion");
3114 object *dep; 3111 object *dep;
3115 3112
3116 dep = present_arch_in_ob (deparch, op); 3113 dep = present_arch_in_ob (deparch, op);
3117 if (!dep) 3114 if (!dep)
3118 { 3115 {
3188 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely."); 3185 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3189 3186
3190 /* Put a gravestone up where the character 'almost' died. List the 3187 /* Put a gravestone up where the character 'almost' died. List the
3191 * exp loss on the stone. 3188 * exp loss on the stone.
3192 */ 3189 */
3193 tmp = arch_to_object (find_archetype ("gravestone")); 3190 tmp = arch_to_object (archetype::find ("gravestone"));
3194 sprintf (buf, "%s's gravestone", &op->name); 3191 sprintf (buf, "%s's gravestone", &op->name);
3195 tmp->name = buf; 3192 tmp->name = buf;
3196 sprintf (buf, "%s's gravestones", &op->name); 3193 sprintf (buf, "%s's gravestones", &op->name);
3197 tmp->name_pl = buf; 3194 tmp->name_pl = buf;
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); 3195 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);
3209 3206
3210 /**************************************/ 3207 /**************************************/
3211 3208
3212 /* remove any poisoning and confusion the character may be suffering. */ 3209 /* remove any poisoning and confusion the character may be suffering. */
3213 /* restore player */ 3210 /* restore player */
3214 at = find_archetype ("poisoning"); 3211 at = archetype::find ("poisoning");
3215 tmp = present_arch_in_ob (at, op); 3212 tmp = present_arch_in_ob (at, op);
3216 if (tmp) 3213 if (tmp)
3217 { 3214 {
3218 remove_ob (tmp); 3215 remove_ob (tmp);
3219 free_object (tmp); 3216 free_object (tmp);
3220 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 3217 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3221 } 3218 }
3222 3219
3223 at = find_archetype ("confusion"); 3220 at = archetype::find ("confusion");
3224 tmp = present_arch_in_ob (at, op); 3221 tmp = present_arch_in_ob (at, op);
3225 if (tmp) 3222 if (tmp)
3226 { 3223 {
3227 remove_ob (tmp); 3224 remove_ob (tmp);
3228 free_object (tmp); 3225 free_object (tmp);
3350 } 3347 }
3351 3348
3352 play_again (op); 3349 play_again (op);
3353 3350
3354 /* peterm: added to create a corpse at deathsite. */ 3351 /* peterm: added to create a corpse at deathsite. */
3355 tmp = arch_to_object (find_archetype ("corpse_pl")); 3352 tmp = arch_to_object (archetype::find ("corpse_pl"));
3356 sprintf (buf, "%s", &op->name); 3353 sprintf (buf, "%s", &op->name);
3357 tmp->name = tmp->name_pl = buf; 3354 tmp->name = tmp->name_pl = buf;
3358 tmp->level = op->level; 3355 tmp->level = op->level;
3359 tmp->x = x; 3356 tmp->x = x;
3360 tmp->y = y; 3357 tmp->y = y;
3596int 3593int
3597stand_near_hostile (object *who) 3594stand_near_hostile (object *who)
3598{ 3595{
3599 object *tmp = NULL; 3596 object *tmp = NULL;
3600 int i, friendly = 0, player = 0, mflags; 3597 int i, friendly = 0, player = 0, mflags;
3601 mapstruct *m; 3598 maptile *m;
3602 sint16 x, y; 3599 sint16 x, y;
3603 3600
3604 if (!who) 3601 if (!who)
3605 return 0; 3602 return 0;
3606 3603

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines