Skip to content

Commit

Permalink
Add unit promotion indicators
Browse files Browse the repository at this point in the history
Also make units Look() on promotion
  • Loading branch information
ZivDero committed Nov 4, 2024
1 parent 2f8f47b commit c6dab3e
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,5 @@ This page lists all the individual contributions to the project by their author.
- Fix a bug where AI Triggers' `MultiSide` wouldn't correctly consider all houses.
- Fix a bug where newly created objects wouldn't reveal shroud for allies with `AllyReveal=yes`.
- Fix a bug where mission `Ambush` wouldn't work correctly.
- Add unit promotion sounds, EVA and flashing.

13 changes: 13 additions & 0 deletions docs/User-Interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ TextLabelOutline=yes ; boolean, should the text be drawn with a b
TextLabelBackgroundTransparency=50 ; unsigned integer, the transparency of the text background fill. Ranged between 0 and 100.
```

### Unit Promotion Indicators

- In Red Alert 2, unit promotion is indicated by sounds, flashing and an EVA voiceline. Vinifera ports this behavior to Tiberian Sun.

In `RULES.INI`:
```ini
[AudioVisual]
UpgradeVeteranSound= ; VocType, the sound played when a unit is promoited to veteran status.
UpgradeEliteSound= ; VocType, the sound played when a unit is promoted to elite status.
VoxUnitPromoted= ; VoxType, the EVA line played when a unit is promoted.
EliteFlashTimer=0 ; integer, the number of frames that a newly elite unit will flash for.
```

### Unit Health Bar

- Vinifera allows customizing the position of the heath bar.
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ Vanilla fixes:
- Fix a bug where AI Triggers' `MultiSide` wouldn't correctly consider all houses (by ZivDero)
- Fix a bug where newly created objects wouldn't reveal shroud for allies with `AllyReveal=yes` (by ZivDero)
- Fix a bug where mission `Ambush` wouldn't work correctly (by ZivDero)
- Add unit promotion sounds, EVA and flashing (by ZivDero)

</details>

11 changes: 10 additions & 1 deletion src/extensions/rules/rulesext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ RulesClassExtension::RulesClassExtension(const RulesClass *this_ptr) :
IceStrength(0),
WeedPipIndex(1),
MaxFreeRefineryDistanceBias(16),
BaseUnit()
BaseUnit(),
UpgradeVeteranSound(VOC_NONE),
UpgradeEliteSound(VOC_NONE),
VoxUnitPromoted(VOX_NONE),
EliteFlashTimer(0)
{
//if (this_ptr) EXT_DEBUG_TRACE("RulesClassExtension::RulesClassExtension - 0x%08X\n", (uintptr_t)(ThisPtr));

Expand Down Expand Up @@ -658,6 +662,11 @@ bool RulesClassExtension::AudioVisual(CCINIClass &ini)
for (int i = 0; i < MaxPips.Count(); i++)
DEBUG_INFO("%d", MaxPips[i]);

UpgradeVeteranSound = ini.Get_VocType(AUDIOVISUAL, "UpgradeVeteranSound", UpgradeVeteranSound);
UpgradeEliteSound = ini.Get_VocType(AUDIOVISUAL, "UpgradeEliteSound", UpgradeEliteSound);
VoxUnitPromoted = ini.Get_VoxType(AUDIOVISUAL, "VoxUnitPromoted", VoxUnitPromoted);
EliteFlashTimer = ini.Get_Int(AUDIOVISUAL, "EliteFlashTimer", EliteFlashTimer);

return true;
}

Expand Down
16 changes: 16 additions & 0 deletions src/extensions/rules/rulesext.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,20 @@ class RulesClassExtension final : public GlobalExtensionClass<RulesClass>
* to allow customizing AI difficulties without affecting the human player.
*/
DifficultyClass DiffHuman;

/**
* Sounds played when a unit is promoted.
*/
VocType UpgradeVeteranSound;
VocType UpgradeEliteSound;

/**
* EVA announcement when a unit is promoted.
*/
VoxType VoxUnitPromoted;

/**
* The number of frames that a newly elite unit will flash for.
*/
int EliteFlashTimer;
};
3 changes: 2 additions & 1 deletion src/extensions/techno/technoext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ TechnoClassExtension::TechnoClassExtension(const TechnoClass *this_ptr) :
ElectricBolt(nullptr),
Storage(Tiberiums.Count()),
SpawnManager(nullptr),
SpawnOwner(nullptr)
SpawnOwner(nullptr),
LastVeterancy(VETERANCY_NONE)
{
//if (this_ptr) EXT_DEBUG_TRACE("TechnoClassExtension::TechnoClassExtension - Name: %s (0x%08X)\n", Name(), (uintptr_t)(This()));

Expand Down
6 changes: 6 additions & 0 deletions src/extensions/techno/technoext.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,10 @@ class TechnoClassExtension : public RadioClassExtension
* The object that spawned this object.
*/
TechnoClass* SpawnOwner;

/**
* The veternacy rank of this unit last time it performed its AI() function.
* Used to determine when a unit has ranked up.
*/
VeterancyRankType LastVeterancy;
};
51 changes: 49 additions & 2 deletions src/extensions/techno/technoext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#include "utracker.h"
#include "aircraft.h"
#include "spawner.h"
#include "vox.h"


/**
Expand Down Expand Up @@ -592,8 +593,7 @@ void TechnoClassExt::_Stun()


/**
* Wrapper function to patch the call in TechnoClass::AI to call
* SpawnManagerClass::AI.
* Wrapper function to insert new things into TechnoClass::AI.
*
* @author: ZivDero
*/
Expand All @@ -603,8 +603,55 @@ void TechnoClassExt::_Mission_AI()

const auto extension = Extension::Fetch<TechnoClassExtension>(this);

/**
* Execute SpawnManager AI.
*/
if (extension->SpawnManager)
extension->SpawnManager->AI();

/**
* Check if the unit has been promoted.
*/
if (extension->LastVeterancy != Veterancy.Get_Rank())
{
if (extension->LastVeterancy != VETERANCY_NONE)
{
if (Veterancy.Get_Rank() == RANK_ELITE)
{
/**
* Play the promotion sound and voice line.
*/
if (House->Is_Player_Control())
{
Sound_Effect(RuleExtension->UpgradeEliteSound, Coord);
Speak(RuleExtension->VoxUnitPromoted);
}

/**
* Elite units also flash for a while.
*/
FlashCount = RuleExtension->EliteFlashTimer;
}
else if (Veterancy.Get_Rank() == RANK_VETERAN)
{
/**
* Play the promotion sound and voice line.
*/
if (House->Is_Player_Control())
{
Sound_Effect(RuleExtension->UpgradeVeteranSound, Coord);
Speak(RuleExtension->VoxUnitPromoted);
}
}

/**
* Force the unit to look in case its range has been upgraded.
*/
Look();
}

extension->LastVeterancy = Veterancy.Get_Rank();
}
}


Expand Down

0 comments on commit c6dab3e

Please sign in to comment.