Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experience warhead implementation #1147

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 12 additions & 0 deletions src/Ext/WarheadType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) {
this->SplashList_PickRandom.Read(exINI, pSection, "SplashList.PickRandom");
this->RemoveDisguise.Read(exINI, pSection, "RemoveDisguise");
this->RemoveMindControl.Read(exINI, pSection, "RemoveMindControl");

this->Experience_GivenFlat.Read(exINI, pSection, "Experience.GivenFlat");
this->Experience_GivenPercent.Read(exINI, pSection, "Experience.GivenPercent");
this->Experience_Transfer.Read(exINI, pSection, "Experience.Transfer");
this->Experience_FirerGetsExp.Read(exINI, pSection, "Experience.FirerGetsExp");
this->Experience_CalculatePercentFromFirer.Read(exINI, pSection, "Experience.CalculatePercentFromFirer");

// Ares tags
// http://ares-developers.github.io/Ares-docs/new/warheads/general.html
Expand All @@ -65,6 +71,12 @@ void WarheadTypeExt::ExtData::Serialize(T& Stm) {
.Process(this->RemoveDisguise)
.Process(this->RemoveMindControl)

.Process(this->Experience_GivenFlat)
.Process(this->Experience_GivenPercent)
.Process(this->Experience_Transfer)
.Process(this->Experience_FirerGetsExp)
.Process(this->Experience_CalculatePercentFromFirer)

// Ares tags
.Process(this->AffectsEnemies)
.Process(this->AffectsOwner)
Expand Down
14 changes: 12 additions & 2 deletions src/Ext/WarheadType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ class WarheadTypeExt
Valueable<bool> SplashList_PickRandom;
Valueable<bool> RemoveDisguise;
Valueable<bool> RemoveMindControl;
Valueable<int> Experience_GivenFlat;
Valueable<double> Experience_GivenPercent;
Valueable<bool> Experience_Transfer;
Valueable<bool> Experience_FirerGetsExp;
Valueable<bool> Experience_CalculatePercentFromFirer;

// Ares tags
// http://ares-developers.github.io/Ares-docs/new/warheads/general.html
Valueable<bool> AffectsEnemies;
Valueable<bool> AffectsOwner;

Valueable<bool> AffectsOwner;

ExtData(WarheadTypeClass* OwnerObject) : Extension<WarheadTypeClass>(OwnerObject),
SpySat(false),
Expand All @@ -36,6 +40,11 @@ class WarheadTypeExt
SplashList_PickRandom(false),
RemoveDisguise(false),
RemoveMindControl(false),
Experience_GivenFlat(0),
Experience_GivenPercent(0.0),
Experience_Transfer(false),
Experience_FirerGetsExp(false),
Experience_CalculatePercentFromFirer(false),

AffectsEnemies(true),
AffectsOwner(OwnerObject->AffectsAllies)
Expand All @@ -45,6 +54,7 @@ class WarheadTypeExt

void ApplyRemoveDisguiseToInf(HouseClass* pHouse, TechnoClass* pTarget);
void ApplyRemoveMindControl(HouseClass* pHouse, TechnoClass* pTarget);
void ApplyModifyExperience(TechnoClass* pTarget, TechnoClass* pOwner);
public:
void Detonate(TechnoClass* pOwner, HouseClass* pHouse, BulletClass* pBullet, CoordStruct coords);
bool CanTargetHouse(HouseClass* pHouse, TechnoClass* pTechno);
Expand Down
84 changes: 81 additions & 3 deletions src/Ext/WarheadType/Detonate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ void WarheadTypeExt::ExtData::Detonate(TechnoClass* pOwner, HouseClass* pHouse,
// List all Warheads here that respect CellSpread
const bool isCellSpreadWarhead =
this->RemoveDisguise ||
this->RemoveMindControl;
this->RemoveMindControl ||
this->Experience_GivenFlat ||
this->Experience_GivenPercent;

const float cellSpread = this->OwnerObject()->CellSpread;
if (cellSpread && isCellSpreadWarhead) {
auto items = Helpers::Alex::getCellSpreadItems(coords, cellSpread, true);
for (auto pTarget : items) {
this->DetonateOnOneUnit(pHouse, pTarget);
this->DetonateOnOneUnit(pHouse, pTarget, pOwner);
}
}
else if (pBullet && isCellSpreadWarhead) {
if (auto pTarget = abstract_cast<TechnoClass*>(pBullet->Target)) {
this->DetonateOnOneUnit(pHouse, pTarget);
this->DetonateOnOneUnit(pHouse, pTarget, pOwner);
}
}
}
Expand All @@ -68,6 +70,10 @@ void WarheadTypeExt::ExtData::DetonateOnOneUnit(HouseClass* pHouse, TechnoClass*
if (this->RemoveMindControl) {
this->ApplyRemoveMindControl(pHouse, pTarget);
}

if (this->Experience_GivenFlat || this->Experience_GivenPercent) {
this->ApplyModifyExperience(pTarget, pOwner);
}
}

void WarheadTypeExt::ExtData::ApplyRemoveMindControl(HouseClass* pHouse, TechnoClass* pTarget)
Expand All @@ -89,3 +95,75 @@ void WarheadTypeExt::ExtData::ApplyRemoveDisguiseToInf(HouseClass* pHouse, Techn
}
}
}

// Add or substract experience for real
int AddExpCustom(VeterancyStruct* vstruct, int ownerCost, int victimCost) {
double toBeAdded = (double)victimCost
/ (ownerCost * RulesClass::Instance->VeteranRatio);
// Used in experience transfer to get the actual amount carried
int transffered = (int)(Math::min(vstruct->Veterancy, abs(toBeAdded))
* (ownerCost * RulesClass::Instance->VeteranRatio));
if (victimCost < 0 && transffered <= 0.0) {
vstruct->Reset();
transffered = 0;
}
else {
vstruct->Add(toBeAdded);
}
return transffered;
}

// General function handling experience warhead behaviour
void WarheadTypeExt::ExtData::ApplyModifyExperience(TechnoClass* pTarget, TechnoClass* pOwner) {

bool expTransfer = this->Experience_Transfer;
bool expInvertDirection = this->Experience_FirerGetsExp;
bool expPercFromFirer = this->Experience_CalculatePercentFromFirer;
auto const pTargetTechno = (pTarget) ? pTarget->GetTechnoType() : nullptr;
auto const pOwnerTechno = (pOwner) ? pOwner->GetTechnoType() : nullptr;

int expGain = 0;
// Percent experience gain
if (this->Experience_GivenPercent) {
// Percent from bullet source
if (expPercFromFirer && pOwnerTechno)
expGain = (int)((pOwnerTechno->GetActualCost(pOwner->Owner) * this->Experience_GivenPercent));
// Percent from bullet target
else if (!expPercFromFirer && pTargetTechno)
expGain = (int)(pTargetTechno->GetActualCost(pTarget->Owner) * this->Experience_GivenPercent);
else return;
}
// Flat gain
else {
expGain = this->Experience_GivenFlat;
}

// Exp Transfer
if (pOwner && pTarget) {
if (expTransfer && !expInvertDirection) {
// Transfer from Source to Target
int diff = AddExpCustom(&pOwner->Veterancy,
pOwnerTechno->GetActualCost(pOwner->Owner), -expGain);
AddExpCustom(&pTarget->Veterancy,
pTargetTechno->GetActualCost(pTarget->Owner), diff);
}
else if (expTransfer && expInvertDirection) {
// Transfer from Target to Source
int diff = AddExpCustom(&pTarget->Veterancy,
pTargetTechno->GetActualCost(pTarget->Owner), -expGain);
AddExpCustom(&pOwner->Veterancy,
pOwnerTechno->GetActualCost(pOwner->Owner), diff);
}
}

if (!expTransfer && expInvertDirection && pOwner) {
// Give Source
AddExpCustom(&pOwner->Veterancy,
pOwnerTechno->GetActualCost(pOwner->Owner), expGain);
}
else if (!expTransfer && !expInvertDirection && pTarget) {
// Give Target
AddExpCustom(&pTarget->Veterancy,
pTargetTechno->GetActualCost(pTarget->Owner), expGain);
}
}