Skip to content

Commit

Permalink
Revamp MakeWay() and split it into CheckWay()/MakeWay()
Browse files Browse the repository at this point in the history
  • Loading branch information
ell1e committed Oct 9, 2023
1 parent ad6e823 commit 69595eb
Show file tree
Hide file tree
Showing 4 changed files with 294 additions and 68 deletions.
15 changes: 15 additions & 0 deletions src/game_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "rand.h"
#include <cmath>
#include <cassert>
#include <unordered_set>

Game_Character::Game_Character(Type type, lcf::rpg::SaveMapEventBase* d) :
_type(type), _data(d)
Expand Down Expand Up @@ -469,6 +470,20 @@ bool Game_Character::MakeWay(int from_x, int from_y, int to_x, int to_y) {
return Game_Map::MakeWay(*this, from_x, from_y, to_x, to_y);
}


bool Game_Character::CheckWay(int from_x, int from_y, int to_x, int to_y) {
return Game_Map::CheckWay(*this, from_x, from_y, to_x, to_y);
}


bool Game_Character::CheckWayEx(
int from_x, int from_y, int to_x, int to_y, bool ignore_all_events,
std::unordered_set<int> *ignore_some_events_by_id) {
return Game_Map::CheckWayEx(*this, from_x, from_y, to_x, to_y,
ignore_all_events, ignore_some_events_by_id);
}


bool Game_Character::Move(int dir) {
if (!IsStopping()) {
return true;
Expand Down
34 changes: 34 additions & 0 deletions src/game_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// Headers
#include <cstdint>
#include <string>
#include <unordered_set>
#include "color.h"
#include "flash.h"
#include <lcf/rpg/moveroute.h>
Expand Down Expand Up @@ -585,6 +586,39 @@ class Game_Character {
*/
virtual bool MakeWay(int from_x, int from_y, int to_x, int to_y);

/**
* Check if this can move to the given tile, but without
* affecting the map. This is usually what you want to use
* for planning, e.g. path finding, where the move isn't
* meant to be actually executed just yet.
*
* @param from_x Moving from x position
* @param from_y Moving from y position
* @param to_x Moving from x position
* @param to_y Moving from y position
*
* @return true if the hypothetical movement of
* this event from (to_x, to_y) from (from_x, from_y) is possible
*/
virtual bool CheckWay(int from_x, int from_y, int to_x, int to_y);

/**
* Like CheckWay, but allows ignoring all events in the check,
* or only some events specified by event id.
*
* @param from_x See CheckWay.
* @param from_y See CheckWay.
* @param to_x See CheckWay.
* @param to_y See Checkway.
* @param ignore_all_events If true, only consider map collision
* and completely ignore any events in the way.
* @param ignore_some_events_by_id If specified, all events with
* ids found in this list will be ignored in the collision check.
* @return true See CheckWay.
*/
virtual bool CheckWayEx(int from_x, int from_y, int to_x, int to_y,
bool ignore_all_events, std::unordered_set<int> *ignore_some_events_by_id);

/**
* Turns the character 90 Degree to the left.
*/
Expand Down
Loading

0 comments on commit 69595eb

Please sign in to comment.