Having trouble while making a mod compatible with CBP

zwei833

Emperor
Joined
Feb 26, 2011
Messages
1,228
Hello. I'm trying to make a CBO compatible with Lastsword's HRE civilization, But I have some trouble now:

There is a unit call "Reiter" in that mod, it is a melee unit, but its special ability is "if attacked, the next turn start will perform an extra ranged attack".

In the XML file, Reiter has <Combat>25</Combat> and <RangedCombat>20</RangedCombat>, but no any <Range>.
Spoiler :
Code:
		<Row>
			<Class>UNITCLASS_LANCER</Class>
			<Type>UNIT_LS_HRE_REITER</Type>
			<PrereqTech>TECH_METALLURGY</PrereqTech>
			<Combat>25</Combat>
			<RangedCombat>20</RangedCombat>
			<Cost>185</Cost>
			<FaithCost>370</FaithCost>
			<RequiresFaithPurchaseEnabled>true</RequiresFaithPurchaseEnabled>
			<Moves>4</Moves>
			<CombatClass>UNITCOMBAT_MOUNTED</CombatClass>
			<Domain>DOMAIN_LAND</Domain>
			<DefaultUnitAI>UNITAI_FAST_ATTACK</DefaultUnitAI>
			<Description>TXT_KEY_UNIT_LS_HRE_REITER</Description>
			<Civilopedia>TXT_KEY_CIVILOPEDIA_UNITS_RLS_HRE_REITER_TEXT</Civilopedia>
			<Strategy>TXT_KEY_UNIT_LS_HRE_REITER_STRATEGY</Strategy>
			<Help>TXT_KEY_UNIT_HELP_LS_HRE_REITER</Help>
			<MilitarySupport>true</MilitarySupport>
			<MilitaryProduction>true</MilitaryProduction>
			<Pillage>true</Pillage>
			<ObsoleteTech>TECH_COMBINED_ARMS</ObsoleteTech>
			<IgnoreBuildingDefense>true</IgnoreBuildingDefense>
			<GoodyHutUpgradeUnitClass>UNITCLASS_ANTI_TANK_GUN</GoodyHutUpgradeUnitClass>
			<AdvancedStartCost>30</AdvancedStartCost>
			<XPValueAttack>3</XPValueAttack>
			<XPValueDefense>3</XPValueDefense>
			<UnitArtInfo>ART_DEF_UNIT_LS_KNIGHT_HRE</UnitArtInfo>
			<UnitFlagIconOffset>0</UnitFlagIconOffset>
			<UnitFlagAtlas>HRE_LS_UNIT_ALPHA_ATLAS_3</UnitFlagAtlas>
			<IconAtlas>UNIT_MOD_LS_17_ATLAS</IconAtlas>
			<PortraitIndex>6</PortraitIndex>
			<MoveRate>QUADRUPED</MoveRate>
		</Row>

Its special ability is achieve by this LUA code:
Spoiler :
Code:
local rangeP = GameInfoTypes.PROMOTION_HRE_LS_RANGE;
local jezail = GameInfoTypes.UNIT_LS_HRE_REITER;
local RangAtt = GameInfoTypes.MISSION_RANGE_ATTACK;
local fIndi = GameInfoTypes.PROMOTION_LS_REITER_COUNTERSTRIKE;
local bKnight = GameInfoTypes.UNIT_LS_HRE_KNIGHT
local eMoves = GameInfoTypes.PROMOTION_LS_HRE_RAID

GameEvents.PlayerDoTurn.Add(function(iPlayer)
	for iUnit in Players[iPlayer]:Units() do
		if iUnit:GetUnitType() == jezail then
			if not iUnit:IsHasPromotion(fIndi) then
				SearchAttack(iUnit, iPlayer)
			else
				iUnit:SetHasPromotion(fIndi, false)
			end
		elseif iUnit:GetUnitType() == bKnight then
			local iMoves = iUnit:GetMoves() / iUnit:MaxMoves();
			iUnit:SetHasPromotion(eMoves, iUnit:GetPlot():GetOwner() == iPlayer)
			iUnit:SetMoves( math.floor(iMoves * iUnit:MaxMoves()))
		end
	end
end)


Events.AIProcessingEndedForPlayer.Add(function(iPlayer)
	for iUnit in Players[iPlayer]:Units() do
		if iUnit:GetUnitType() == jezail then
			iUnit:SetHasPromotion(fIndi, true)
		end
	end
end)

function SearchAttack(jUnit, iPlayer)
	local iPlot = jUnit:GetPlot();
	local iMoves = jUnit:GetMoves()
	if iMoves <= 0 then
		return
	end
	jUnit:SetHasPromotion(rangeP, true)
	local hTab = {}
	local hCou = 0;
	local bX = jUnit:GetX();
	local bY = jUnit:GetY();	
	for iX = -2, 2 do
		for iY = -2, 2 do
			local plot = Map.PlotXYWithRangeCheck(bX, bY, iX, iY, 2)
			if plot then
				if jUnit:CanStartMission(RangAtt, plot:GetX(), plot:GetY()) then
					if not plot:IsCity() then
						if not plot:IsWater() then
							table.insert(hTab, plot)
						end
					end
				end
			end
		end
	end
	if #hTab > 0 then
		local ePlot = hTab[math.random(1, hCou)];
		jUnit:PushMission(RangAtt, ePlot:GetX(), ePlot:GetY())
	end
	jUnit:SetMoves(iMoves);
	jUnit:SetMadeAttack(false);
	jUnit:SetHasPromotion(rangeP, false)
end

The problem is:
It seems that in CBO, a unit with a <RangedCombat> but without <Range> can not do any melee attack nor any ranged attack at all.
Is there any way to solve this issue?
 
This is more on Gazebo's part, but since you're using CBO if I had to rework it, I would "mock" the effect by using RED Combat System in CP to deduct hp off the attacker instead directly at the end of the combat.
 
This is more on Gazebo's part, but since you're using CBO if I had to rework it, I would "mock" the effect by using RED Combat System in CP to deduct hp off the attacker instead directly at the end of the combat.

There is a promotion type that I added for someone back in the day that deals retaliatory damage to a target when attacked by someone. You could use that for a similar effect? Look in the core table includes part of the CP.

G
 
Top Bottom