Jump to content


Photo

Building generators behind base


1 reply to this topic

#1 LarkinVB

LarkinVB

    title available

  • Members
  • 1,488 posts

Posted 25 February 2005 - 02:40 PM

Sometimes bases are packed with buildings.
I wanted to allow generators to be build at LP behind base.

Add this to cpu_manager.ai :

function CpuManager:IsGenerator( build_id )

	
   if build_id == cpu_manager.stats:GetBuildingID( "ork_generator" ) then
   return true
   elseif build_id == cpu_manager.stats:GetBuildingID( "space_marine_generator" ) then
   return true
   elseif build_id == cpu_manager.stats:GetBuildingID( "chaos_plasma_generator" ) then
   return true
   elseif build_id == cpu_manager.stats:GetBuildingID( "eldar_warp_generator" ) then
   return true
   end

   return false
end


--find the closest listen post behind base within path to enemy and use it for building generators
function CpuManager:FindClosestLP2Base()

   local build_pos = nil
   local best_enemy_strat = 0
   local enemy = cpu_manager:FindClosestEnemyPlayer()
   dbAssert( enemy ~= nil )
	
   local enemy_pos = enemy:GetStartingPosition()
   local base_pos = self.cpu_player:GetStartingPosition()

   --path distance from base to closest enemy
   local enemy_base = cpu_manager.terrain_analyzer:GetPathingDistance( enemy_pos, base_pos )

   for strat_ai in resource_manager:GetStrategicPointAIs() do
	
   if strat_ai:Owner() == cpu_manager.player_id and strat_ai:HasListeningPost() then
  local strat_pos = strat_ai:GetEntity():GetPosition()
  dbAssert( strat_pos ~= nil )
   
  --path distance from enemy to strategic point
  local enemy_strat = cpu_manager.terrain_analyzer:GetPathingDistance( enemy_pos, strat_pos )
   
   --do not choose strategic point in front of base
   if enemy_strat ~= -1 and enemy_strat > enemy_base then
   	 
 	 --distance from base to strategic point
 	 local base_strat = cpu_manager.terrain_analyzer:GetPathingDistance( strat_pos, base_pos )

 	 if ( build_pos == nil or enemy_strat > best_enemy_strat ) and 
        base_strat ~= -1 and base_strat < 150 then
	
      best_enemy_strat = enemy_strat
      build_pos = strat_pos
      
 	 end
   end
   end
   end

   return build_pos
end

and modify strategies\strategy.ai to look like this :

if( self:PlanExists("Build Building Plan", id) == false ) then

    local start_pos = cpu_manager.cpu_player:GetStartingPosition()

    if cpu_manager:IsTurret( id ) then

    local build_pos = cpu_manager:FindClosestLP2Enemy()
    if build_pos ~= nil then
    self.AddPlan( self, BuildBuildingPlan( id, build_pos ) )
    else
    self.AddPlan( self, BuildBuildingPlan( id, start_pos ) )     
    end
	elseif cpu_manager:IsGenerator( id ) then
    local build_pos = cpu_manager:FindClosestLP2Base()
    if build_pos ~= nil then
    self.AddPlan( self, BuildBuildingPlan( id, build_pos ) )
    else
    self.AddPlan( self, BuildBuildingPlan( id, start_pos ) )     
    end
	else
    self.AddPlan( self, BuildBuildingPlan( id, start_pos ) )
	end

 end
  

Perhaps you find it usefull.
I also added reverse build order for ork banners for my mod. Usually turrets are build at nearest LP to enemy but I found that banners are to precious for orks. Therefore the start building them at LP near base. You have to mod

cpu_manager.ai to look like this

--find the closest listen post I own to enemy within path and use it as defense point for turrets
function CpuManager:FindClosestLP2Enemy()

   local closest_p = nil
   local best_distance = 0
   local enemy = cpu_manager:FindClosestEnemyPlayer()
   dbAssert( enemy ~= nil )
	
   local from_pos = enemy:GetStartingPosition()

   local base_distance = cpu_manager.terrain_analyzer:GetPathingDistance( from_pos, self.cpu_player:GetStartingPosition() )

   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()
   dbAssert( strat_pos ~= nil )
   
   local cur_distance = cpu_manager.terrain_analyzer:GetPathingDistance( from_pos, strat_pos )
   
   --no building behind base or within threat range
   if cur_distance ~= -1 and cur_distance < base_distance and not 
 	 cpu_manager.terrain_analyzer:HasThreat( strat_pos, 20 ) then
 	 
 	 local num_turrets = 0
 	 
 	 for build_channel in build_manager:GetBuildChannelAIs() do
      
      if self:IsTurret( build_channel:GetBlueprintID() ) and 
      distance_sqr(build_channel:GetEntity():GetPosition(), strat_pos) < 300 then
      
      num_turrets = num_turrets + 1
      end
      
 	 end
 	 
 	 --random turrets for choosen LP
 	 --set fixed seed for consistant randoms per LP
 	 math.randomseed( strat_pos.x*strat_pos.y*self.player_id )

 	 if num_turrets < math.random( 2,3 ) then
       --determine best distance, orks reverse order
      if self.player_stats:GetPlayerRaceName() == "ork_race" then
                 
      if closest_p == nil or cur_distance > best_distance then
      
      best_distance = cur_distance
      closest_p = strat_pos

      end
      else
      if closest_p == nil or cur_distance < best_distance then
      
      best_distance = cur_distance
      closest_p = strat_pos

      end
      end
 	 end
   end
   
   end
   end
	
   --reset seed to original one
   math.randomseed( os.time()*self.player_id )

   return closest_p
end


#2 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 25 February 2005 - 05:35 PM

Superb! This is one step closer to ensuring that if a startpoint is too conjested (ie. 4p_ Billy's Peril) then the AI can move buildings to the nearest LPs from the main base. Its important for the AI to keep important base buildings close to the startpoint BUT if the startpoint is inherently tight then nearest LPs will do just fine. Will also allow the AI to build secondary HQs (at some point when we get to that) in blank areas on a map furthest from enemy.

Edited by thudo, 25 February 2005 - 05:35 PM.

Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users