Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,281 changes: 2,281 additions & 0 deletions src/cute_c2.h

Large diffs are not rendered by default.

2,694 changes: 1,666 additions & 1,028 deletions src/game_character.cpp

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions src/game_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,45 @@
#include <lcf/rpg/savemapeventbase.h>
#include "drawable.h"
#include "utils.h"
#include "cute_c2.h"

/**
* Game_Character class.
*/
class Game_Character {
public:


//TODO - PIXELMOVE
float real_x;
float real_y;

float target_x;
float target_y;
c2v move_direction;
bool forced_skip = false; //When a movement is not skippable, but it is forced to be skiped.
bool is_moving_toward_target = false;
bool is_move_toward_target_skippable = false;

bool MoveVector(c2v vector);
bool MoveVector(float vx, float vy);
float GetCustomZoom() const { return custom_zoom; }
void SetCustomZoom(float z) { custom_zoom = z; }

float GetRealX() const;
float GetRealY() const;

void SetMoveTowardTarget(c2v position, bool skippable);
void SetMoveTowardTarget(float x, float y, bool skippable);
bool UpdateMoveTowardTarget();

float GetStepSize() const;


// END - PIXELMOVE



using AnimType = lcf::rpg::EventPage::AnimType;

enum Type {
Expand Down Expand Up @@ -585,6 +618,7 @@ class Game_Character {
* @post If successful, IsStopping() == false.
*/
bool Jump(int x, int y);
bool Jump(float x, float y);

/**
* Check if this can move to the given tile.
Expand Down Expand Up @@ -913,6 +947,9 @@ class Game_Character {
UpLeft
};

float Epsilon = pow(256, -2); //TODO - PIXELMOVE


static bool IsDirectionDiagonal(int d);

/** Reverses a direction, ex: ReverseDir(Up) == Down. */
Expand All @@ -924,6 +961,10 @@ class Game_Character {
static constexpr int GetDxFromDirection(int dir);
static constexpr int GetDyFromDirection(int dir);

/** Wait time for DOOM mode */
int doomWait = 0;


protected:
explicit Game_Character(Type type, lcf::rpg::SaveMapEventBase* d);
/** Check for and fix incorrect data after loading save game */
Expand All @@ -944,10 +985,18 @@ class Game_Character {
void UpdateFlash();
bool BeginMoveRouteJump(int32_t& current_index, const lcf::rpg::MoveRoute& current_route);

// For pixel-perfect jumping
float jump_start_real_x = 0.0f;
float jump_start_real_y = 0.0f;
float jump_end_real_x = 0.0f;
float jump_end_real_y = 0.0f;

lcf::rpg::SaveMapEventBase* data();
const lcf::rpg::SaveMapEventBase* data() const;

int original_move_frequency = 2;

float custom_zoom = 1.0f; // Default is 100%
// contains if any movement (<= step_forward) of a forced move route was successful

Type _type = {};
Expand Down Expand Up @@ -994,6 +1043,14 @@ inline Game_Character::Type Game_Character::GetType() const {
return _type;
}


//TODO - PIXELMOVE
inline float Game_Character::GetStepSize() const {
return (float)(1 << (1 + GetMoveSpeed())) / 256.0; // SCREEN_TILE_SIZE == 265
}
//END - PIXELMOVE


inline int Game_Character::GetX() const {
return data()->position_x;
}
Expand Down
9 changes: 9 additions & 0 deletions src/game_config_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ void Game_ConfigGame::LoadFromArgs(CmdlineParser& cp) {
new_game.Set(arg.ArgIsOn());
continue;
}
if (cp.ParseNext(arg, 0, {"--pixel-movement", "--no-pixel-movement"})) {
allow_pixel_movement.Set(arg.ArgIsOn());
patch_override = true;
continue;
}
if (cp.ParseNext(arg, 1, "--engine")) {
if (arg.NumValues() > 0) {
const auto& v = arg.Value(0);
Expand Down Expand Up @@ -235,6 +240,10 @@ void Game_ConfigGame::LoadFromStream(Filesystem_Stream::InputStream& is) {
patch_override = true;
}

if (allow_pixel_movement.FromIni(ini)) {
patch_override = true;
}

if (RuntimePatches::ParseFromIni(ini)) {
patch_override = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/game_config_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct Game_ConfigGame {

ConfigParam<int> patch_guardrevamp_normal{ "GuardRevamp", "Changes damage calculation for defense situations (Normal)", "Patch", "GuardRevamp.NormalDefense", 0 };
ConfigParam<int> patch_guardrevamp_strong{ "GuardRevamp", "Changes damage calculation for defense situations (Strong)", "Patch", "GuardRevamp.StrongDefense", 0 };

ConfigParam<int> allow_pixel_movement{"allow_pixel_movement", "Allow pixel-based movement instead of tile-based.", "Patch", "allow_pixel_movement", false};
// Command line only
BoolConfigParam patch_support{ "Support patches", "When OFF all patch support is disabled", "", "", true };

Expand Down
102 changes: 102 additions & 0 deletions src/game_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "output.h"
#include <cmath>
#include <cassert>
#include "cute_c2.h"

Game_Event::Game_Event(int map_id, const lcf::rpg::Event* event) :
Game_EventBase(Event),
Expand All @@ -44,7 +45,18 @@ Game_Event::Game_Event(int map_id, const lcf::rpg::Event* event) :
SetX(event->x);
SetY(event->y);

// if (true) {
if (Player::game_config.allow_pixel_movement.Get()){ //TODO - PIXELMOVE
real_x = (float)GetX();
real_y = (float)GetY();
//Output::Warning("Event Pos = {}x{}", real_x, real_y);
}// END - PIXELMOVE


RefreshPage();

Output::Debug("event[{}].name: {}", data()->ID, GetSpriteName()); //TODO - PIXELMOVE

}

void Game_Event::SanitizeData() {
Expand Down Expand Up @@ -92,6 +104,13 @@ void Game_Event::SetSaveData(lcf::rpg::SaveMapEvent save)
interpreter->SetState(state);
}
}

// if (true) {
if (Player::game_config.allow_pixel_movement.Get()){ // TODO - PIXELMOVE
real_x = (float)GetX();
real_y = (float)GetY();
} // END - PIXELMOVE

}

lcf::rpg::SaveMapEvent Game_Event::GetSaveData() const {
Expand Down Expand Up @@ -469,7 +488,24 @@ void Game_Event::MoveTypeRandom() {
return;
}

/*
Move(GetDirection());
*/

// if (true) { // TODO - PIXELMOVE
if (Player::game_config.allow_pixel_movement.Get()){
c2v target = c2V(
round(real_x + GetDxFromDirection(GetDirection())),
round(real_y + GetDyFromDirection(GetDirection()))
);
SetMoveTowardTarget(target, true);
UpdateMoveTowardTarget();
}
else {
Move(GetDirection());
} // END - PIXELMOVE



if (IsStopping()) {
if (IsWaitingForegroundExecution() || (GetStopCount() >= GetMaxStopCount() + 60)) {
Expand Down Expand Up @@ -535,6 +571,7 @@ void Game_Event::MoveTypeTowardsOrAwayPlayer(bool towards) {

const auto prev_dir = GetDirection();

/*
int dir = 0;
if (!in_sight) {
dir = Rand::GetRandomNumber(0, 3);
Expand All @@ -552,6 +589,71 @@ void Game_Event::MoveTypeTowardsOrAwayPlayer(bool towards) {
}

Move(dir);
*/


// if (true) {
if (Player::game_config.allow_pixel_movement.Get()){ //TODO - PIXELMOVE
int dir = 0;
int draw = 0;
c2v target;
if (!in_sight) {
dir = Rand::GetRandomNumber(0, 3);
}
else {
draw = Rand::GetRandomNumber(0, 9);
if (draw == 0) {
dir = GetDirection();
}
else if (draw == 1) {
dir = Rand::GetRandomNumber(0, 3);
}
}
if (towards) {
TurnTowardCharacter(GetPlayer());
}
else {
TurnAwayFromCharacter(GetPlayer());
}
if (draw > 1) {
int flag = towards ? 1 : -1;
target.x = (Main_Data::game_player->real_x - real_x) * flag;
target.y = (Main_Data::game_player->real_y - real_y) * flag;
target = c2Add(c2Norm(target), c2V(real_x, real_y));
}
else {
SetDirection(dir);
target.x = round(real_x + GetDxFromDirection(dir));
target.y = round(real_y + GetDyFromDirection(dir));
}
SetMoveTowardTarget(target, true);
UpdateMoveTowardTarget();
}
else {
int dir = 0;
if (!in_sight) {
dir = Rand::GetRandomNumber(0, 3);
}
else {
int draw = Rand::GetRandomNumber(0, 9);
if (draw == 0) {
dir = GetDirection();
}
else if (draw == 1) {
dir = Rand::GetRandomNumber(0, 3);
}
else {
dir = towards
? GetDirectionToCharacter(GetPlayer())
: GetDirectionAwayCharacter(GetPlayer());
}
}

Move(dir);
} // END - PIXEL MOVE




if (IsStopping()) {
if (IsWaitingForegroundExecution() || (GetStopCount() >= GetMaxStopCount() + 60)) {
Expand Down
1 change: 1 addition & 0 deletions src/game_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Game_Event : public Game_EventBase {
/** Load from saved game */
void SetSaveData(lcf::rpg::SaveMapEvent save);


/** @return save game data */
lcf::rpg::SaveMapEvent GetSaveData() const;

Expand Down
4 changes: 3 additions & 1 deletion src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,9 @@ void Game_Interpreter::SetupChoices(const std::vector<std::string>& choices, int
}

pm.SetChoiceContinuation([this, indent](int choice_result) {
SetSubcommandIndex(indent, choice_result);
if (IsRunning()) {
SetSubcommandIndex(indent, choice_result);
}
return AsyncOp();
});

Expand Down
Loading