Skip to content

Commit

Permalink
MoveEvent + RewriteMap + SQRT/POW
Browse files Browse the repository at this point in the history
Add variable as event in MoveRoute
Add RewriteMap ( WIP )
Correction for QRT and POW variables
  • Loading branch information
MackValentine committed May 2, 2024
1 parent b313163 commit 7dc836e
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 14 deletions.
113 changes: 108 additions & 5 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3134,6 +3134,13 @@ bool Game_Interpreter::CommandPlayerVisibility(lcf::rpg::EventCommand const& com

bool Game_Interpreter::CommandMoveEvent(lcf::rpg::EventCommand const& com) { // code 11330
int event_id = com.parameters[0];
int repeat_ = com.parameters[2];
int mode = com.parameters[2] >> 8;

int repeat = ManiacBitmask(com.parameters[2], 0x1);

event_id = ValueOrVariable(mode, com.parameters[0]);

Game_Character* event = GetCharacter(event_id);
if (event != NULL) {
// If the event is a vehicle in use, push the commands to the player instead
Expand All @@ -3149,7 +3156,7 @@ bool Game_Interpreter::CommandMoveEvent(lcf::rpg::EventCommand const& com) { //
move_freq = 6;
}

route.repeat = com.parameters[2] != 0;
route.repeat = repeat != 0;
route.skippable = com.parameters[3] != 0;

for (auto it = com.parameters.begin() + 4; it < com.parameters.end(); ) {
Expand Down Expand Up @@ -3584,6 +3591,15 @@ bool Game_Interpreter::CommandConditionalBranch(lcf::rpg::EventCommand const& co
}
break;
case 6:
value1 = ValueOrVariable(com.parameters[3], com.parameters[1]);

if (com.parameters[4] == 1) {
Game_Character* ch = Game_Character::GetCharacter(value1, value1);
if (ch != nullptr)
result = true;
break;
}
character = GetCharacter(value1);
// Orientation of char
character = GetCharacter(com.parameters[1]);
if (character != NULL) {
Expand Down Expand Up @@ -4459,13 +4475,13 @@ bool Game_Interpreter::CommandManiacGetPictureInfo(lcf::rpg::EventCommand const&
x = Utils::RoundTo<int>(data.current_x);
y = Utils::RoundTo<int>(data.current_y);
width = Utils::RoundTo<int>(width * data.current_magnify / 100.0);
height = Utils::RoundTo<int>(height * data.maniac_current_magnify_height / 100.0);
//height = Utils::RoundTo<int>(height * data.maniac_current_magnify_height / 100.0);
break;
case 2:
x = Utils::RoundTo<int>(data.finish_x);
y = Utils::RoundTo<int>(data.finish_y);
width = Utils::RoundTo<int>(width * data.finish_magnify / 100.0);
height = Utils::RoundTo<int>(height * data.maniac_finish_magnify_height / 100.0);
//height = Utils::RoundTo<int>(height * data.maniac_finish_magnify_height / 100.0);
break;
}

Expand Down Expand Up @@ -4622,12 +4638,99 @@ bool Game_Interpreter::CommandManiacKeyInputProcEx(lcf::rpg::EventCommand const&
return true;
}

bool Game_Interpreter::CommandManiacRewriteMap(lcf::rpg::EventCommand const&) {
bool Game_Interpreter::CommandManiacRewriteMap(lcf::rpg::EventCommand const& com) {
if (!Player::IsPatchManiac()) {
return true;
}

Output::Warning("Maniac Patch: Command RewriteMap not supported");

int layer = com.parameters[2];
int tile_type = 0;
int tile_id = com.parameters[3];

std::bitset<32> f(com.parameters[0]);
//Output::Debug("B : {}", f.to_string());

if (f[0] == 1)
tile_type = 1;
if (f[1] == 1)
tile_type = 2;

if (tile_type >= 3)
tile_type = tile_type % 16;

int id = tile_id;
if (tile_type == 1)
id = Main_Data::game_variables.get()->Get(tile_id);
else if (tile_type == 2)
id = Main_Data::game_variables.get()->Get(Main_Data::game_variables.get()->Get(tile_id));

int ranged = com.parameters[1];

int x = com.parameters[4];
int y = com.parameters[5];
int w = com.parameters[6];
int h = com.parameters[7];

int x_type = 0;
int y_type = 0;
int w_type = 0;
int h_type = 0;

if (f[4] == 1)
x_type = 1;
else if (f[5] == 1)
x_type = 2;

if (x_type == 1)
x = Main_Data::game_variables.get()->Get(x);
else if (x_type == 2)
x = Main_Data::game_variables.get()->Get(Main_Data::game_variables.get()->Get(x));


if (f[8] == 1)
y_type = 1;
else if (f[9] == 1)
y_type = 2;

if (y_type == 1)
y = Main_Data::game_variables.get()->Get(y);
else if (y_type == 2)
y = Main_Data::game_variables.get()->Get(Main_Data::game_variables.get()->Get(y));


if (f[12] == 1)
w_type = 1;
else if (f[13] == 1)
w_type = 2;

if (w_type == 1)
w = Main_Data::game_variables.get()->Get(w);
else if (w_type == 2)
w = Main_Data::game_variables.get()->Get(Main_Data::game_variables.get()->Get(w));


if (f[16] == 1)
h_type = 1;
else if (f[17] == 1)
h_type = 2;

if (h_type == 1)
h = Main_Data::game_variables.get()->Get(h);
else if (h_type == 2)
h = Main_Data::game_variables.get()->Get(Main_Data::game_variables.get()->Get(h));


// Output::Debug("L{} R{} T{} ID{} X{} Y{} W{} H{} VX{} VY{} VW{} VH{}", layer, ranged, tile_type, id, x, y, w, h, x_type, y_type, w_type, h_type);


Scene_Map* scene = (Scene_Map*)Scene::Find(Scene::Map).get();
if (!scene)
return true;
for (int i = 0; i < w; i++)
for (int j = 0; j < h; j++)
scene->spriteset->ChangeTile(layer, x + i, y + j, id);

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/game_interpreter_control_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,10 @@ int ControlVariables::Enemy(int op, int enemy_idx) {
}

int ControlVariables::Pow(int arg1, int arg2) {
return static_cast<int>(std::pow(arg1, arg2));
return static_cast<int>(std::pow(arg2, arg1));
}

int ControlVariables::Sqrt(int arg, int mul) {
int ControlVariables::Sqrt(int mul, int arg) {
// This is not how negative sqrt works, just following the implementation here
int res = static_cast<int>(sqrt(abs(arg)) * mul);
if (arg < 0) {
Expand Down
15 changes: 15 additions & 0 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2037,3 +2037,18 @@ bool Game_Map::Parallax::FakeXPosition() {
bool Game_Map::Parallax::FakeYPosition() {
return parallax_fake_y;
}

int Game_Map::ChangeTile(int layer, int x, int y, int new_id) {

int tile_index = x + y * GetTilesX();

//Output::Debug("{}", map->upper_layer[tile_index]);

if (layer == 0)
map->lower_layer[tile_index] = 5048 - 48 + (new_id)-18;
else
map->upper_layer[tile_index] = new_id + 10000;

SetNeedRefresh(true);
return 1;
}
3 changes: 3 additions & 0 deletions src/game_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,9 @@ namespace Game_Map {
void AddEventToSwitchCache(lcf::rpg::Event& ev, int switch_id);
void AddEventToVariableCache(lcf::rpg::Event& ev, int var_id);


int ChangeTile(int layer, int x, int y, int new_id);

namespace Parallax {
struct Params {
std::string name;
Expand Down
12 changes: 6 additions & 6 deletions src/game_pictures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void SyncCurrentToFinish(lcf::rpg::SavePicture& data) {
data.current_blue = data.finish_blue;
data.current_sat = data.finish_sat;
data.current_magnify = data.finish_magnify;
data.maniac_current_magnify_height = data.maniac_finish_magnify_height;
//data.maniac_current_magnify_height = data.maniac_finish_magnify_height;
data.current_top_trans = data.finish_top_trans;
data.current_bot_trans = data.finish_bot_trans;
if (do_effect) {
Expand Down Expand Up @@ -116,8 +116,8 @@ std::vector<lcf::rpg::SavePicture> Game_Pictures::GetSaveData() const {
}
if (!Player::IsPatchManiac()) {
// Default the values so they are not stored in the savegame
data.maniac_current_magnify_height = 100;
data.maniac_finish_magnify_height = 100;
//data.maniac_current_magnify_height = 100;
//data.maniac_finish_magnify_height = 100;
}
save.push_back(std::move(data));
}
Expand Down Expand Up @@ -540,7 +540,7 @@ void Game_Pictures::Picture::Update(bool is_battle) {
data.current_blue = interpolate(data.current_blue, data.finish_blue);
data.current_sat = interpolate(data.current_sat, data.finish_sat);
data.current_magnify = interpolate(data.current_magnify, data.finish_magnify);
data.maniac_current_magnify_height = interpolate(data.maniac_current_magnify_height, data.maniac_finish_magnify_height);
//data.maniac_current_magnify_height = interpolate(data.maniac_current_magnify_height, data.maniac_finish_magnify_height);
data.current_top_trans = interpolate(data.current_top_trans, data.finish_top_trans);
data.current_bot_trans = interpolate(data.current_bot_trans, data.finish_bot_trans);
}
Expand Down Expand Up @@ -609,7 +609,7 @@ Game_Pictures::ShowParams Game_Pictures::Picture::GetShowParams() const {
params.position_x = static_cast<int>(data.finish_x);
params.position_y = static_cast<int>(data.finish_y);
params.magnify_width = data.finish_magnify;
params.magnify_height = data.maniac_finish_magnify_height;
//params.magnify_height = data.maniac_finish_magnify_height;
params.top_trans = data.finish_top_trans;
params.bottom_trans = data.finish_bot_trans;
params.red = data.finish_red;
Expand Down Expand Up @@ -640,7 +640,7 @@ void Game_Pictures::Picture::SetNonEffectParams(const Params& params, bool set_p
data.finish_y = params.position_y;
}
data.finish_magnify = params.magnify_width;
data.maniac_finish_magnify_height = params.magnify_height;
//data.maniac_finish_magnify_height = params.magnify_height;
data.finish_top_trans = params.top_trans;
data.finish_bot_trans = params.bottom_trans;
data.finish_red = params.red;
Expand Down
2 changes: 1 addition & 1 deletion src/sprite_picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void Sprite_Picture::Draw(Bitmap& dst) {
SetZoomX(data.current_magnify / 100.0);
SetZoomY(data.current_magnify / 100.0);
if (Player::IsPatchManiac()) {
SetZoomY(data.maniac_current_magnify_height / 100.0);
//SetZoomY(data.maniac_current_magnify_height / 100.0);
}

auto sr = GetSrcRect();
Expand Down
28 changes: 28 additions & 0 deletions src/spriteset_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,31 @@ void Spriteset_Map::CalculatePanoramaRenderOffset() {
}
}
}

void Spriteset_Map::ChangeTile(int layer, int x, int y, int new_id) {

auto t = tilemap->GetMapDataDown();
if (layer == 1)
t = tilemap->GetMapDataUp();

int i = x + y * Game_Map::GetTilesX();

//Output::Debug("S : {}/{}", i, t.size());

if (i <= t.size()) {

if (layer == 0)
t[i] = 5048 - 48 + (new_id)-18;
else
t[i] = new_id + 10000;

if (layer == 0)
tilemap->SetMapDataDown(t);
else
tilemap->SetMapDataUp(t);

Game_Map::ChangeTile(layer, x, y, new_id);
Game_Map::SetNeedRefresh(true);
}

}
6 changes: 6 additions & 0 deletions src/spriteset_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class Spriteset_Map {
*/
void SubstituteUp(int old_id, int new_id);


/**
* Change tile at position X/Y
*/
void ChangeTile(int layer, int x, int y, int new_id);

/**
* @return true if we should clear the screen before drawing the map
*/
Expand Down

0 comments on commit 7dc836e

Please sign in to comment.