Skip to content

Commit

Permalink
Added support for unit types to have different construction animation…
Browse files Browse the repository at this point in the history
…s depending on whether they are built on top of something or not
  • Loading branch information
Andrettin committed Aug 8, 2022
1 parent 0bc0662 commit 52e716c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
4 changes: 3 additions & 1 deletion src/unit/script_unit_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,9 @@ int CclDefineUnitType(lua_State *l)
}
//Wyrmgus end
} else if (!strcmp(value, "Construction")) {
type->construction = wyrmgus::construction::get(LuaToString(l, -1));
type->construction = construction::get(LuaToString(l, -1));
} else if (!strcmp(value, "OnTopConstruction")) {
type->on_top_construction = construction::get(LuaToString(l, -1));
} else if (!strcmp(value, "DrawLevel")) {
type->draw_level = LuaToNumber(l, -1);
} else if (!strcmp(value, "MaxOnBoard")) {
Expand Down
13 changes: 10 additions & 3 deletions src/unit/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7160,12 +7160,19 @@ const wyrmgus::animation_set *CUnit::get_animation_set() const

const wyrmgus::construction *CUnit::get_construction() const
{
const wyrmgus::unit_type_variation *variation = this->GetVariation();
const unit_type_variation *variation = this->GetVariation();
if (variation != nullptr && variation->get_construction() != nullptr) {
return variation->get_construction();
} else {
return this->Type->get_construction();
}

if (this->Type->get_on_top_construction() != nullptr) {
const on_top_build_restriction *on_top = OnTopDetails(*this->Type, nullptr);
if (on_top != nullptr) {
return this->Type->get_on_top_construction();
}
}

return this->Type->get_construction();
}

const icon *CUnit::get_icon() const
Expand Down
26 changes: 8 additions & 18 deletions src/unit/unit_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,25 +987,15 @@ static void DrawConstruction(const int player, const construction_frame *cframe,
const player_color *player_color = CPlayer::Players[player]->get_player_color();

if (cframe->get_image_type() == construction_image_type::construction) {
const unit_type_variation *variation = unit.GetVariation();
if (variation != nullptr && variation->get_construction() != nullptr) {
const construction *construction = variation->get_construction();
pos.x -= (construction->get_frame_width() * scale_factor).to_int() / 2;
pos.y -= (construction->get_frame_height() * scale_factor).to_int() / 2;
if (frame < 0) {
construction->get_graphics()->DrawPlayerColorFrameClipX(player_color, -frame - 1, pos.x, pos.y, time_of_day, render_commands);
} else {
construction->get_graphics()->DrawPlayerColorFrameClip(player_color, frame, pos.x, pos.y, time_of_day, render_commands);
}
const construction *construction = unit.get_construction();

pos.x -= (construction->get_frame_width() * scale_factor).to_int() / 2;
pos.y -= (construction->get_frame_height() * scale_factor).to_int() / 2;

if (frame < 0) {
construction->get_graphics()->DrawPlayerColorFrameClipX(player_color, -frame - 1, pos.x, pos.y, time_of_day, render_commands);
} else {
const construction *construction = type.get_construction();
pos.x -= (construction->get_frame_width() * scale_factor).to_int() / 2;
pos.y -= (construction->get_frame_height() * scale_factor).to_int() / 2;
if (frame < 0) {
construction->get_graphics()->DrawPlayerColorFrameClipX(player_color, -frame - 1, pos.x, pos.y, time_of_day, render_commands);
} else {
construction->get_graphics()->DrawPlayerColorFrameClip(player_color, frame, pos.x, pos.y, time_of_day, render_commands);
}
construction->get_graphics()->DrawPlayerColorFrameClip(player_color, frame, pos.x, pos.y, time_of_day, render_commands);
}
} else {
//Wyrmgus start
Expand Down
1 change: 1 addition & 0 deletions src/unit/unit_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,7 @@ void unit_type::set_parent(const unit_type *parent_type)
this->box_size = parent_type->box_size;
this->box_offset = parent_type->box_offset;
this->construction = parent_type->construction;
this->on_top_construction = parent_type->on_top_construction;
this->domain = parent_type->domain;
this->Missile.Name = parent_type->Missile.Name;
this->Missile.Missile = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion src/unit/unit_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,8 @@ class unit_type final : public detailed_data_entry, public data_type<unit_type>
private:
unit_type *corpse_type = nullptr; //corpse unit-type

wyrmgus::construction *construction = nullptr; /// What is shown in the construction phase
wyrmgus::construction *construction = nullptr; //what is shown in the construction phase
wyrmgus::construction *on_top_construction = nullptr;

int repair_hp = 0; /// Amount of HP per repair
resource_map<int> repair_costs; /// How much it costs to repair
Expand Down

0 comments on commit 52e716c

Please sign in to comment.