Skip to content

Commit

Permalink
Some improvements to the hero code
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrettin committed Dec 17, 2015
1 parent 5e1a3de commit 3c00f0b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/include/unittype.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ class CUnitType
bool CanSelect(GroupSelectionMode mode = SELECTABLE_BY_RECTANGLE_ONLY) const;

//Wyrmgus start
int GetAvailableLevelUpUpgrades() const;
VariationInfo *GetDefaultVariation(CPlayer &player) const;
std::string GetDefaultName(CPlayer &player) const;
CPlayerColorGraphic *GetDefaultLayerSprite(CPlayer &player, int image_layer) const;
Expand Down
53 changes: 51 additions & 2 deletions src/unit/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
//Wyrmgus end
#include "game.h"
#include "editor.h"
//Wyrmgus start
#include "grand_strategy.h"
//Wyrmgus end
#include "interface.h"
//Wyrmgus start
#include "item.h"
Expand Down Expand Up @@ -663,8 +666,43 @@ void CUnit::Retrain()
}
}

std::string unit_name = GetMessageName();

//now, revert the unit's type to the level 1 one
while (this->Type->Stats[this->Player->Index].Variables[LEVEL_INDEX].Value > 1) {
bool found_previous_unit_type = false;
for (size_t i = 0; i != UnitTypes.size(); ++i) {
if (Character != NULL && Character->ForbiddenUpgrades[i]) {
continue;
}
for (size_t j = 0; j != AiHelpers.ExperienceUpgrades[i].size(); ++j) {
if (AiHelpers.ExperienceUpgrades[i][j] == this->Type) {
this->Variable[LEVELUP_INDEX].Value += 1;
TransformUnitIntoType(*this, *UnitTypes[i]);
if (!IsNetworkGame() && Character != NULL && Character->Persistent && Player->AiEnabled == false) { //save the unit-type experience upgrade for persistent characters
if (Character->Type->Slot != i) {
Character->Type = const_cast<CUnitType *>(&(*UnitTypes[i]));
if (GrandStrategy) { //also update the corresponding grand strategy hero, if in grand strategy mode
CGrandStrategyHero *hero = GrandStrategyGame.GetHero(Character->GetFullName());
if (hero) {
hero->SetType(i);
}
}
SaveHero(Character);
}
}
found_previous_unit_type = true;
break;
}
}
if (found_previous_unit_type) {
break;
}
}
}

if (this->Player == ThisPlayer) {
this->Player->Notify(NotifyGreen, this->tilePos, _("%s has retrained."), GetMessageName().c_str());
this->Player->Notify(NotifyGreen, this->tilePos, _("%s's level-up choices have been reset."), unit_name.c_str());
}
}

Expand Down Expand Up @@ -3235,15 +3273,26 @@ PixelPos CUnit::GetMapPixelPosCenter() const
int CUnit::GetAvailableLevelUpUpgrades(bool only_units) const
{
int value = 0;
int upgrade_value = 0;

if (AiHelpers.ExperienceUpgrades.size() > Type->Slot) {
for (size_t i = 0; i != AiHelpers.ExperienceUpgrades[Type->Slot].size(); ++i) {
if (Character == NULL || !Character->ForbiddenUpgrades[AiHelpers.ExperienceUpgrades[Type->Slot][i]->Slot]) {
value += 1;
int local_upgrade_value = 1;

if (!only_units) {
local_upgrade_value += AiHelpers.ExperienceUpgrades[Type->Slot][i]->GetAvailableLevelUpUpgrades();
}

if (local_upgrade_value > upgrade_value) {
upgrade_value = local_upgrade_value;
}
}
}
}

value += upgrade_value;

if (!only_units && AiHelpers.LearnableAbilities.size() > Type->Slot) {
for (size_t i = 0; i != AiHelpers.LearnableAbilities[Type->Slot].size(); ++i) {
if (!IndividualUpgrades[AiHelpers.LearnableAbilities[Type->Slot][i]->ID]) {
Expand Down
31 changes: 31 additions & 0 deletions src/unit/unittype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

#include "unittype.h"

//Wyrmgus start
#include "../ai/ai_local.h" //for using AiHelpers
//Wyrmgus end
#include "animation.h"
#include "animation/animation_exactframe.h"
#include "animation/animation_frame.h"
Expand Down Expand Up @@ -726,6 +729,34 @@ bool CUnitType::CanSelect(GroupSelectionMode mode) const
}

//Wyrmgus start
int CUnitType::GetAvailableLevelUpUpgrades() const
{
int value = 0;
int upgrade_value = 0;

if (AiHelpers.ExperienceUpgrades.size() > this->Slot) {
for (size_t i = 0; i != AiHelpers.ExperienceUpgrades[this->Slot].size(); ++i) {
int local_upgrade_value = 1;

local_upgrade_value += AiHelpers.ExperienceUpgrades[this->Slot][i]->GetAvailableLevelUpUpgrades();

if (local_upgrade_value > upgrade_value) {
upgrade_value = local_upgrade_value;
}
}
}

value += upgrade_value;

if (AiHelpers.LearnableAbilities.size() > this->Slot) {
for (size_t i = 0; i != AiHelpers.LearnableAbilities[this->Slot].size(); ++i) {
value += 1;
}
}

return value;
}

VariationInfo *CUnitType::GetDefaultVariation(CPlayer &player) const
{
for (int i = 0; i < VariationMax; ++i) {
Expand Down

0 comments on commit 3c00f0b

Please sign in to comment.