-
Notifications
You must be signed in to change notification settings - Fork 1
/
AAIUnitStatistics.cpp
85 lines (73 loc) · 3.35 KB
/
AAIUnitStatistics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// -------------------------------------------------------------------------
// AAI
//
// A skirmish AI for the Spring engine.
// Copyright Alexander Seizinger
//
// Released under GPL license: see LICENSE.html for more information.
// -------------------------------------------------------------------------
#include "AAIUnitStatistics.h"
AAIUnitStatistics::AAIUnitStatistics()
{
m_unitCostStatistics.resize( AAIUnitCategory::numberOfUnitCategories );
m_unitBuildtimeStatistics.resize( AAIUnitCategory::numberOfUnitCategories );
m_unitPrimaryAbilityStatistics.resize( AAIUnitCategory::numberOfUnitCategories );
m_unitSecondaryAbilityStatistics.resize( AAIUnitCategory::numberOfUnitCategories );
};
AAIUnitStatistics::~AAIUnitStatistics()
{
m_unitCostStatistics.clear();
m_unitBuildtimeStatistics.clear();
m_unitPrimaryAbilityStatistics.clear();
m_unitSecondaryAbilityStatistics.clear();
};
void AAIUnitStatistics::Init(const std::vector<const springLegacyAI::UnitDef*>& unitDefs, const std::vector<UnitTypeProperties>& unitProperties, const std::vector< std::list<UnitDefId> >& unitsInCategory, const std::vector< std::list<UnitDefId> >& unitsInCombatCategory)
{
//-----------------------------------------------------------------------------------------------------------------
// calculate unit category statistics
//-----------------------------------------------------------------------------------------------------------------
for(uint32_t cat = 0; cat < AAIUnitCategory::numberOfUnitCategories; ++cat)
{
for(auto unitDefId : unitsInCategory[cat])
{
m_unitBuildtimeStatistics[cat].AddValue( unitProperties[unitDefId.id].m_buildtime );
m_unitCostStatistics[cat].AddValue( unitProperties[unitDefId.id].m_totalCost );
m_unitPrimaryAbilityStatistics[cat].AddValue( unitProperties[unitDefId.id].m_primaryAbility );
m_unitSecondaryAbilityStatistics[cat].AddValue( unitProperties[unitDefId.id].m_secondaryAbility );
}
// calculate average values after last value has been added
m_unitBuildtimeStatistics[cat].Finalize();
m_unitCostStatistics[cat].Finalize();
m_unitPrimaryAbilityStatistics[cat].Finalize();
m_unitSecondaryAbilityStatistics[cat].Finalize();
}
m_sensorStatistics.Init(unitDefs, unitProperties, unitsInCategory);
}
void SensorStatistics::Init(const std::vector<const springLegacyAI::UnitDef*>& unitDefs, const std::vector<UnitTypeProperties>& unitProperties, const std::vector< std::list<UnitDefId> >& unitsInCategory)
{
const int index = AAIUnitCategory(EUnitCategory::STATIC_SENSOR).GetArrayIndex();
for(auto defId = unitsInCategory[index].begin(); defId != unitsInCategory[index].end(); ++defId)
{
if(unitProperties[defId->id].m_unitType.IsRadar())
{
m_radarRanges.AddValue( unitDefs[defId->id]->radarRadius );
m_radarCosts.AddValue( unitProperties[defId->id].m_totalCost );
}
if(unitProperties[defId->id].m_unitType.IsSonar())
{
m_sonarRanges.AddValue( unitDefs[defId->id]->sonarRadius );
m_sonarCosts.AddValue( unitProperties[defId->id].m_totalCost );
}
if(unitProperties[defId->id].m_unitType.IsSeismicDetector())
{
m_seismicRanges.AddValue( unitDefs[defId->id]->seismicRadius );
m_seismicCosts.AddValue( unitProperties[defId->id].m_totalCost );
}
}
m_radarRanges.Finalize();
m_sonarRanges.Finalize();
m_seismicRanges.Finalize();
m_radarCosts.Finalize();
m_sonarCosts.Finalize();
m_seismicCosts.Finalize();
}