Use more CUnitType& instead of CUnitType*.
Add some Assert on unitType.
This commit is contained in:
parent
b79c7732fd
commit
48e338c83b
7 changed files with 19 additions and 18 deletions
|
@ -120,10 +120,10 @@ void AiResetUnitTypeEquiv()
|
|||
** @param a the first unittype
|
||||
** @param b the second unittype
|
||||
*/
|
||||
void AiNewUnitTypeEquiv(CUnitType *a, CUnitType *b)
|
||||
void AiNewUnitTypeEquiv(const CUnitType &a, const CUnitType &b)
|
||||
{
|
||||
int find = UnitTypeEquivs[a->Slot];
|
||||
int replace = UnitTypeEquivs[b->Slot];
|
||||
int find = UnitTypeEquivs[a.Slot];
|
||||
int replace = UnitTypeEquivs[b.Slot];
|
||||
|
||||
// Always record equivalences with the lowest unittype.
|
||||
if (find < replace) {
|
||||
|
@ -226,7 +226,7 @@ void AiForce::CountTypes(unsigned int *counter, const size_t len)
|
|||
**
|
||||
** @return True if it fits, false otherwise.
|
||||
*/
|
||||
bool AiForce::IsBelongsTo(const CUnitType *type)
|
||||
bool AiForce::IsBelongsTo(const CUnitType &type)
|
||||
{
|
||||
bool flag = false;
|
||||
unsigned int counter[UnitTypeMax + 1];
|
||||
|
@ -241,7 +241,7 @@ bool AiForce::IsBelongsTo(const CUnitType *type)
|
|||
const int slot = aitype.Type->Slot;
|
||||
|
||||
if (counter[slot] < aitype.Want) {
|
||||
if (UnitTypeEquivs[type->Slot] == slot) {
|
||||
if (UnitTypeEquivs[type.Slot] == slot) {
|
||||
if (counter[slot] < aitype.Want - 1) {
|
||||
Completed = false;
|
||||
}
|
||||
|
@ -465,7 +465,7 @@ bool AiForceManager::Assign(CUnit &unit)
|
|||
if (force.IsAttacking()) {
|
||||
continue;
|
||||
}
|
||||
if (force.IsBelongsTo(unit.Type)) {
|
||||
if (force.IsBelongsTo(*unit.Type)) {
|
||||
force.Insert(unit);
|
||||
unit.GroupId = i + 1;
|
||||
return true;
|
||||
|
|
|
@ -158,7 +158,7 @@ public:
|
|||
|
||||
private:
|
||||
void CountTypes(unsigned int *counter, const size_t len);
|
||||
bool IsBelongsTo(const CUnitType *type);
|
||||
bool IsBelongsTo(const CUnitType &type);
|
||||
void Insert(CUnit &unit);
|
||||
|
||||
void Update();
|
||||
|
@ -388,7 +388,7 @@ extern void AiResourceManager();
|
|||
/// Ask the ai to explore around pos
|
||||
extern void AiExplore(const Vec2i &pos, int exploreMask);
|
||||
/// Make two unittypes be considered equals
|
||||
extern void AiNewUnitTypeEquiv(CUnitType *a, CUnitType *b);
|
||||
extern void AiNewUnitTypeEquiv(const CUnitType &a, const CUnitType &b);
|
||||
/// Remove any equivalence between unittypes
|
||||
extern void AiResetUnitTypeEquiv();
|
||||
/// Finds all equivalents units to a given one
|
||||
|
|
|
@ -236,11 +236,11 @@ static void InitAiHelper(AiHelper &aiHelper)
|
|||
}
|
||||
|
||||
for (std::vector<CUnitType *>::const_iterator d = UnitTypes.begin(); d != UnitTypes.end(); ++d) {
|
||||
CUnitType *type = *d;
|
||||
CUnitType &type = **d;
|
||||
|
||||
if (type->CanStore[i] > 0) {
|
||||
if (type.CanStore[i] > 0) {
|
||||
/* HACK : we can't store TIME then use 0 as 1 */
|
||||
AiHelperInsert(aiHelper.Depots, i - 1, **d);
|
||||
AiHelperInsert(aiHelper.Depots, i - 1, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ static int CclDefineAiHelper(lua_State *l)
|
|||
LuaError(l, "unknown unittype: %s" _C_ value);
|
||||
}
|
||||
AiHelperInsert(AiHelpers.Equiv, base->Slot, *type);
|
||||
AiNewUnitTypeEquiv(base, type);
|
||||
AiNewUnitTypeEquiv(*base, *type);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -86,6 +86,7 @@ int GetPlayerData(const int player, const char *prop, const char *arg)
|
|||
} else if (!strcmp(prop, "UnitTypesCount")) {
|
||||
const std::string unit(arg);
|
||||
CUnitType *type = UnitTypeByIdent(unit);
|
||||
Assert(type);
|
||||
return Players[player].UnitTypesCount[type->Slot];
|
||||
} else if (!strcmp(prop, "AiEnabled")) {
|
||||
return Players[player].AiEnabled;
|
||||
|
|
|
@ -111,6 +111,7 @@ found:
|
|||
CPlayer &player = Players[playerId];
|
||||
const Vec2i pos(unit.tilePos.x + offX, unit.tilePos.y + offY);
|
||||
CUnitType *type = UnitTypeByIdent(this->unitTypeStr.c_str());
|
||||
Assert(type);
|
||||
Vec2i resPos;
|
||||
DebugPrint("Creating a %s\n" _C_ type->Name.c_str());
|
||||
FindNearestDrop(*type, pos, resPos, LookingW);
|
||||
|
|
|
@ -726,10 +726,9 @@ static int CclGetPlayerData(lua_State *l)
|
|||
lua_pushnumber(l, p->MaxResources[resId]);
|
||||
return 1;
|
||||
} else if (!strcmp(data, "UnitTypesCount")) {
|
||||
CUnitType *type;
|
||||
|
||||
LuaCheckArgs(l, 3);
|
||||
type = CclGetUnitType(l);
|
||||
CUnitType *type = CclGetUnitType(l);
|
||||
Assert(type);
|
||||
lua_pushnumber(l, p->UnitTypesCount[type->Slot]);
|
||||
return 1;
|
||||
} else if (!strcmp(data, "AiEnabled")) {
|
||||
|
|
|
@ -456,7 +456,7 @@ int SelectUnitsByType(CUnit &base)
|
|||
*/
|
||||
int ToggleUnitsByType(CUnit &base)
|
||||
{
|
||||
const CUnitType *type = base.Type;
|
||||
const CUnitType &type = *base.Type;
|
||||
|
||||
// if unit is a cadaver or hidden (not on map)
|
||||
// no unit can be selected.
|
||||
|
@ -465,7 +465,7 @@ int ToggleUnitsByType(CUnit &base)
|
|||
}
|
||||
// if unit isn't belonging to the player, or is a static unit
|
||||
// (like a building), only 1 unit can be selected at the same time.
|
||||
if (!CanSelectMultipleUnits(*base.Player) || !type->SelectableByRectangle) {
|
||||
if (!CanSelectMultipleUnits(*base.Player) || !type.SelectableByRectangle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -487,7 +487,7 @@ int ToggleUnitsByType(CUnit &base)
|
|||
const Vec2i maxPos = vp->MapPos + vpSize + offset;
|
||||
std::vector<CUnit *> table;
|
||||
|
||||
Select(minPos, maxPos, table, HasSameTypeAs(*type));
|
||||
Select(minPos, maxPos, table, HasSameTypeAs(type));
|
||||
|
||||
// FIXME: peon/peasant with gold/wood & co are considered from
|
||||
// different type... idem for tankers
|
||||
|
|
Loading…
Reference in a new issue