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.31 by pippijn, Mon Dec 11 19:46:47 2006 UTC vs.
Revision 1.37 by root, Thu Dec 14 02:37:37 2006 UTC

320 * All we can really get in this is some settings like host and display 320 * All we can really get in this is some settings like host and display
321 * mode. 321 * mode.
322 */ 322 */
323 323
324int 324int
325add_player (NewSocket * ns) 325add_player (client_socket * ns)
326{ 326{
327 player *p; 327 player *p;
328 328
329 p = get_player (NULL); 329 p = get_player (NULL);
330 p->socket = *ns; 330 p->socket = *ns;
336 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 336 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent));
337 /* Needed because the socket we just copied over needs to be cleared. 337 /* Needed because the socket we just copied over needs to be cleared.
338 * Note that this can result in a client reset if there is partial data 338 * Note that this can result in a client reset if there is partial data
339 * on the uncoming socket. 339 * on the uncoming socket.
340 */ 340 */
341 //TODO socket copying is EVIL, do not do this
341 p->socket.inbuf.len = 0; 342 p->socket.inbuf_len = 0;
342 set_first_map (p->ob); 343 set_first_map (p->ob);
343 344
344 CLEAR_FLAG (p->ob, FLAG_FRIENDLY); 345 CLEAR_FLAG (p->ob, FLAG_FRIENDLY);
345 add_friendly_object (p->ob); 346 add_friendly_object (p->ob);
346 send_rules (p->ob); 347 send_rules (p->ob);
644 (op->type == ARMOUR || op->type == BOOTS || 645 (op->type == ARMOUR || op->type == BOOTS ||
645 op->type == CLOAK || op->type == HELMET || 646 op->type == CLOAK || op->type == HELMET ||
646 op->type == SHIELD || op->type == GLOVES || 647 op->type == SHIELD || op->type == GLOVES ||
647 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 648 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON))
648 { 649 {
649 remove_ob (op); 650 op->destroy ();
650 free_object (op);
651 continue; 651 continue;
652 } 652 }
653 } 653 }
654 654
655 /* This really needs to be better - we should really give 655 /* This really needs to be better - we should really give
666 if (tmp->type == op->type && tmp->name == op->name) 666 if (tmp->type == op->type && tmp->name == op->name)
667 break; 667 break;
668 668
669 if (tmp) 669 if (tmp)
670 { 670 {
671 remove_ob (op); 671 op->destroy ();
672 free_object (op);
673 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); 672 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name);
674 continue; 673 continue;
675 } 674 }
675
676 if (op->nrof > 1) 676 if (op->nrof > 1)
677 op->nrof = 1; 677 op->nrof = 1;
678 } 678 }
679 679
680 if (op->type == SPELLBOOK && op->inv) 680 if (op->type == SPELLBOOK && op->inv)
692 CLEAR_FLAG (op, FLAG_CURSED); 692 CLEAR_FLAG (op, FLAG_CURSED);
693 CLEAR_FLAG (op, FLAG_DAMNED); 693 CLEAR_FLAG (op, FLAG_DAMNED);
694 } 694 }
695 if (op->type == SPELL) 695 if (op->type == SPELL)
696 { 696 {
697 remove_ob (op); 697 op->destroy ();
698 free_object (op);
699 continue; 698 continue;
700 } 699 }
701 else if (op->type == SKILL) 700 else if (op->type == SKILL)
702 { 701 {
703 SET_FLAG (op, FLAG_CAN_USE_SKILL); 702 SET_FLAG (op, FLAG_CAN_USE_SKILL);
742 * removing the player - it probably makes more sense 741 * removing the player - it probably makes more sense
743 * to leave it to play_again to remove the object in all 742 * to leave it to play_again to remove the object in all
744 * cases. 743 * cases.
745 */ 744 */
746 if (!QUERY_FLAG (op, FLAG_REMOVED)) 745 if (!QUERY_FLAG (op, FLAG_REMOVED))
747 remove_ob (op); 746 op->remove ();
748 /* Need to set this to null - otherwise, it could point to garbage, 747 /* Need to set this to null - otherwise, it could point to garbage,
749 * and draw() doesn't check to see if the player is removed, only if 748 * and draw() doesn't check to see if the player is removed, only if
750 * the map is null or not swapped out. 749 * the map is null or not swapped out.
751 */ 750 */
752 op->map = NULL; 751 op->map = NULL;
1052{ 1051{
1053 int tmp_loop; 1052 int tmp_loop;
1054 1053
1055 if (key == 'q' || key == 'Q') 1054 if (key == 'q' || key == 'Q')
1056 { 1055 {
1057 remove_ob (op); 1056 op->remove ();
1058 play_again (op); 1057 play_again (op);
1059 return 0; 1058 return 0;
1060 } 1059 }
1061 if (key == 'd' || key == 'D') 1060 if (key == 'd' || key == 'D')
1062 { 1061 {
1063 char buf[MAX_BUF]; 1062 char buf[MAX_BUF];
1064 1063
1065 /* this must before then initial items are given */ 1064 /* this must before then initial items are given */
1066 esrv_new_player (op->contr, op->weight + op->carrying); 1065 esrv_new_player (op->contr, op->weight + op->carrying);
1066
1067 create_treasure (find_treasurelist ("starting_wealth"), op, 0, 0, 0); 1067 treasurelist *tl = find_treasurelist ("starting_wealth");
1068 if (tl)
1069 create_treasure (tl, op, 0, 0, 0);
1068 1070
1069 INVOKE_PLAYER (BIRTH, op->contr); 1071 INVOKE_PLAYER (BIRTH, op->contr);
1070 INVOKE_PLAYER (LOGIN, op->contr); 1072 INVOKE_PLAYER (LOGIN, op->contr);
1071 1073
1072 op->contr->state = ST_PLAYING; 1074 op->contr->state = ST_PLAYING;
1097 { 1099 {
1098 object *tmp; 1100 object *tmp;
1099 char mapname[MAX_BUF]; 1101 char mapname[MAX_BUF];
1100 1102
1101 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); 1103 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name);
1102 tmp = get_object (); 1104 tmp = object::create ();
1103 EXIT_PATH (tmp) = mapname; 1105 EXIT_PATH (tmp) = mapname;
1104 EXIT_X (tmp) = op->x; 1106 EXIT_X (tmp) = op->x;
1105 EXIT_Y (tmp) = op->y; 1107 EXIT_Y (tmp) = op->y;
1106 enter_exit (op, tmp); /* we don't really care if it succeeded; 1108 enter_exit (op, tmp); /* we don't really care if it succeeded;
1107 * if the map isn't there, then stay on the 1109 * if the map isn't there, then stay on the
1108 * default initial map */ 1110 * default initial map */
1109 free_object (tmp); 1111 tmp->destroy ();
1110 } 1112 }
1111 else 1113 else
1112 { 1114 {
1113 LOG (llevDebug, "first_map_ext_path not set\n"); 1115 LOG (llevDebug, "first_map_ext_path not set\n");
1114 } 1116 }
1124 { 1126 {
1125 shstr name = op->name; 1127 shstr name = op->name;
1126 int x = op->x, y = op->y; 1128 int x = op->x, y = op->y;
1127 1129
1128 remove_statbonus (op); 1130 remove_statbonus (op);
1129 remove_ob (op); 1131 op->remove ();
1130 op->arch = get_player_archetype (op->arch); 1132 op->arch = get_player_archetype (op->arch);
1131 copy_object (&op->arch->clone, op); 1133 op->arch->clone.copy_to (op);
1132 op->instantiate (); 1134 op->instantiate ();
1133 op->stats = op->contr->orig_stats; 1135 op->stats = op->contr->orig_stats;
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;
1873 } 1875 }
1874 1876
1875 /* this should not happen, but sometimes does */ 1877 /* this should not happen, but sometimes does */
1876 if (arrow->nrof == 0) 1878 if (arrow->nrof == 0)
1877 { 1879 {
1878 remove_ob (arrow); 1880 arrow->destroy ();
1879 free_object (arrow);
1880 return 0; 1881 return 0;
1881 } 1882 }
1882 1883
1883 left = arrow; /* these are arrows left to the player */ 1884 left = arrow; /* these are arrows left to the player */
1884 arrow = get_split_ob (arrow, 1); 1885 arrow = get_split_ob (arrow, 1);
1885 if (arrow == NULL) 1886 if (arrow == NULL)
1886 { 1887 {
1887 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1888 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1888 return 0; 1889 return 0;
1889 } 1890 }
1890 set_owner (arrow, op); 1891 arrow->set_owner (op);
1891 arrow->skill = bow->skill; 1892 arrow->skill = bow->skill;
1892 1893
1893 arrow->direction = dir; 1894 arrow->direction = dir;
1894 arrow->x = sx; 1895 arrow->x = sx;
1895 arrow->y = sy; 1896 arrow->y = sy;
2362 * player owns it and it is either friendly or unagressive. 2363 * player owns it and it is either friendly or unagressive.
2363 */ 2364 */
2364 if ((op->type == PLAYER) 2365 if ((op->type == PLAYER)
2365#if COZY_SERVER 2366#if COZY_SERVER
2366 && 2367 &&
2367 ((get_owner (mon) && get_owner (mon)->contr 2368 ((mon->owner && mon->owner->contr
2368 && same_party (get_owner (mon)->contr->party, op->contr->party)) || get_owner (mon) == op) 2369 && same_party (mon->owner->contr->party, op->contr->party)) || mon->owner == op)
2369#else 2370#else
2370 && get_owner (mon) == op 2371 && mon->owner == op
2371#endif 2372#endif
2372 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2373 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2373 { 2374 {
2374 /* If we're braced, we don't want to switch places with it */ 2375 /* If we're braced, we don't want to switch places with it */
2375 if (op->contr->braced) 2376 if (op->contr->braced)
2604 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2605 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
2605 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2606 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2606 { 2607 {
2607 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2608 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE);
2608 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2609 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2610
2609 if (op->contr) 2611 if (op->contr)
2610 esrv_del_item (op->contr, tmp->count); 2612 esrv_del_item (op->contr, tmp->count);
2611 remove_ob (tmp); 2613
2612 free_object (tmp); 2614 tmp->destroy ();
2613 CLEAR_FLAG (op, FLAG_LIFESAVE); 2615 CLEAR_FLAG (op, FLAG_LIFESAVE);
2616
2614 if (op->stats.hp < 0) 2617 if (op->stats.hp < 0)
2615 op->stats.hp = op->stats.maxhp; 2618 op->stats.hp = op->stats.maxhp;
2619
2616 if (op->stats.food < 0) 2620 if (op->stats.food < 0)
2617 op->stats.food = 999; 2621 op->stats.food = 999;
2622
2618 fix_player (op); 2623 fix_player (op);
2619 return 1; 2624 return 1;
2620 } 2625 }
2621 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2626 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2622 CLEAR_FLAG (op, FLAG_LIFESAVE); 2627 CLEAR_FLAG (op, FLAG_LIFESAVE);
2639 next = op->below; /* Make sure we have a good value, in case 2644 next = op->below; /* Make sure we have a good value, in case
2640 * we remove object 'op' 2645 * we remove object 'op'
2641 */ 2646 */
2642 if (QUERY_FLAG (op, FLAG_UNPAID)) 2647 if (QUERY_FLAG (op, FLAG_UNPAID))
2643 { 2648 {
2644 remove_ob (op); 2649 op->remove ();
2645 op->x = env->x; 2650 op->x = env->x;
2646 op->y = env->y; 2651 op->y = env->y;
2647 if (env->type == PLAYER) 2652 if (env->type == PLAYER)
2648 esrv_del_item (env->contr, op->count); 2653 esrv_del_item (env->contr, op->count);
2649 insert_ob_in_map (op, env->map, NULL, 0); 2654 insert_ob_in_map (op, env->map, NULL, 0);
2946 /* restore player */ 2951 /* restore player */
2947 at = archetype::find ("poisoning"); 2952 at = archetype::find ("poisoning");
2948 tmp = present_arch_in_ob (at, op); 2953 tmp = present_arch_in_ob (at, op);
2949 if (tmp) 2954 if (tmp)
2950 { 2955 {
2951 remove_ob (tmp); 2956 tmp->destroy ();
2952 free_object (tmp);
2953 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2957 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2954 } 2958 }
2955 2959
2956 at = archetype::find ("confusion"); 2960 at = archetype::find ("confusion");
2957 tmp = present_arch_in_ob (at, op); 2961 tmp = present_arch_in_ob (at, op);
2958 if (tmp) 2962 if (tmp)
2959 { 2963 {
2960 remove_ob (tmp); 2964 tmp->destroy ();
2961 free_object (tmp);
2962 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2965 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2963 } 2966 }
2964 2967
2965 cure_disease (op, 0); /* remove any disease */ 2968 cure_disease (op, 0); /* remove any disease */
2966 op->stats.hp = op->stats.maxhp; 2969 op->stats.hp = op->stats.maxhp;
3176 3179
3177 /* remove any poisoning and confusion the character may be suffering. */ 3180 /* remove any poisoning and confusion the character may be suffering. */
3178 /* restore player */ 3181 /* restore player */
3179 at = archetype::find ("poisoning"); 3182 at = archetype::find ("poisoning");
3180 tmp = present_arch_in_ob (at, op); 3183 tmp = present_arch_in_ob (at, op);
3184
3181 if (tmp) 3185 if (tmp)
3182 { 3186 {
3183 remove_ob (tmp); 3187 tmp->destroy ();
3184 free_object (tmp);
3185 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 3188 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3186 } 3189 }
3187 3190
3188 at = archetype::find ("confusion"); 3191 at = archetype::find ("confusion");
3189 tmp = present_arch_in_ob (at, op); 3192 tmp = present_arch_in_ob (at, op);
3190 if (tmp) 3193 if (tmp)
3191 { 3194 {
3192 remove_ob (tmp); 3195 tmp->destroy ();
3193 free_object (tmp);
3194 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 3196 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3195 } 3197 }
3196 3198
3197 cure_disease (op, 0); /* remove any disease */ 3199 cure_disease (op, 0); /* remove any disease */
3198 3200
3273 check_score (op); 3275 check_score (op);
3274 3276
3275 if (op->contr->ranges[range_golem]) 3277 if (op->contr->ranges[range_golem])
3276 { 3278 {
3277 remove_friendly_object (op->contr->ranges[range_golem]); 3279 remove_friendly_object (op->contr->ranges[range_golem]);
3278 remove_ob (op->contr->ranges[range_golem]); 3280 op->contr->ranges[range_golem]->destroy ();
3279 free_object (op->contr->ranges[range_golem]);
3280 op->contr->ranges[range_golem] = 0; 3281 op->contr->ranges[range_golem] = 0;
3281 } 3282 }
3282 3283
3283 loot_object (op); /* Remove some of the items for good */ 3284 loot_object (op); /* Remove some of the items for good */
3284 remove_ob (op); 3285 op->remove ();
3285 op->direction = 0; 3286 op->direction = 0;
3286 3287
3287 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp) 3288 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp)
3288 { 3289 {
3289 delete_character (op->name, 0); 3290 delete_character (op->name, 0);
3342 for (tmp = op->inv; tmp != NULL; tmp = next) 3343 for (tmp = op->inv; tmp != NULL; tmp = next)
3343 { 3344 {
3344 next = tmp->below; 3345 next = tmp->below;
3345 if (tmp->type == EXPERIENCE || tmp->invisible) 3346 if (tmp->type == EXPERIENCE || tmp->invisible)
3346 continue; 3347 continue;
3347 remove_ob (tmp); 3348 tmp->remove ();
3348 tmp->x = op->x, tmp->y = op->y; 3349 tmp->x = op->x, tmp->y = op->y;
3349 if (tmp->type == CONTAINER) 3350 if (tmp->type == CONTAINER)
3350 { /* empty container to ground */ 3351 { /* empty container to ground */
3351 loot_object (tmp); 3352 loot_object (tmp);
3352 } 3353 }
3353 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) 3354 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3)))
3354 { 3355 {
3355 if (tmp->nrof > 1) 3356 if (tmp->nrof > 1)
3356 { 3357 {
3357 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 3358 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1));
3358 free_object (tmp2); 3359 tmp2->destroy ();
3359 insert_ob_in_map (tmp, op->map, NULL, 0); 3360 insert_ob_in_map (tmp, op->map, NULL, 0);
3360 } 3361 }
3361 else 3362 else
3362 free_object (tmp); 3363 tmp->destroy ();
3363 } 3364 }
3364 else 3365 else
3365 insert_ob_in_map (tmp, op->map, NULL, 0); 3366 insert_ob_in_map (tmp, op->map, NULL, 0);
3366 } 3367 }
3367} 3368}
3432 if (op->type == PLAYER) 3433 if (op->type == PLAYER)
3433 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); 3434 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name);
3434 3435
3435 cast_spell (op, throw_ob, dir, spob, NULL); 3436 cast_spell (op, throw_ob, dir, spob, NULL);
3436 3437
3437 if (!QUERY_FLAG (throw_ob, FLAG_REMOVED)) 3438 throw_ob->destroy ();
3438 remove_ob (throw_ob);
3439 free_object (throw_ob);
3440} 3439}
3441 3440
3442void 3441void
3443make_visible (object *op) 3442make_visible (object *op)
3444{ 3443{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines