Skip to content
13 changes: 11 additions & 2 deletions src/battle_animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "player.h"
#include "options.h"
#include "drawable_mgr.h"
#include "scene_map.h"
#include "spriteset_map.h"

BattleAnimation::BattleAnimation(const lcf::rpg::Animation& anim, bool only_sound, int cutoff) :
animation(anim), only_sound(only_sound)
Expand Down Expand Up @@ -261,9 +263,16 @@ void BattleAnimationMap::DrawSingle(Bitmap& dst) {
return;
}
const int character_height = 24;
int vertical_center = target.GetScreenY(false, false) - character_height / 2;
int x_off = target.GetScreenX();
int y_off = target.GetScreenY(false, false);
if (Scene::instance->type == Scene::Map) {
x_off += static_cast<Scene_Map*>(Scene::instance.get())->spriteset->GetRenderOx();
y_off += static_cast<Scene_Map*>(Scene::instance.get())->spriteset->GetRenderOy();
}
int vertical_center = y_off - character_height / 2;
int offset = CalculateOffset(animation.position, character_height);
DrawAt(dst, target.GetScreenX(), vertical_center + offset);

DrawAt(dst, x_off, vertical_center + offset);
}

void BattleAnimationMap::FlashTargets(int r, int g, int b, int p) {
Expand Down
49 changes: 45 additions & 4 deletions src/drawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,45 @@ class Drawable {

void SetZ(Z_t z);

/* @return true if this drawable should appear in all scenes */
/** @return true if this drawable should appear in all scenes */
bool IsGlobal() const;

/* @return true if this drawable should appear in all scenes that use shared drawables */
/** @return true if this drawable should appear in all scenes that use shared drawables */
bool IsShared() const;

/* @return true if the drawable is currently visible */
/** @return true if the drawable is currently visible */
bool IsVisible() const;

/**
* Set if the drawable should be visisble
* Set if the drawable should be visible
*
* @param value whether is visible or not.
*/
void SetVisible(bool value);

/** @return x offset for the rendering */
int GetRenderOx() const;

/**
* Sets the rendering offset in x direction. Used for custom resolutions.
* This is not enforced by the Drawable. Drawables must honor this value.
*
* @param offset_x x offset
*/
// FIXME: Currently only used by panorama, sprites and tiles on the map
void SetRenderOx(int offset_x);

/** @return y offset for the rendering */
int GetRenderOy() const;

/**
* Sets the rendering offset in y direction. Used for custom resolutions.
* This is not enforced by the Drawable. Drawables must honor this value.
*
* @param offset_y y offset
*/
void SetRenderOy(int offset_y);

/**
* Converts a RPG Maker map layer value into a EasyRPG priority value.
*
Expand All @@ -93,6 +116,8 @@ class Drawable {
private:
Z_t _z = 0;
Flags _flags = Flags::Default;
int render_ox = 0;
int render_oy = 0;
};

inline Drawable::Flags operator|(Drawable::Flags l, Drawable::Flags r) {
Expand Down Expand Up @@ -137,6 +162,22 @@ inline void Drawable::SetVisible(bool value) {
_flags = value ? _flags & ~Flags::Invisible : _flags | Flags::Invisible;
}

inline int Drawable::GetRenderOx() const {
return render_ox;
}

inline void Drawable::SetRenderOx(int offset_x) {
render_ox = offset_x;
}

inline int Drawable::GetRenderOy() const {
return render_oy;
}

inline void Drawable::SetRenderOy(int offset_y) {
render_oy = offset_y;
}

// Upper 8 bit are reserved for the layer
static constexpr uint64_t z_offset = 64 - 8;

Expand Down
24 changes: 12 additions & 12 deletions src/game_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ int Game_Character::GetScreenX(bool apply_shift) const {
int x = GetSpriteX() / TILE_SIZE - Game_Map::GetDisplayX() / TILE_SIZE + TILE_SIZE;

if (Game_Map::LoopHorizontal()) {
x = Utils::PositiveModulo(x, Game_Map::GetWidth() * TILE_SIZE);
x = Utils::PositiveModulo(x, Game_Map::GetTilesX() * TILE_SIZE);
}
x -= TILE_SIZE / 2;

if (apply_shift) {
x += Game_Map::GetWidth() * TILE_SIZE;
x += Game_Map::GetTilesX() * TILE_SIZE;
}

return x;
Expand All @@ -93,11 +93,11 @@ int Game_Character::GetScreenY(bool apply_shift, bool apply_jump) const {
}

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

if (apply_shift) {
y += Game_Map::GetHeight() * TILE_SIZE;
y += Game_Map::GetTilesY() * TILE_SIZE;
}

return y;
Expand Down Expand Up @@ -699,15 +699,15 @@ bool Game_Character::Jump(int x, int y) {
// Adjust positions for looping maps. jump begin positions
// get set off the edge of the map to preserve direction.
if (Game_Map::LoopHorizontal()
&& (x < 0 || x >= Game_Map::GetWidth()))
&& (x < 0 || x >= Game_Map::GetTilesX()))
{
const auto old_x = x;
x = Game_Map::RoundX(x);
begin_x += x - old_x;
}

if (Game_Map::LoopVertical()
&& (y < 0 || y >= Game_Map::GetHeight()))
&& (y < 0 || y >= Game_Map::GetTilesY()))
{
auto old_y = y;
y = Game_Map::RoundY(y);
Expand All @@ -727,11 +727,11 @@ bool Game_Character::Jump(int x, int y) {
int Game_Character::DistanceXfromPlayer() const {
int sx = GetX() - Main_Data::game_player->GetX();
if (Game_Map::LoopHorizontal()) {
if (std::abs(sx) > Game_Map::GetWidth() / 2) {
if (std::abs(sx) > Game_Map::GetTilesX() / 2) {
if (sx > 0)
sx -= Game_Map::GetWidth();
sx -= Game_Map::GetTilesX();
else
sx += Game_Map::GetWidth();
sx += Game_Map::GetTilesX();
}
}
return sx;
Expand All @@ -740,11 +740,11 @@ int Game_Character::DistanceXfromPlayer() const {
int Game_Character::DistanceYfromPlayer() const {
int sy = GetY() - Main_Data::game_player->GetY();
if (Game_Map::LoopVertical()) {
if (std::abs(sy) > Game_Map::GetHeight() / 2) {
if (std::abs(sy) > Game_Map::GetTilesY() / 2) {
if (sy > 0)
sy -= Game_Map::GetHeight();
sy -= Game_Map::GetTilesY();
else
sy += Game_Map::GetHeight();
sy += Game_Map::GetTilesY();
}
}
return sy;
Expand Down
38 changes: 19 additions & 19 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ static void ClampingAdd(int low, int high, int& acc, int& inc) {
}

void Game_Map::AddScreenX(int& screen_x, int& inc) {
int map_width = GetWidth() * SCREEN_TILE_SIZE;
int map_width = GetTilesX() * SCREEN_TILE_SIZE;
if (LoopHorizontal()) {
screen_x = (screen_x + inc) % map_width;
} else {
Expand All @@ -468,7 +468,7 @@ void Game_Map::AddScreenX(int& screen_x, int& inc) {
}

void Game_Map::AddScreenY(int& screen_y, int& inc) {
int map_height = GetHeight() * SCREEN_TILE_SIZE;
int map_height = GetTilesY() * SCREEN_TILE_SIZE;
if (LoopVertical()) {
screen_y = (screen_y + inc) % map_height;
} else {
Expand All @@ -477,7 +477,7 @@ void Game_Map::AddScreenY(int& screen_y, int& inc) {
}

bool Game_Map::IsValid(int x, int y) {
return (x >= 0 && x < GetWidth() && y >= 0 && y < GetHeight());
return (x >= 0 && x < GetTilesX() && y >= 0 && y < GetTilesY());
}

static int GetPassableMask(int old_x, int old_y, int new_x, int new_y) {
Expand Down Expand Up @@ -673,7 +673,7 @@ bool Game_Map::CanLandAirship(int x, int y) {

const int bit = Passable::Down | Passable::Right | Passable::Left | Passable::Up;

int tile_index = x + y * GetWidth();
int tile_index = x + y * GetTilesX();

if (!IsPassableLowerTile(bit, tile_index)) {
return false;
Expand Down Expand Up @@ -792,7 +792,7 @@ bool Game_Map::IsPassableTile(const Game_Character* self, int bit, int x, int y)
};
}

int tile_index = x + y * GetWidth();
int tile_index = x + y * GetTilesX();
int tile_id = map->upper_layer[tile_index] - BLOCK_F;
tile_id = map_info.upper_tiles[tile_id];

Expand Down Expand Up @@ -825,7 +825,7 @@ int Game_Map::GetBushDepth(int x, int y) {
bool Game_Map::IsCounter(int x, int y) {
if (!Game_Map::IsValid(x, y)) return false;

int const tile_id = map->upper_layer[x + y * GetWidth()];
int const tile_id = map->upper_layer[x + y * GetTilesX()];
if (tile_id < BLOCK_F) return false;
int const index = map_info.upper_tiles[tile_id - BLOCK_F];
return !!(passages_up[index] & Passable::Counter);
Expand Down Expand Up @@ -857,7 +857,7 @@ int Game_Map::GetTerrainTag(int x, int y) {
unsigned chip_index = 0;

if (Game_Map::IsValid(x, y)) {
const auto chip_id = map->lower_layer[x + y * GetWidth()];
const auto chip_id = map->lower_layer[x + y * GetTilesX()];
chip_index = ChipIdToIndex(chip_id);

// Apply tile substitution
Expand Down Expand Up @@ -900,31 +900,31 @@ bool Game_Map::LoopVertical() {

int Game_Map::RoundX(int x, int units) {
if (LoopHorizontal()) {
return Utils::PositiveModulo(x, GetWidth() * units);
return Utils::PositiveModulo(x, GetTilesX() * units);
} else {
return x;
}
}

int Game_Map::RoundY(int y, int units) {
if (LoopVertical()) {
return Utils::PositiveModulo(y, GetHeight() * units);
return Utils::PositiveModulo(y, GetTilesY() * units);
} else {
return y;
}
}

int Game_Map::RoundDx(int dx, int units) {
if (LoopHorizontal()) {
return Utils::PositiveModulo(std::abs(dx), GetWidth() * units) * Utils::Sign(dx);
return Utils::PositiveModulo(std::abs(dx), GetTilesX() * units) * Utils::Sign(dx);
} else {
return dx;
}
}

int Game_Map::RoundDy(int dy, int units) {
if (LoopVertical()) {
return Utils::PositiveModulo(std::abs(dy), GetHeight() * units) * Utils::Sign(dy);
return Utils::PositiveModulo(std::abs(dy), GetTilesY() * units) * Utils::Sign(dy);
} else {
return dy;
}
Expand Down Expand Up @@ -1210,11 +1210,11 @@ void Game_Map::PrintPathToMap() {
Output::Debug("Tree: {}", ss.str());
}

int Game_Map::GetWidth() {
int Game_Map::GetTilesX() {
return map->width;
}

int Game_Map::GetHeight() {
int Game_Map::GetTilesY() {
return map->height;
}

Expand Down Expand Up @@ -1391,7 +1391,7 @@ int Game_Map::GetDisplayX() {
}

void Game_Map::SetPositionX(int x, bool reset_panorama) {
const int map_width = GetWidth() * SCREEN_TILE_SIZE;
const int map_width = GetTilesX() * SCREEN_TILE_SIZE;
if (LoopHorizontal()) {
x = Utils::PositiveModulo(x, map_width);
} else {
Expand All @@ -1413,7 +1413,7 @@ int Game_Map::GetDisplayY() {
}

void Game_Map::SetPositionY(int y, bool reset_panorama) {
const int map_height = GetHeight() * SCREEN_TILE_SIZE;
const int map_height = GetTilesY() * SCREEN_TILE_SIZE;
if (LoopVertical()) {
y = Utils::PositiveModulo(y, map_height);
} else {
Expand Down Expand Up @@ -1738,8 +1738,8 @@ void Game_Map::Parallax::ResetPositionX() {
++tiles_per_screen;
}

if (GetWidth() > tiles_per_screen && parallax_width > screen_width) {
const int w = (GetWidth() - tiles_per_screen) * TILE_SIZE;
if (GetTilesX() > tiles_per_screen && parallax_width > screen_width) {
const int w = (GetTilesX() - tiles_per_screen) * TILE_SIZE;
const int ph = 2 * std::min(w, parallax_width - screen_width) * map_info.position_x / w;
if (Player::IsRPG2k()) {
SetPositionX(ph);
Expand Down Expand Up @@ -1776,8 +1776,8 @@ void Game_Map::Parallax::ResetPositionY() {
++tiles_per_screen;
}

if (GetHeight() > tiles_per_screen && parallax_height > screen_height) {
const int h = (GetHeight() - tiles_per_screen) * TILE_SIZE;
if (GetTilesY() > tiles_per_screen && parallax_height > screen_height) {
const int h = (GetTilesY() - tiles_per_screen) * TILE_SIZE;
const int pv = 2 * std::min(h, parallax_height - screen_height) * map_info.position_y / h;
SetPositionY(pv);
} else {
Expand Down
16 changes: 4 additions & 12 deletions src/game_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,11 @@ namespace Game_Map {
*/
void PrintPathToMap();

/**
* Gets current map width.
*
* @return current map width.
*/
int GetWidth();
/** @return amount of tiles in x direction */
int GetTilesX();

/**
* Gets current map height.
*
* @return current map height.
*/
int GetHeight();
/** @return amount of tiles in y direction */
int GetTilesY();

/** @return original map battle encounter rate steps. */
int GetOriginalEncounterSteps();
Expand Down
4 changes: 2 additions & 2 deletions src/game_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ void Game_Player::UpdateScroll(int amount, bool was_jumping) {
auto dx = (GetX() * SCREEN_TILE_SIZE) - Game_Map::GetPositionX() - GetPanX();
auto dy = (GetY() * SCREEN_TILE_SIZE) - Game_Map::GetPositionY() - GetPanY();

const auto w = Game_Map::GetWidth() * SCREEN_TILE_SIZE;
const auto h = Game_Map::GetHeight() * SCREEN_TILE_SIZE;
const auto w = Game_Map::GetTilesX() * SCREEN_TILE_SIZE;
const auto h = Game_Map::GetTilesY() * SCREEN_TILE_SIZE;

dx = Utils::PositiveModulo(dx + w / 2, w) - w / 2;
dy = Utils::PositiveModulo(dy + h / 2, h) - h / 2;
Expand Down
6 changes: 3 additions & 3 deletions src/plane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ void Plane::Draw(Bitmap& dst) {
BitmapRef source = tone_effect == Tone() ? bitmap : tone_bitmap;

Rect dst_rect = dst.GetRect();
int src_x = -ox;
int src_y = -oy;
int src_x = -ox - GetRenderOx();
int src_y = -oy - GetRenderOy();

// Apply screen shaking
const int shake_x = Main_Data::game_screen->GetShakeOffsetX();
Expand All @@ -60,7 +60,7 @@ void Plane::Draw(Bitmap& dst) {
// Using coordinates where the top-left of the screen is the origin...
// Minimal width is a 20 tile wide map by default, smaller maps are hacked
int bg_x = -Game_Map::GetDisplayX() / TILE_SIZE + shake_x;
int bg_width = std::max(Game_Map::GetWidth() * TILE_SIZE, Player::screen_width);
int bg_width = std::max(Game_Map::GetTilesX() * TILE_SIZE, Player::screen_width);

// Clip the panorama to the screen
if (bg_x < 0) {
Expand Down
Loading