Check for allowed units inside AI Script?

Wargus is a Warcraft 2 mod that allows you to play Warcraft 2 with the Stratagus engine.
Mizukami999
Posts: 14
Joined: Tue Dec 20, 2016 7:00 am

Check for allowed units inside AI Script?

Postby Mizukami999 » Sun Apr 23, 2017 6:22 am

(I better make a separate topic out of this...)

Friends! Does anybody know if it's possible to check whather a unit is allowed (like DefineAllow("unit-peon", "FFFFFFFFFFFFFFFF")) for a particular AI player before forming standard attack groups.

The problem is, the standard attack procedure requires AI to create a particular army, and only then to attack with the force.
In my case, AI is not allowed to build a particular unit if another player already created one. So, proper attack procedure is not working.

The standard build-attack method is:

Code: Select all

function() return AiForce(1, {"unit-footman", 1,}) end,
function() return AiWaitForce(1) end,
function() return AiAttackWithForce(1) end,
Yukiko
Posts: 52
Joined: Sun May 24, 2015 6:52 pm

Re: Check for allowed units inside AI Script?

Postby Yukiko » Sun Apr 23, 2017 1:45 pm

You could try using the Jadeite Ai to do fancy things. I've attached the latest version.

Code: Select all

function AiNathan_Skirmish_Fall_Genesis_2015()
	-- Wild Attacker
	AiJadeite_Intermittent_2010()
	if (GetPlayerData(AiPlayer(), "UnitTypesCount", AiBarracks()) > 0) then
		if (GetPlayerData(AiPlayer(), "UnitTypesCount", AiSoldier()) > 3) then
			AiJadeite_Force_2010(3, AiSoldier(), 15, AiShooter(), 10, AiCatapult(), 4)
			if (GetPlayerData(AiPlayer(), "UnitTypesCount", AiSoldier()) > 8) then
				AiJadeite_Upgrade_2010(AiSoldier())
				AiJadeite_Upgrade_2010(AiShooter())
				AiJadeite_Attack_2010(3)
			end
		else
			AiJadeite_Force_2010(0, AiSoldier(), 4)
		end
	end
end

Code: Select all

function AiLucas_Skirmish_Standard_2015(defendmelee, defendrange, attackmelee, attackrange)
	if (defendmelee == nil) then defendmelee = 2 end
	if (defendrange == nil) then defendrange = 0 end
	if (attackmelee == nil) then attackmelee = 5 end
	if (attackrange == nil) then attackrange = 1 end
	-- Defend
	if ((GameCycle > 15000) and (GetPlayerData(AiPlayer(), "UnitTypesCount", AiStables()) > 0)) then
		AiJadeite_Force_2010(0, AiCavalry(), 2 + defendmelee, AiShooter(), 1 + defendrange)
	elseif (GameCycle > 7500) then
		if (GetPlayerData(AiPlayer(), "UnitTypesCount", AiStables()) > 0) then
			AiJadeite_Force_2010(0, AiCavalry(), 2 + defendmelee, AiShooter(), 1 + defendrange, AiSoldier(), 0)
		else
			AiJadeite_Force_2010(0, AiSoldier(), 2 + defendmelee, AiShooter(), 1 + defendrange)
		end
	elseif (GameCycle > 2500) then
		AiJadeite_Build_2010(AiGuardTower())
		if (GetPlayerData(AiPlayer(), "UnitTypesCount", AiStables()) > 0) then
			AiJadeite_Force_2010(0, AiCavalry(), 2 + defendmelee, AiShooter(), 0 + defendrange)
		else
			AiJadeite_Force_2010(0, AiSoldier(), 2 + defendmelee, AiShooter(), 0 + defendrange)
		end
	end
	-- Attack
	if ((GetPlayerData(AiPlayer(), "UnitTypesCount", AiBlacksmith()) > 0) or (GetPlayerData(AiPlayer(), "Resources", "gold") > 5000)) then
		if (GameCycle > 15000) then
			AiJadeite_Force_2010(3, AiCavalry(), 10, AiShooter(), 4, AiCatapult(), 1)
		elseif (GameCycle > 7500) then
			if (GetPlayerData(AiPlayer(), "UnitTypesCount", AiStables()) > 0) then
				AiJadeite_Force_2010(3, AiCavalry(), 5 + attackmelee, AiShooter(), 3 + attackrange, AiCatapult(), attackrange)
			else
				if (attackrange < 2) then
					AiJadeite_Force_2010(3, AiSoldier(), 1 + attackmelee, AiShooter(), 2 + attackrange)
				else
					AiJadeite_Force_2010(3, AiSoldier(), 1 + attackmelee, AiShooter(), 1 + attackrange, AiCatapult(), attackrange)
				end
			end
		else
			if (GetPlayerData(AiPlayer(), "UnitTypesCount", AiStables()) > 0) then
				AiJadeite_Force_2010(3, AiCavalry(), 5 + attackmelee, AiShooter(), attackrange, AiCatapult(), attackrange)
			else
				AiJadeite_Force_2010(3, AiSoldier(), 5 + attackmelee, AiShooter(), attackrange)
			end
		end
		AiJadeite_Attack_2010(3)
	end
	-- Buildings and Upgrades
	AiJadeite_Intermittent_2010()
	if (GetPlayerData(AiPlayer(), "UnitTypesCount", AiSoldier()) > 2) then 
		if ((GetPlayerData(AiPlayer(), "Resources", "gold") > 5000) or (GameCycle > 5000)) then
			AiJadeite_Upgrade_2010(AiCavalryMage())
		else
			AiJadeite_Upgrade_2010(AiSoldier())
		end
	end
	if (((GameCycle > 15000) and (GetPlayerData(AiPlayer(), "Resources", "gold") > 3000)) or (attackrange > 1)) then
		AiJadeite_Upgrade_2010(AiShooter())
		AiJadeite_Upgrade_2010(AiCatapult())
	elseif (GameCycle > 2500) then
		if (GetPlayerData(AiPlayer(), "UnitTypesCount", AiBlacksmith()) > 0) then 
			AiJadeite_Build_2010(AiBarracks(), 2)
		end
	elseif (GameCycle < 500) then
		AiJadeite_Force_2010(0, AiSoldier(), 2)
	end
end
You can see some more examples in scripts/ai/ai_redribbon_2015.lua
Attachments
ai_jadeite_2010.lua
Latest Jadeite from Timeless Tales.
(35.03 KiB) Downloaded 88 times
Mizukami999
Posts: 14
Joined: Tue Dec 20, 2016 7:00 am

Re: Check for allowed units inside AI Script?

Postby Mizukami999 » Mon Apr 24, 2017 7:23 am

Thank you. I'll try to use this.

Who is online

Users browsing this forum: No registered users and 1 guest