Add Free Unit - By UnitClass?

Irkalla

ENTP POWWWEEEEEER
Joined
Sep 25, 2012
Messages
1,009
Location
Way down around Vicksburg
Any way I can give a civ a unit by the unit class type instead of the unit type?

Trying to create something that's robust. If I can't, I'll just make a less robust, ad hoc version.
 
CvCivilizationInfo::getCivilizationUnits(int i)

This function return which unit the civilization can build for that unitclass. Note that this can be -1 (NO_UNIT). You will need to make sure you don't spawn a unit if it is.
 
CvCivilizationInfo::getCivilizationUnits(int i)

This function return which unit the civilization can build for that unitclass. Note that this can be -1 (NO_UNIT). You will need to make sure you don't spawn a unit if it is.

I assume the method accepts a UnitClassType ID as its sole parameter.

oh crap that's C++. I should have specified Lua!
 
Code:
function GetCivSpecificUnit(pPlayer, sUnitClass)
  local sUnitType = nil
  local sCivType = GameInfo.Civilizations[pPlayer:GetCivilizationType()].Type

  for pOverride in GameInfo.Civilization_UnitClassOverrides{CivilizationType = sCivType, UnitClassType = sUnitClass} do
    sUnitType = pOverride.UnitType
    break
  end

  if (sUnitType == nil) then
    sUnitType = GameInfo.UnitClasses[sUnitClass].DefaultUnit
  end

  return sUnitType
end
 
*edit* I shouldn't leave threads open while doing other things, then replying without checking for new posts...
 
Code:
function GetCivSpecificUnit(pPlayer, sUnitClass)
  local sUnitType = nil
  local sCivType = GameInfo.Civilizations[pPlayer:GetCivilizationType()].Type

  for pOverride in GameInfo.Civilization_UnitClassOverrides{CivilizationType = sCivType, UnitClassType = sUnitClass} do
    sUnitType = pOverride.UnitType
    break
  end

  if (sUnitType == nil) then
    sUnitType = GameInfo.UnitClasses[sUnitClass].DefaultUnit
  end

  return sUnitType
end

I'll give it a whirl.
 
Back
Top Bottom