Skip to content
Open
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
65 changes: 65 additions & 0 deletions src/dynrpg_easyrpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,71 @@ bool DynRpg::EasyRpgPlugin::Invoke(std::string_view func, dyn_arg_list args, boo
return EasyOput(args);
} else if (func == "easyrpg_add") {
return EasyAdd(args);
} else if (func == "easyrpg_event_airship_move") {
auto func_name = "easyrpg_event_airship_move";
bool okay = false;
int char_id, allow;

std::tie(char_id, allow) = DynRpg::ParseArgs<int, int>(func_name, args, &okay);
if (!okay) {
return true;
}

if (char_id == 0) {
char_id = Game_Character::CharThisEvent;
} else if (char_id == -1) {
char_id = Game_Character::CharPlayer;
}

// GetCharacter handles: 10001/-1 = Player, 10002 = Boat, 10003 = Ship, 10004 = Airship, 10005/0 = This Event, >0 = Event ID
Game_Character* target = interpreter ? interpreter->GetCharacter(char_id, func_name) : Game_Character::GetCharacter(char_id, 0);
if (target) {
target->SetAllowAirshipMove(allow != 0);
}
return true;
} else if (func == "easyrpg_event_set_z") {
auto func_name = "easyrpg_event_set_z";
bool okay = false;
int char_id, z_value;

std::tie(char_id, z_value) = DynRpg::ParseArgs<int, int>(func_name, args, &okay);
if (!okay) {
return true;
}

if (char_id == 0) {
char_id = Game_Character::CharThisEvent;
} else if (char_id == -1) {
char_id = Game_Character::CharPlayer;
}

Game_Character* target = interpreter ? interpreter->GetCharacter(char_id, func_name) : Game_Character::GetCharacter(char_id, 0);
if (target) {
target->SetAltitude(z_value);
}
return true;
} else if (func == "easyrpg_event_get_z") {
auto func_name = "easyrpg_event_get_z";
bool okay = false;
int char_id, variable_id;

std::tie(char_id, variable_id) = DynRpg::ParseArgs<int, int>(func_name, args, &okay);
if (!okay) {
return true;
}

if (char_id == 0) {
char_id = Game_Character::CharThisEvent;
} else if (char_id == -1) {
char_id = Game_Character::CharPlayer;
}

Game_Character* target = interpreter ? interpreter->GetCharacter(char_id, func_name) : Game_Character::GetCharacter(char_id, 0);
if (target) {
Main_Data::game_variables->Set(variable_id, target->GetAltitude());
Game_Map::SetNeedRefreshForVarChange(variable_id);
}
return true;
}
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/game_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ int Game_Character::GetScreenX() const {
int Game_Character::GetScreenY(bool apply_jump) const {
int y = GetSpriteY() / TILE_SIZE - Game_Map::GetDisplayY() / TILE_SIZE + TILE_SIZE;

if (apply_jump) {
y -= GetJumpHeight();
}

if (Game_Map::LoopVertical()) {
y = Utils::PositiveModulo(y, Game_Map::GetTilesY() * TILE_SIZE);
}

if (apply_jump) {
y -= GetJumpHeight() + GetAltitude();
}

return y;
}

Expand Down
9 changes: 9 additions & 0 deletions src/game_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,12 @@ class Game_Character {
*/
void SetFlying(bool val);

bool GetAllowAirshipMove() const { return allow_airship_move; }
void SetAllowAirshipMove(bool allow) { allow_airship_move = allow; }

virtual int GetAltitude() const { return custom_altitude; }
virtual void SetAltitude(int altitude) { custom_altitude = altitude; }

/**
* @return whether the RPG_RT processed flag is set.
*/
Expand Down Expand Up @@ -944,6 +950,9 @@ class Game_Character {
void UpdateFlash();
bool BeginMoveRouteJump(int32_t& current_index, const lcf::rpg::MoveRoute& current_route);

bool allow_airship_move = false;
int custom_altitude = 0;

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

Expand Down
36 changes: 33 additions & 3 deletions src/game_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ Drawable::Z_t Game_Player::GetScreenZ(int x_offset, int y_offset) const {
return Game_Character::GetScreenZ(x_offset, y_offset) | (0xFFFFu << 16u);
}

int Game_Player::GetAltitude() const {
if (InAirship()) {
auto* vehicle = GetVehicle();
if (vehicle) {
return vehicle->GetAltitude();
}
}
return Game_Character::GetAltitude();
}

void Game_Player::SetAltitude(int altitude) {
if (InAirship()) {
auto* vehicle = GetVehicle();
if (vehicle) {
vehicle->SetAltitude(altitude);
return;
}
}
Game_Character::SetAltitude(altitude);
}

void Game_Player::ReserveTeleport(int map_id, int x, int y, int direction, TeleportTarget::Type tt) {
teleport_target = TeleportTarget(map_id, x, y, direction, tt);

Expand Down Expand Up @@ -283,8 +304,13 @@ bool Game_Player::UpdateAirship() {
}

void Game_Player::UpdateNextMovementAction() {
auto* vehicle = GetVehicle();
bool airship_move_allowed = GetAllowAirshipMove() || (vehicle && vehicle->GetAllowAirshipMove());

if (UpdateAirship()) {
return;
if (!airship_move_allowed || !IsAboard()) {
return;
}
}

UpdateMoveRoute(data()->move_route_index, data()->move_route, true);
Expand Down Expand Up @@ -523,7 +549,9 @@ bool Game_Player::GetOnVehicle() {
data()->aboard = true;

// Note: RPG_RT ignores the lock_facing flag here!
SetFacing(Left);
if (!GetAllowAirshipMove() && !vehicle->GetAllowAirshipMove()) {
SetFacing(Left);
}

data()->preboard_move_speed = GetMoveSpeed();
SetMoveSpeed(vehicle->GetMoveSpeed());
Expand Down Expand Up @@ -575,7 +603,9 @@ bool Game_Player::GetOffVehicle() {
}

// Note: RPG_RT ignores the lock_facing flag here!
SetFacing(Left);
if (!GetAllowAirshipMove() && !vehicle->GetAllowAirshipMove()) {
SetFacing(Left);
}
vehicle->StartDescent();
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/game_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class Game_Player : public Game_PlayerBase {
int GetVehicleType() const;
Game_Vehicle* GetVehicle() const;

int GetAltitude() const override;
void SetAltitude(int altitude) override;

/**
* Set the menu callling flag
*
Expand Down
46 changes: 37 additions & 9 deletions src/game_vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,20 @@ const lcf::rpg::Music& Game_Vehicle::GetBGM() {

void Game_Vehicle::StartDescent() {
if (IsFlying()) {
SetFacing(Left);
if (!GetAllowAirshipMove() && !Main_Data::game_player->GetAllowAirshipMove()) {
SetFacing(Left);
}
descent_start_altitude = GetAltitude();
has_custom_altitude = false;
data()->remaining_descent = SCREEN_TILE_SIZE;
}
}

void Game_Vehicle::StartAscent() {
if (!IsFlying()) {
ascent_start_altitude = GetAltitude();
ascent_target_altitude = std::max<int>(TILE_SIZE, ascent_start_altitude);
has_custom_altitude = false;
data()->remaining_ascent = SCREEN_TILE_SIZE;
SetFlying(true);
}
Expand Down Expand Up @@ -137,18 +144,27 @@ void Game_Vehicle::SyncWithRider(const Game_Character* rider) {
}

int Game_Vehicle::GetAltitude() const {
if (!IsFlying())
if (has_custom_altitude) {
return Game_Character::GetAltitude();
}
if (!IsFlying()) {
return 0;
else if (IsAscending())
return (SCREEN_TILE_SIZE - data()->remaining_ascent) / (SCREEN_TILE_SIZE / TILE_SIZE);
else if (IsDescending())
return data()->remaining_descent / (SCREEN_TILE_SIZE / TILE_SIZE);
else
return SCREEN_TILE_SIZE / (SCREEN_TILE_SIZE / TILE_SIZE);
} else if (IsAscending()) {
return ascent_start_altitude + ((ascent_target_altitude - ascent_start_altitude) * (SCREEN_TILE_SIZE - data()->remaining_ascent)) / SCREEN_TILE_SIZE;
} else if (IsDescending()) {
return (descent_start_altitude * data()->remaining_descent) / SCREEN_TILE_SIZE;
} else {
return ascent_target_altitude;
}
}

void Game_Vehicle::SetAltitude(int altitude) {
Game_Character::SetAltitude(altitude);
has_custom_altitude = true;
}

int Game_Vehicle::GetScreenY(bool apply_jump) const {
return Game_Character::GetScreenY(apply_jump) - GetAltitude();
return Game_Character::GetScreenY(apply_jump);
}

bool Game_Vehicle::CanLand() const {
Expand Down Expand Up @@ -183,9 +199,16 @@ bool Game_Vehicle::AnimateAscentDescent() {
if (!IsDescending()) {
SetFlying(false);
if (CanLand()) {
has_custom_altitude = false;
Game_Character::SetAltitude(0);
ascent_start_altitude = 0;
ascent_target_altitude = TILE_SIZE;
descent_start_altitude = TILE_SIZE;
SetDefaultDirection();
} else {
int prev_target = descent_start_altitude;
StartAscent();
ascent_target_altitude = prev_target;
}
}
return true;
Expand All @@ -197,6 +220,11 @@ void Game_Vehicle::ForceLand() {
data()->remaining_descent = 0;
data()->remaining_ascent = 0;
data()->flying = 0;
has_custom_altitude = false;
Game_Character::SetAltitude(0);
ascent_start_altitude = 0;
ascent_target_altitude = TILE_SIZE;
descent_start_altitude = TILE_SIZE;
}

void Game_Vehicle::Update() {
Expand Down
12 changes: 11 additions & 1 deletion src/game_vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class Game_Vehicle : public Game_VehicleBase {
bool IsAscending() const;
bool IsDescending() const;
bool IsAscendingOrDescending() const;
int GetAltitude() const;
int GetAltitude() const override;
void SetAltitude(int altitude) override;
bool IsInUse() const;
bool IsAboard() const;
void SyncWithRider(const Game_Character* rider);
Expand All @@ -78,6 +79,8 @@ class Game_Vehicle : public Game_VehicleBase {
void StartDescent();
void SetDefaultDirection();
void ForceLand();
int GetRemainingDescent() const { return data()->remaining_descent; }


/**
* Sets default sprite name. Usually the name of the graphic file.
Expand All @@ -92,6 +95,13 @@ class Game_Vehicle : public Game_VehicleBase {

/** Gets the original sprite graphic index */
int GetOrigSpriteIndex() const;

private:
bool has_custom_altitude = false;
int ascent_start_altitude = 0;
int ascent_target_altitude = TILE_SIZE;
int descent_start_altitude = TILE_SIZE;

};

inline void Game_Vehicle::SetOrigSpriteGraphic(std::string sprite_name, int index) {
Expand Down
48 changes: 36 additions & 12 deletions src/sprite_airshipshadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,27 @@
// Headers
#include "cache.h"
#include "bitmap.h"
#include "game_character.h"
#include "game_map.h"
#include "game_player.h"
#include "game_system.h"
#include "game_vehicle.h"
#include "main_data.h"
#include "player.h"
#include "sprite_airshipshadow.h"
#include "utils.h"
#include <string>

Sprite_AirshipShadow::Sprite_AirshipShadow(int x_offset, int y_offset) :
x_offset(x_offset), y_offset(y_offset) {
SetBitmap(Bitmap::Create(16,16));
Sprite_AirshipShadow(nullptr, x_offset, y_offset) {
}

Sprite_AirshipShadow::Sprite_AirshipShadow(Game_Character* character, int x_offset, int y_offset) :
target_character(character), x_offset(x_offset), y_offset(y_offset) {
SetBitmap(Bitmap::Create(16, 16));
GetBitmap()->SetId("AirshipShadow");

SetOx(TILE_SIZE/2);
SetOx(TILE_SIZE / 2);
SetOy(TILE_SIZE);

RecreateShadow();
Expand All @@ -56,27 +64,43 @@ void Sprite_AirshipShadow::RecreateShadow() {
}

void Sprite_AirshipShadow::Draw(Bitmap &dst) {
Game_Vehicle* airship = Game_Map::GetVehicle(Game_Vehicle::Airship);
const int altitude = airship->GetAltitude();
Game_Character* target = target_character ? target_character : Game_Map::GetVehicle(Game_Vehicle::Airship);
if (!target) {
return;
}
const int altitude = target->GetAltitude();
const int max_altitude = TILE_SIZE;
const double opacity = (double)altitude / max_altitude;
const double opacity = Utils::Clamp((double)altitude / max_altitude, 0.0, 1.0);
SetOpacity(opacity * 255);

SetX(Main_Data::game_player->GetScreenX() + x_offset);
SetY(Main_Data::game_player->GetScreenY() + y_offset + Main_Data::game_player->GetJumpHeight());
SetY(Main_Data::game_player->GetScreenY(false) + y_offset);

Sprite::Draw(dst);
}

void Sprite_AirshipShadow::Update() {
if (!Main_Data::game_player->InAirship()) {
Game_Character* target = target_character ? target_character : Game_Map::GetVehicle(Game_Vehicle::Airship);
if (!target) {
SetVisible(false);
return;
}
SetVisible(true);

Game_Vehicle* airship = Game_Map::GetVehicle(Game_Vehicle::Airship);
const int altitude = target->GetAltitude();
bool show = false;
if (target_character) {
show = target->IsVisible() && altitude > 0;
} else {
auto* airship = static_cast<Game_Vehicle*>(target);
show = Main_Data::game_player->InAirship() || (airship->IsInCurrentMap() && altitude > 0);
}

if (!show) {
SetVisible(false);
return;
}
SetVisible(true);

// Synchronized with airship priority
SetZ(airship->GetScreenZ(x_offset, y_offset) - 1);
// Synchronized with target priority (drawn directly underneath the character)
SetZ(target->GetScreenZ(x_offset, y_offset) - 1);
}
Loading
Loading