Skip to content

Commit ba14d2f

Browse files
committed
Fixing Gorlab Swamps
This involves: 1. Making sleep timer not clear sleep flag: Gorlab Swamp usecode checks for it to determine who is awake. 2. Fixing Npc_proximity_handler::handle_event that prevents wake-up with sleep flag set due to change above. 3. Disable party members from being woken from sleep schedule by Avatar. 4. Make awake checks depend on frame-rate and slightly tweaking the probabilities to account for the above. Fixes exult#297 Swamps of Gorlab sleep is broken
1 parent 3869125 commit ba14d2f

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

npcnear.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "gamewin.h"
3333
#include "ignore_unused_variable_warning.h"
3434
#include "items.h"
35+
#include "paths.h"
3536
#include "schedule.h"
3637
#include "ucmachine.h"
3738

@@ -58,16 +59,16 @@ bool Bg_dont_wake(Game_window* gwin, Actor* npc);
5859
void Npc_proximity_handler::add(
5960
unsigned long curtime, // Current time (msecs).
6061
Npc_actor* npc,
61-
int additional_secs // More secs. to wait.
62+
int additional_ticks // More secs. to wait.
6263
) {
6364
int msecs; // Hostile? Wait 0-2 secs.
6465
if (npc->get_effective_alignment() >= Actor::evil) {
6566
msecs = rand() % 2000;
6667
} else { // Wait between 2 & 6 secs.
6768
msecs = (rand() % 4000) + 2000;
6869
}
69-
unsigned long newtime = curtime + msecs;
70-
newtime += 1000 * additional_secs;
70+
unsigned long newtime = curtime + (msecs * gwin->get_std_delay() / 100);
71+
newtime += additional_ticks * gwin->get_std_delay();
7172
gwin->get_tqueue()->add(newtime, this, npc);
7273
}
7374

@@ -113,11 +114,10 @@ void Npc_proximity_handler::handle_event(unsigned long curtime, uintptr udata) {
113114
auto sched
114115
= static_cast<Schedule::Schedule_types>(npc->get_schedule_type());
115116
// Sleep schedule?
116-
if (npc->get_schedule() && sched == Schedule::sleep &&
117-
// But not under a sleep spell?
118-
!npc->get_flag(Obj_flags::asleep) && gwin->is_main_actor_inside()
117+
if (npc->get_schedule() && sched == Schedule::sleep && !npc->is_in_party()
119118
&& !Bg_dont_wake(gwin, npc) && npc->distance(gwin->get_main_actor()) < 6
120-
&& rand() % 3 != 0) {
119+
&& Fast_pathfinder_client::is_straight_path(npc, gwin->get_main_actor())
120+
&& (rand() % 3) == 0) {
121121
// Trick: Stand, but stay in
122122
// sleep_schedule.
123123
npc->get_schedule()->ending(Schedule::stand);

npcnear.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Npc_proximity_handler : public Time_sensitive {
4343
}
4444

4545
// Add npc to queue.
46-
void add(unsigned long curtime, Npc_actor* npc, int additional_secs = 0);
46+
void add(unsigned long curtime, Npc_actor* npc, int additional_ticks = 0);
4747
void remove(Npc_actor* npc); // Remove.
4848
// Run usecode function.
4949
void handle_event(unsigned long curtime, uintptr udata) override;

npctime.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ void Npc_sleep_timer::handle_event(unsigned long curtime, uintptr udata) {
408408
&& (curtime >= end_time || !npc->get_flag(Obj_flags::asleep))) {
409409
// Avoid waking sleeping people.
410410
if (npc->get_schedule_type() == Schedule::sleep) {
411-
npc->clear_sleep();
411+
// This breaks Gorlab Swamp in SI/SS.
412+
// npc->clear_sleep();
412413
} else if (!npc->is_dead()) {
413414
// Don't wake the dead.
414415
npc->clear_flag(Obj_flags::asleep);

0 commit comments

Comments
 (0)