… | |
… | |
194 | return; |
194 | return; |
195 | |
195 | |
196 | terminate_all_pets (ob); |
196 | terminate_all_pets (ob); |
197 | remove_friendly_object (ob); |
197 | remove_friendly_object (ob); |
198 | ob->deactivate_recursive (); |
198 | ob->deactivate_recursive (); |
|
|
199 | maplevel = ob->map->path; |
199 | ob->remove (); |
200 | ob->remove (); |
200 | ob->map = 0; |
201 | ob->map = 0; |
201 | |
202 | |
202 | // for weird reasons, this is often "ob", keeping a circular reference |
203 | // for weird reasons, this is often "ob", keeping a circular reference |
203 | ranges [range_skill] = 0; |
204 | ranges [range_skill] = 0; |
… | |
… | |
211 | player::connect (client *ns) |
212 | player::connect (client *ns) |
212 | { |
213 | { |
213 | this->ns = ns; |
214 | this->ns = ns; |
214 | ns->pl = this; |
215 | ns->pl = this; |
215 | |
216 | |
|
|
217 | run_on = 0; |
|
|
218 | fire_on = 0; |
|
|
219 | ob->container = 0; //TODO: client-specific |
|
|
220 | |
216 | ns->update_look = 0; |
221 | ns->update_look = 0; |
217 | ns->look_position = 0; |
222 | ns->look_position = 0; |
218 | |
223 | |
219 | clear_los (ob); |
224 | clear_los (ob); |
220 | |
225 | |
221 | //TODO: must move into client |
226 | ns->reset_stats (); |
222 | /* we need to clear these to -1 and not zero - otherwise, |
|
|
223 | * if a player quits and starts a new character, we wont |
|
|
224 | * send new values to the client, as things like exp start |
|
|
225 | * at zero. |
|
|
226 | */ |
|
|
227 | for (int i = 0; i < NUM_SKILLS; i++) |
|
|
228 | last_skill_exp[i] = -1; |
|
|
229 | |
|
|
230 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
231 | last_resist[i] = -1; |
|
|
232 | |
|
|
233 | last_weapon_sp = -1; |
|
|
234 | last_level = -1; |
|
|
235 | last_stats.exp = -1; |
|
|
236 | last_weight = (uint32) - 1; |
|
|
237 | last_flags = 0; |
|
|
238 | last_weight = 0; |
|
|
239 | last_weight_limit = 0; |
|
|
240 | last_path_attuned = 0; |
|
|
241 | last_path_repelled = 0; |
|
|
242 | last_path_denied = 0; |
|
|
243 | last_speed = 0; |
|
|
244 | run_on = 0; |
|
|
245 | fire_on = 0; |
|
|
246 | memset (&last_stats, 0, sizeof (living)); //TODO dirty |
|
|
247 | |
227 | |
248 | /* make sure he's a player -- needed because of class change. */ |
228 | /* make sure he's a player -- needed because of class change. */ |
249 | ob->type = PLAYER; // we are paranoid |
229 | ob->type = PLAYER; // we are paranoid |
250 | ob->race = ob->arch->clone.race; |
230 | ob->race = ob->arch->clone.race; |
251 | |
231 | |
… | |
… | |
315 | if (active) |
295 | if (active) |
316 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
296 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
317 | |
297 | |
318 | INVOKE_PLAYER (DISCONNECT, this); |
298 | INVOKE_PLAYER (DISCONNECT, this); |
319 | |
299 | |
|
|
300 | ns->reset_stats (); |
320 | ns->pl = 0; |
301 | ns->pl = 0; |
321 | this->ns = 0; |
302 | this->ns = 0; |
322 | } |
303 | } |
323 | |
304 | |
|
|
305 | ob->container = 0; //TODO: client-specific |
324 | deactivate (); |
306 | deactivate (); |
325 | } |
307 | } |
326 | |
308 | |
327 | // the need for this function can be explained |
309 | // the need for this function can be explained |
328 | // by load_object not returning the object |
310 | // by load_object not returning the object |
… | |
… | |
545 | x = mon->x; |
527 | x = mon->x; |
546 | y = mon->y; |
528 | y = mon->y; |
547 | m = mon->map; |
529 | m = mon->map; |
548 | dir = rv.direction; |
530 | dir = rv.direction; |
549 | lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */ |
531 | lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */ |
550 | diff = FABS (rv.distance_x) > FABS (rv.distance_y) ? FABS (rv.distance_x) : FABS (rv.distance_y); |
532 | diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); |
|
|
533 | |
551 | /* If we can't solve it within the search distance, return now. */ |
534 | /* If we can't solve it within the search distance, return now. */ |
552 | if (diff > max) |
535 | if (diff > max) |
553 | return 0; |
536 | return 0; |
|
|
537 | |
554 | while (diff > 1 && max > 0) |
538 | while (diff > 1 && max > 0) |
555 | { |
539 | { |
556 | lastx = x; |
540 | lastx = x; |
557 | lasty = y; |
541 | lasty = y; |
558 | lastmap = m; |
542 | lastmap = m; |
… | |
… | |
640 | max--; |
624 | max--; |
641 | lastdir = dir; |
625 | lastdir = dir; |
642 | if (!firstdir) |
626 | if (!firstdir) |
643 | firstdir = dir; |
627 | firstdir = dir; |
644 | } |
628 | } |
|
|
629 | |
645 | if (diff <= 1) |
630 | if (diff <= 1) |
646 | { |
631 | { |
647 | /* Recalculate diff (distance) because we may not have actually |
632 | /* Recalculate diff (distance) because we may not have actually |
648 | * headed toward player for entire distance. |
633 | * headed toward player for entire distance. |
649 | */ |
634 | */ |
650 | get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0); |
635 | get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0); |
651 | diff = FABS (rv.distance_x) > FABS (rv.distance_y) ? FABS (rv.distance_x) : FABS (rv.distance_y); |
636 | diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); |
652 | } |
637 | } |
|
|
638 | |
653 | if (diff > max) |
639 | if (diff > max) |
654 | return 0; |
640 | return 0; |
655 | } |
641 | } |
|
|
642 | |
656 | /* If we reached the max, didn't find a direction in time */ |
643 | /* If we reached the max, didn't find a direction in time */ |
657 | if (!max) |
644 | if (!max) |
658 | return 0; |
645 | return 0; |
659 | |
646 | |
660 | return firstdir; |
647 | return firstdir; |
… | |
… | |
774 | roll_stat (void) |
761 | roll_stat (void) |
775 | { |
762 | { |
776 | int a[4], i, j, k; |
763 | int a[4], i, j, k; |
777 | |
764 | |
778 | for (i = 0; i < 4; i++) |
765 | for (i = 0; i < 4; i++) |
779 | a[i] = (int) RANDOM () % 6 + 1; |
766 | a[i] = (int) rndm (6) + 1; |
780 | |
767 | |
781 | for (i = 0, j = 0, k = 7; i < 4; i++) |
768 | for (i = 0, j = 0, k = 7; i < 4; i++) |
782 | if (a[i] < k) |
769 | if (a[i] < k) |
783 | k = a[i], j = i; |
770 | k = a[i], j = i; |
784 | |
771 | |
… | |
… | |
914 | * to save here. |
901 | * to save here. |
915 | */ |
902 | */ |
916 | sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &op->name); |
903 | sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &op->name); |
917 | make_path_to_file (buf); |
904 | make_path_to_file (buf); |
918 | |
905 | |
919 | #ifdef AUTOSAVE |
|
|
920 | op->contr->last_save_tick = pticks; |
|
|
921 | #endif |
|
|
922 | start_info (op); |
906 | start_info (op); |
923 | CLEAR_FLAG (op, FLAG_WIZ); |
907 | CLEAR_FLAG (op, FLAG_WIZ); |
924 | give_initial_items (op, op->randomitems); |
908 | give_initial_items (op, op->randomitems); |
925 | link_player_skills (op); |
909 | link_player_skills (op); |
926 | esrv_send_inventory (op, op); |
910 | esrv_send_inventory (op, op); |
… | |
… | |
2232 | return 0; |
2216 | return 0; |
2233 | } |
2217 | } |
2234 | |
2218 | |
2235 | /* peterm: added following line */ |
2219 | /* peterm: added following line */ |
2236 | if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) |
2220 | if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) |
2237 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
2221 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
2238 | |
2222 | |
2239 | op->facing = dir; |
2223 | op->facing = dir; |
2240 | |
2224 | |
2241 | if (op->hide) |
2225 | if (op->hide) |
2242 | do_hidden_move (op); |
2226 | do_hidden_move (op); |
… | |
… | |
3003 | tmp->x = op->x, tmp->y = op->y; |
2987 | tmp->x = op->x, tmp->y = op->y; |
3004 | if (tmp->type == CONTAINER) |
2988 | if (tmp->type == CONTAINER) |
3005 | { /* empty container to ground */ |
2989 | { /* empty container to ground */ |
3006 | loot_object (tmp); |
2990 | loot_object (tmp); |
3007 | } |
2991 | } |
3008 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) |
2992 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) |
3009 | { |
2993 | { |
3010 | if (tmp->nrof > 1) |
2994 | if (tmp->nrof > 1) |
3011 | { |
2995 | { |
3012 | tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); |
2996 | tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); |
3013 | tmp2->destroy (); |
2997 | tmp2->destroy (); |
… | |
… | |
3547 | * not readied. |
3531 | * not readied. |
3548 | */ |
3532 | */ |
3549 | void |
3533 | void |
3550 | player_unready_range_ob (player *pl, object *ob) |
3534 | player_unready_range_ob (player *pl, object *ob) |
3551 | { |
3535 | { |
3552 | rangetype i; |
|
|
3553 | |
|
|
3554 | for (i = (rangetype) 0; i < range_size; i = (rangetype) ((int) i + 1)) |
3536 | for (rangetype i = (rangetype) 0; i < range_size; i = (rangetype) ((int) i + 1)) |
3555 | { |
|
|
3556 | if (pl->ranges[i] == ob) |
3537 | if (pl->ranges[i] == ob) |
3557 | { |
3538 | { |
3558 | pl->ranges[i] = NULL; |
3539 | pl->ranges[i] = 0; |
3559 | if (pl->shoottype == i) |
3540 | if (pl->shoottype == i) |
3560 | { |
|
|
3561 | pl->shoottype = range_none; |
3541 | pl->shoottype = range_none; |
3562 | } |
|
|
3563 | } |
3542 | } |
3564 | } |
|
|
3565 | } |
3543 | } |