… | |
… | |
284 | } |
284 | } |
285 | |
285 | |
286 | void |
286 | void |
287 | player::disconnect () |
287 | player::disconnect () |
288 | { |
288 | { |
|
|
289 | if (ob) |
|
|
290 | { |
|
|
291 | ob->close_container (); //TODO: client-specific |
|
|
292 | ob->drop_unpaid_items (); |
|
|
293 | } |
|
|
294 | |
289 | if (ns) |
295 | if (ns) |
290 | { |
296 | { |
291 | if (active) |
297 | if (active) |
292 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
298 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
293 | |
299 | |
294 | INVOKE_PLAYER (DISCONNECT, this); |
300 | INVOKE_PLAYER (DISCONNECT, this); |
295 | |
301 | |
296 | ns->reset_stats (); |
302 | ns->reset_stats (); |
297 | ns->pl = 0; |
303 | ns->pl = 0; |
298 | ns = 0; |
304 | ns = 0; |
299 | } |
|
|
300 | |
|
|
301 | if (ob) |
|
|
302 | { |
|
|
303 | ob->close_container (); //TODO: client-specific |
|
|
304 | ob->drop_unpaid_items (); |
|
|
305 | } |
305 | } |
306 | |
306 | |
307 | observe = ob; |
307 | observe = ob; |
308 | |
308 | |
309 | deactivate (); |
309 | deactivate (); |
… | |
… | |
425 | unsigned lastdist; |
425 | unsigned lastdist; |
426 | rv_vector rv; |
426 | rv_vector rv; |
427 | |
427 | |
428 | for (ol = first_friendly_object, lastdist = 1000; ol; ol = ol->next) |
428 | for (ol = first_friendly_object, lastdist = 1000; ol; ol = ol->next) |
429 | { |
429 | { |
430 | /* We should not find free objects on this friendly list, but it |
|
|
431 | * does periodically happen. Given that, lets deal with it. |
|
|
432 | * While unlikely, it is possible the next object on the friendly |
|
|
433 | * list is also free, so encapsulate this in a while loop. |
|
|
434 | */ |
|
|
435 | while (QUERY_FLAG (ol->ob, FLAG_FREED) || !QUERY_FLAG (ol->ob, FLAG_FRIENDLY)) |
|
|
436 | { |
|
|
437 | object *tmp = ol->ob; |
|
|
438 | |
|
|
439 | /* Can't do much more other than log the fact, because the object |
|
|
440 | * itself will have been cleared. |
|
|
441 | */ |
|
|
442 | LOG (llevDebug, "get_nearest_player: Found free/non friendly object '%s' on friendly list\n", |
|
|
443 | tmp->debug_desc ()); |
|
|
444 | ol = ol->next; |
|
|
445 | remove_friendly_object (tmp); |
|
|
446 | if (!ol) |
|
|
447 | return op; |
|
|
448 | } |
|
|
449 | |
|
|
450 | /* Remove special check for player from this. First, it looks to cause |
|
|
451 | * some crashes (ol->ob->contr not set properly?), but secondly, a more |
|
|
452 | * complicated method of state checking would be needed in any case - |
|
|
453 | * as it was, a clever player could type quit, and the function would |
|
|
454 | * skip them over while waiting for confirmation. Remove |
|
|
455 | * on_same_map check, as can_detect_enemy also does this |
|
|
456 | */ |
|
|
457 | if (!can_detect_enemy (mon, ol->ob, &rv)) |
430 | if (!can_detect_enemy (mon, ol->ob, &rv)) |
458 | continue; |
431 | continue; |
459 | |
432 | |
460 | if (lastdist > rv.distance) |
433 | if (lastdist > rv.distance) |
461 | { |
434 | { |
… | |
… | |
2446 | { |
2419 | { |
2447 | gen_grace = op->stats.maxgrace; |
2420 | gen_grace = op->stats.maxgrace; |
2448 | rate_grace -= rate_grace / 2 * op->contr->gen_grace; |
2421 | rate_grace -= rate_grace / 2 * op->contr->gen_grace; |
2449 | } |
2422 | } |
2450 | |
2423 | |
2451 | /* Regenerate Spell Points */ |
|
|
2452 | if (!op->contr->golem && --op->last_sp < 0) |
|
|
2453 | { |
|
|
2454 | gen_sp = gen_sp * 10 / (op->contr->gen_sp_armour < 10 ? 10 : op->contr->gen_sp_armour); |
|
|
2455 | if (op->stats.sp < op->stats.maxsp) |
|
|
2456 | { |
|
|
2457 | op->stats.sp++; |
|
|
2458 | /* dms do not consume food */ |
|
|
2459 | if (!QUERY_FLAG (op, FLAG_WIZ)) |
|
|
2460 | { |
|
|
2461 | op->stats.food--; |
|
|
2462 | if (op->contr->digestion < 0) |
|
|
2463 | op->stats.food += op->contr->digestion; |
|
|
2464 | else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) |
|
|
2465 | op->stats.food = last_food; |
|
|
2466 | } |
|
|
2467 | } |
|
|
2468 | |
|
|
2469 | if (max_sp > 1) |
|
|
2470 | { |
|
|
2471 | over_sp = (gen_sp + 10) / rate_sp; |
|
|
2472 | if (over_sp > 0) |
|
|
2473 | { |
|
|
2474 | if (op->stats.sp < op->stats.maxsp) |
|
|
2475 | { |
|
|
2476 | op->stats.sp += over_sp > max_sp ? max_sp : over_sp; |
|
|
2477 | |
|
|
2478 | if (random_roll (0, rate_sp - 1, op, PREFER_LOW) > ((gen_sp + 10) % rate_sp)) |
|
|
2479 | op->stats.sp--; |
|
|
2480 | |
|
|
2481 | if (op->stats.sp > op->stats.maxsp) |
|
|
2482 | op->stats.sp = op->stats.maxsp; |
|
|
2483 | } |
|
|
2484 | op->last_sp = 0; |
|
|
2485 | } |
|
|
2486 | else |
|
|
2487 | op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10); |
|
|
2488 | } |
|
|
2489 | else |
|
|
2490 | op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10); |
|
|
2491 | } |
|
|
2492 | |
|
|
2493 | /* Regenerate Grace */ |
2424 | /* Regenerate Grace */ |
2494 | /* I altered this a little - maximum grace is ony achieved through prayer -b.t. */ |
2425 | /* I altered this a little - maximum grace is ony achieved through prayer -b.t. */ |
2495 | if (--op->last_grace < 0) |
2426 | if (--op->last_grace < 0) |
2496 | { |
2427 | { |
2497 | if (op->stats.grace < op->stats.maxgrace / 2) |
2428 | if (op->stats.grace < op->stats.maxgrace / 2) |
… | |
… | |
2516 | op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10); |
2447 | op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10); |
2517 | } |
2448 | } |
2518 | /* wearing stuff doesn't detract from grace generation. */ |
2449 | /* wearing stuff doesn't detract from grace generation. */ |
2519 | } |
2450 | } |
2520 | |
2451 | |
|
|
2452 | if (op->stats.food > 0) |
|
|
2453 | { |
2521 | /* Regenerate Hit Points */ |
2454 | /* Regenerate Spell Points */ |
2522 | if (--op->last_heal < 0) |
2455 | if (!op->contr->golem && --op->last_sp < 0) |
2523 | { |
|
|
2524 | if (op->stats.hp < op->stats.maxhp) |
|
|
2525 | { |
2456 | { |
2526 | op->stats.hp++; |
2457 | gen_sp = gen_sp * 10 / (op->contr->gen_sp_armour < 10 ? 10 : op->contr->gen_sp_armour); |
2527 | /* dms do not consume food */ |
2458 | |
2528 | if (!QUERY_FLAG (op, FLAG_WIZ)) |
2459 | if (op->stats.sp < op->stats.maxsp) |
2529 | { |
2460 | { |
|
|
2461 | op->stats.sp++; |
|
|
2462 | |
|
|
2463 | /* dms do not consume food */ |
|
|
2464 | if (!QUERY_FLAG (op, FLAG_WIZ)) |
|
|
2465 | { |
2530 | op->stats.food--; |
2466 | op->stats.food--; |
|
|
2467 | |
2531 | if (op->contr->digestion < 0) |
2468 | if (op->contr->digestion < 0) |
2532 | op->stats.food += op->contr->digestion; |
2469 | op->stats.food += op->contr->digestion; |
2533 | else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) |
2470 | else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) |
2534 | op->stats.food = last_food; |
2471 | op->stats.food = last_food; |
|
|
2472 | } |
2535 | } |
2473 | } |
2536 | } |
|
|
2537 | |
2474 | |
2538 | if (max_hp > 1) |
2475 | if (max_sp > 1) |
2539 | { |
|
|
2540 | over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; |
|
|
2541 | if (over_hp > 0) |
|
|
2542 | { |
2476 | { |
2543 | op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; |
2477 | over_sp = (gen_sp + 10) / rate_sp; |
|
|
2478 | if (over_sp > 0) |
|
|
2479 | { |
|
|
2480 | if (op->stats.sp < op->stats.maxsp) |
|
|
2481 | { |
|
|
2482 | op->stats.sp += over_sp > max_sp ? max_sp : over_sp; |
|
|
2483 | |
|
|
2484 | if (random_roll (0, rate_sp - 1, op, PREFER_LOW) > ((gen_sp + 10) % rate_sp)) |
|
|
2485 | op->stats.sp--; |
|
|
2486 | |
|
|
2487 | if (op->stats.sp > op->stats.maxsp) |
|
|
2488 | op->stats.sp = op->stats.maxsp; |
|
|
2489 | } |
|
|
2490 | |
2544 | op->last_heal = 0; |
2491 | op->last_sp = 0; |
|
|
2492 | } |
|
|
2493 | else |
|
|
2494 | op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10); |
2545 | } |
2495 | } |
2546 | else |
2496 | else |
|
|
2497 | op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10); |
|
|
2498 | } |
|
|
2499 | |
|
|
2500 | /* Regenerate Hit Points */ |
|
|
2501 | if (--op->last_heal < 0) |
|
|
2502 | { |
|
|
2503 | if (op->stats.hp < op->stats.maxhp) |
2547 | { |
2504 | { |
2548 | op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); |
2505 | op->stats.hp++; |
|
|
2506 | |
|
|
2507 | /* dms do not consume food */ |
|
|
2508 | if (!QUERY_FLAG (op, FLAG_WIZ)) |
|
|
2509 | { |
|
|
2510 | op->stats.food--; |
|
|
2511 | |
|
|
2512 | if (op->contr->digestion < 0) |
|
|
2513 | op->stats.food += op->contr->digestion; |
|
|
2514 | else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) |
|
|
2515 | op->stats.food = last_food; |
|
|
2516 | } |
2549 | } |
2517 | } |
|
|
2518 | |
|
|
2519 | if (max_hp > 1) |
|
|
2520 | { |
|
|
2521 | over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; |
|
|
2522 | |
|
|
2523 | if (over_hp > 0) |
|
|
2524 | { |
|
|
2525 | op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; |
|
|
2526 | op->last_heal = 0; |
|
|
2527 | } |
|
|
2528 | else |
|
|
2529 | op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); |
2550 | } |
2530 | } |
2551 | else |
2531 | else |
2552 | { |
|
|
2553 | op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); |
2532 | op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); |
2554 | } |
2533 | } |
2555 | } |
2534 | } |
2556 | |
2535 | |
2557 | /* Digestion */ |
2536 | /* Digestion */ |
2558 | if (--op->last_eat < 0) |
2537 | if (--op->last_eat < 0) |
… | |
… | |
2595 | new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); |
2574 | new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); |
2596 | manual_apply (op, flesh, 0); |
2575 | manual_apply (op, flesh, 0); |
2597 | } |
2576 | } |
2598 | } |
2577 | } |
2599 | |
2578 | |
2600 | while (op->stats.food < 0 && op->stats.hp >= 0) |
2579 | if (op->stats.food < 0) |
2601 | op->stats.food++, op->stats.hp--; |
2580 | { |
|
|
2581 | op->stats.hp += op->stats.food; |
|
|
2582 | op->stats.food = 0; |
|
|
2583 | } |
2602 | |
2584 | |
2603 | if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) |
2585 | if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) |
2604 | kill_player (op); |
2586 | kill_player (op); |
2605 | } |
2587 | } |
2606 | } |
2588 | } |