|
|
|
@ -235,6 +235,11 @@ namespace gui { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FSM::keyboard_mouse() { |
|
|
|
|
if($autowalking) { |
|
|
|
|
autowalk(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while(const auto ev = $window.pollEvent()) { |
|
|
|
|
if(ev->is<sf::Event::Closed>()) { |
|
|
|
|
event(Event::QUIT); |
|
|
|
@ -251,6 +256,7 @@ namespace gui { |
|
|
|
|
|
|
|
|
|
if(const auto* key = ev->getIf<sf::Event::KeyPressed>()) { |
|
|
|
|
using KEY = sf::Keyboard::Scan; |
|
|
|
|
|
|
|
|
|
switch(key->scancode) { |
|
|
|
|
case KEY::W: |
|
|
|
|
event(Event::MOVE_FORWARD); |
|
|
|
@ -286,6 +292,8 @@ namespace gui { |
|
|
|
|
sound::mute(false); |
|
|
|
|
$main_ui.debug(); |
|
|
|
|
break; |
|
|
|
|
case KEY::O: |
|
|
|
|
$autowalking = true; |
|
|
|
|
default: |
|
|
|
|
break; // ignored
|
|
|
|
|
} |
|
|
|
@ -398,4 +406,108 @@ namespace gui { |
|
|
|
|
|
|
|
|
|
run_systems(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FSM::autowalk() { |
|
|
|
|
fmt::println("I'M WALKIN' HEAR!"); |
|
|
|
|
|
|
|
|
|
$window.handleEvents( |
|
|
|
|
[&](const sf::Event::KeyPressed &) { |
|
|
|
|
$autowalking = false; |
|
|
|
|
fmt::println("ABORT AUTOWALK"); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if(!$autowalking) return; |
|
|
|
|
|
|
|
|
|
while(in_state(State::IN_COMBAT) || in_state(State::ATTACKING)) { |
|
|
|
|
if(in_state(State::ATTACKING)) { |
|
|
|
|
event(Event::TICK); |
|
|
|
|
} else { |
|
|
|
|
event(Event::ATTACK); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handle_world_events(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto& player_position = $level.world->get<Position>($level.player); |
|
|
|
|
auto current = player_position.location; |
|
|
|
|
Point target = current; |
|
|
|
|
bool found = $level.map->neighbors(target, false, -1); |
|
|
|
|
if(!found) { |
|
|
|
|
dbc::log("no neighbor found, aborting autowalk"); |
|
|
|
|
$autowalking = false; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!$level.map->can_move(target)) { |
|
|
|
|
dbc::log("neighbors is telling me to go to a bad spot."); |
|
|
|
|
$autowalking = false; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int delta_x = int(target.x) - int(current.x); |
|
|
|
|
int delta_y = int(target.y) - int(current.y); |
|
|
|
|
|
|
|
|
|
int facing = $main_ui.$compass_dir; |
|
|
|
|
int target_facing = 0; |
|
|
|
|
|
|
|
|
|
if(delta_x == -1 && delta_y == 0) { |
|
|
|
|
// west
|
|
|
|
|
fmt::println("WEST: {}, {}", target.x, target.y); |
|
|
|
|
target_facing = 4; |
|
|
|
|
} else if(delta_x == 1 && delta_y == 0) { |
|
|
|
|
// east
|
|
|
|
|
fmt::println("EAST: {}, {}", target.x, target.y); |
|
|
|
|
target_facing = 0; |
|
|
|
|
} else if(delta_x == 0 && delta_y == 1) { |
|
|
|
|
fmt::println("SOUTH: {}, {}", target.x, target.y); |
|
|
|
|
// south
|
|
|
|
|
target_facing = 2; |
|
|
|
|
} else if(delta_x == 0 && delta_y == -1) { |
|
|
|
|
fmt::println("NORTH: {}, {}", target.x, target.y); |
|
|
|
|
// north
|
|
|
|
|
target_facing = 6; |
|
|
|
|
} else { |
|
|
|
|
dbc::sentinel( |
|
|
|
|
fmt::format("got more than 4 direction result: " |
|
|
|
|
"current={},{} " |
|
|
|
|
"target={},{} " |
|
|
|
|
"delta={},{} ", |
|
|
|
|
current.x, current.y, |
|
|
|
|
target.x, target.y, |
|
|
|
|
delta_x, delta_y)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto dir = facing < target_facing ? Event::ROTATE_LEFT : Event::ROTATE_RIGHT; |
|
|
|
|
|
|
|
|
|
while(facing != target_facing) { |
|
|
|
|
event(dir); |
|
|
|
|
render(); |
|
|
|
|
handle_world_events(); |
|
|
|
|
facing = $main_ui.$compass_dir; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dbc::check($main_ui.$compass_dir == target_facing, |
|
|
|
|
"player isn't facing the correct direction"); |
|
|
|
|
|
|
|
|
|
if(!in_state(State::IN_COMBAT)) { |
|
|
|
|
if(in_state(State::ATTACKING)) { |
|
|
|
|
event(Event::TICK); |
|
|
|
|
} else { |
|
|
|
|
event(Event::MOVE_FORWARD); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handle_world_events(); |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
fmt::println("IN WHILE MOVING"); |
|
|
|
|
event(Event::TICK); |
|
|
|
|
event(Event::ATTACK); |
|
|
|
|
render(); |
|
|
|
|
handle_world_events(); |
|
|
|
|
} while(in_state(State::MOVING)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|