Add to cpu_manager.ai :
function CpuManager:FindClosestListenPost( from_pos ) local closest_strat = nil local prev_distance = 0 for strat_ai in resource_manager:GetUnlockedStrategicPointAIs() do if strat_ai:Owner() == cpu_manager.player_id and strat_ai:HasListeningPost() then local strat_pos = strat_ai:GetEntity():GetPosition() --determine distance if closest_strat == nil then prev_distance = cpu_manager.terrain_analyzer:GetPathingDistance( from_pos, strat_pos ) closest_strat = strat_pos --ailog("d:\\defense.txt", "First LP at : "..tostring(prev_distance)) else --check if LP closer to from_pos local cur_distance = cpu_manager.terrain_analyzer:GetPathingDistance( from_pos, strat_pos ) if prev_distance > cur_distance then prev_distance = cur_distance closest_strat = strat_pos --ailog("d:\\defense.txt", "Closer LP at : "..tostring(prev_distance)) end end end end return closest_strat end function CpuManager:FindClosestDefensePoint() local enemy = cpu_manager:FindClosestEnemyPlayer() dbAssert( enemy ~= nil ) --find the closest strategic point I own to this enemy, and use it as my defense point local listen_pt = self:FindClosestListenPost( enemy:GetStartingPosition() ) return listen_pt end function CpuManager:IsTurret( build_name ) --ailog("d:\\defense.txt", "Check turret : "..build_name) if build_name == "ork_waagh_banner" then return true elseif build_name == "space_marine_turret_bolter" then return true elseif build_name == "chaos_turret_bolter" then return true elseif build_name == "eldar_support_platform_scatterlaser" then return true end --ailog("d:\\defense.txt", "No turret : "..build_name) return false end
Modify strategy.ai :
elseif( build_type.btype == CpuPrerequisites.BT_Building ) then if( not cpu_manager.components[ CpuPlayer.CT_BuildBuildings ] ) then return end local id = cpu_manager.stats:GetBuildingID( build_type.name ) if( self:PlanExists("Build Building Plan", id) == false ) then local start_pos = cpu_manager.cpu_player:GetStartingPosition() if cpu_manager:IsTurret( build_type.name ) then local build_pos = cpu_manager:FindClosestDefensePoint() if build_pos ~= nil then --ailog("d:\\defense.txt", "Build defense : "..build_type.name) self.AddPlan( self, BuildBuildingPlan( id, build_pos ) ) else --ailog("d:\\defense.txt", "Build defense Pos NIL : "..build_type.name) self.AddPlan( self, BuildBuildingPlan( id, start_pos ) ) end else --ailog("d:\\defense.txt", "Build other : "..build_type.name) self.AddPlan( self, BuildBuildingPlan( id, start_pos ) ) end end
Modify chaosbuildbasestrategy.ai or equivalent race file :
function ChaosBuildBaseStrategy:DoSecondaryBuildings() --build a second machine pit --check that we have one and only one machine cult local num_vehicle_buildings = 0 local num_barracks = 0 local num_turrets = 0 for build_channel in build_manager:GetBuildChannelAIs() do if build_channel:GetBlueprintID() == self.vehicle_building_id then num_vehicle_buildings = num_vehicle_buildings + 1 end if build_channel:GetBlueprintID() == self.barracks_id then num_barracks = num_barracks + 1 end if build_channel:GetBlueprintID() == self.turret_id then num_turrets = num_turrets + 1 end end --build a second machine cult if num_vehicle_buildings == 1 and resource_manager:GetResourceAmount():Get( ResourceAmount.RT_Requisition ) > 1000 and resource_manager:GetResourceAmount():Get( ResourceAmount.RT_Power ) > 500 then local build_type = CpuBuildType() build_type.btype = CpuPrerequisites.BT_Building build_type.name = self.vehicle_building_name self:TryBuild( build_type ) --build a second barracks elseif num_barracks == 1 and resource_manager:GetResourceAmount():Get( ResourceAmount.RT_Requisition ) > 1500 then local build_type = CpuBuildType() build_type.btype = CpuPrerequisites.BT_Building build_type.name = self.barracks_name self:TryBuild( build_type ) --build a turret elseif num_turrets < 10 and resource_manager:GetResourceAmount():Get( ResourceAmount.RT_Requisition ) > 400 and resource_manager:GetResourceAmount():Get( ResourceAmount.RT_Power ) > 200 then local build_type = CpuBuildType() build_type.btype = CpuPrerequisites.BT_Building build_type.name = self.turret_name self:TryBuild( build_type ) end end
Edited by LarkinVB, 01 February 2005 - 11:38 PM.