Skip to content

Commit

Permalink
Made changes necessary for the goblin shield to be drawn correctly as…
Browse files Browse the repository at this point in the history
… a layer
  • Loading branch information
Andrettin committed Dec 21, 2015
1 parent fc5d0e0 commit 9a1f4f7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/include/unittype.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ class CUnitType
int Upkeep; /// Gold upkeep (for grand strategy mode)
int ItemClass; /// Item class (if the unit type is an item)
std::vector<int> WeaponClasses; /// Weapon classes that the unit type can use (if the unit type uses a weapon)
bool InvertedSoutheastArms; /// Whether the arms are inverted for the southeast/southwest graphics
//Wyrmgus end
PixelPos MissileOffsets[UnitSides][MaxAttackPos]; /// Attack offsets for missiles

Expand Down
3 changes: 3 additions & 0 deletions src/unit/script_unittype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ static int CclDefineUnitType(lua_State *l)
type->Sound = parent_type->Sound;
type->NumDirections = parent_type->NumDirections;
type->NeutralMinimapColorRGB = parent_type->NeutralMinimapColorRGB;
type->InvertedSoutheastArms = parent_type->InvertedSoutheastArms;
if (parent_type->CanCastSpell) {
type->CanCastSpell = new char[SpellTypeTable.size()];
memset(type->CanCastSpell, 0, SpellTypeTable.size() * sizeof(char));
Expand Down Expand Up @@ -1867,6 +1868,8 @@ static int CclDefineUnitType(lua_State *l)
LuaError(l, "incorrect weapon class");
}
}
} else if (!strcmp(value, "InvertedSoutheastArms")) {
type->InvertedSoutheastArms = LuaToBoolean(l, -1);
//Wyrmgus end
} else {
int index = UnitTypeVar.VariableNameLookup[value];
Expand Down
38 changes: 32 additions & 6 deletions src/unit/unit_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,16 +1192,29 @@ void CUnit::Draw(const CViewport &vp) const
DrawPlayerColorOverlay(*type, this->GetLayerSprite(BackpackImageLayer), player, this->GetLayerFrame(BackpackImageLayer, frame), screenPos + this->GetLayerOffset(BackpackImageLayer, frame));
}

//draw the left arm before the body if not facing south (or the still frame, since that also faces south)
if ((this->Direction != LookingS || this->CurrentAction() == UnitActionDie) && frame != type->StillFrame) {
//draw the left arm before the body if not facing south (or the still frame, since that also faces south); if the position of the arms in the southeast frame is inverted, don't draw the left arm yet either
if (
(this->Direction != LookingS || this->CurrentAction() == UnitActionDie)
&& frame != type->StillFrame
&& !(
type->InvertedSoutheastArms
&& (this->Direction == LookingSE || this->Direction == LookingSW || (this->Direction == LookingS && this->CurrentAction() == UnitActionDie))
)
) {
//draw the shield before the left arm if not facing south
DrawPlayerColorOverlay(*type, this->GetLayerSprite(ShieldImageLayer), player, this->GetLayerFrame(ShieldImageLayer, frame), screenPos + this->GetLayerOffset(ShieldImageLayer, frame));

DrawPlayerColorOverlay(*type, this->GetLayerSprite(LeftArmImageLayer), player, this->GetLayerFrame(LeftArmImageLayer, frame), screenPos + this->GetLayerOffset(LeftArmImageLayer, frame));
}

//draw the right arm before the body if facing north
if (this->Direction == LookingN && this->CurrentAction() != UnitActionDie) {
//draw the right arm before the body if facing north, or if facing southeast/southwest and the arms are inverted for that direction
if (
(this->Direction == LookingN && this->CurrentAction() != UnitActionDie)
|| (
type->InvertedSoutheastArms
&& (this->Direction == LookingSE || this->Direction == LookingSW || (this->Direction == LookingS && this->CurrentAction() == UnitActionDie))
)
) {
DrawPlayerColorOverlay(*type, this->GetLayerSprite(WeaponImageLayer), player, this->GetLayerFrame(WeaponImageLayer, frame), screenPos + this->GetLayerOffset(WeaponImageLayer, frame));
DrawPlayerColorOverlay(*type, this->GetLayerSprite(RightArmImageLayer), player, this->GetLayerFrame(RightArmImageLayer, frame), screenPos + this->GetLayerOffset(RightArmImageLayer, frame));
}
Expand Down Expand Up @@ -1286,14 +1299,27 @@ void CUnit::Draw(const CViewport &vp) const
DrawPlayerColorOverlay(*type, this->GetLayerSprite(BootsImageLayer), player, this->GetLayerFrame(BootsImageLayer, frame), screenPos + this->GetLayerOffset(BootsImageLayer, frame));

//draw the left arm just after the body if facing south
if ((this->Direction == LookingS && this->CurrentAction() != UnitActionDie) || frame == type->StillFrame) {
if (
(this->Direction == LookingS && this->CurrentAction() != UnitActionDie)
|| frame == type->StillFrame
|| (
type->InvertedSoutheastArms
&& (this->Direction == LookingSE || this->Direction == LookingSW || (this->Direction == LookingS && this->CurrentAction() == UnitActionDie))
)
) {
DrawPlayerColorOverlay(*type, this->GetLayerSprite(LeftArmImageLayer), player, this->GetLayerFrame(LeftArmImageLayer, frame), screenPos + this->GetLayerOffset(LeftArmImageLayer, frame));
DrawPlayerColorOverlay(*type, this->GetLayerSprite(ClothingLeftArmImageLayer), player, this->GetLayerFrame(ClothingLeftArmImageLayer, frame), screenPos + this->GetLayerOffset(ClothingLeftArmImageLayer, frame));
DrawPlayerColorOverlay(*type, this->GetLayerSprite(ShieldImageLayer), player, this->GetLayerFrame(ShieldImageLayer, frame), screenPos + this->GetLayerOffset(ShieldImageLayer, frame));
}

//draw the right arm just after the body if not facing north
if (this->Direction != LookingN || this->CurrentAction() == UnitActionDie) {
if (
(this->Direction != LookingN || this->CurrentAction() == UnitActionDie)
&& !(
type->InvertedSoutheastArms
&& (this->Direction == LookingSE || this->Direction == LookingSW || (this->Direction == LookingS && this->CurrentAction() == UnitActionDie))
)
) {
DrawPlayerColorOverlay(*type, this->GetLayerSprite(WeaponImageLayer), player, this->GetLayerFrame(WeaponImageLayer, frame), screenPos + this->GetLayerOffset(WeaponImageLayer, frame));
DrawPlayerColorOverlay(*type, this->GetLayerSprite(RightArmImageLayer), player, this->GetLayerFrame(RightArmImageLayer, frame), screenPos + this->GetLayerOffset(RightArmImageLayer, frame));
DrawPlayerColorOverlay(*type, this->GetLayerSprite(ClothingRightArmImageLayer), player, this->GetLayerFrame(ClothingRightArmImageLayer, frame), screenPos + this->GetLayerOffset(ClothingRightArmImageLayer, frame));
Expand Down
2 changes: 1 addition & 1 deletion src/unit/unittype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ CUnitType::CUnitType() :
Slot(0), Width(0), Height(0), OffsetX(0), OffsetY(0), DrawLevel(0),
ShadowWidth(0), ShadowHeight(0), ShadowOffsetX(0), ShadowOffsetY(0),
//Wyrmgus start
TechnologyPointCost(0), Upkeep(0), TrainQuantity(0), ItemClass(-1),
TechnologyPointCost(0), Upkeep(0), TrainQuantity(0), ItemClass(-1), InvertedSoutheastArms(false),
//Wyrmgus end
Animations(NULL), StillFrame(0),
DeathExplosion(NULL), OnHit(NULL), OnEachCycle(NULL), OnEachSecond(NULL), OnInit(NULL),
Expand Down

0 comments on commit 9a1f4f7

Please sign in to comment.