Home Crush your enemies... and create an EMPIRE!!! Space Empires V -- BUY NOW!!!

User login

  • Create new account
  • Request new password

Navigation

  • news
    • archive
    • blogs
    • books
    • forums
    • recent posts
    • groups
  • image galleries
  • projects & downloads
  • search
  • create content
  • news aggregator

Search

Who's online

There are currently 2 users and 239 guests online.

Online users

  • Randallw
  • ForesterSOF

Languages

  • English English
  • French French

Browse archives

« November 2008  
Mo Tu We Th Fr Sa Su
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Home » news » forums » Support & Feedback » Scenarios & Mods » SE:V MODs

Unit Groups and AI

Submitted by Gideon on Sat, 2007-04-21 16:40. SE:V MODs

I've been trying, and I have yet to discover how to have the AI look inside a unit group.

Has anyone here had any success? I want to count the number of units inside the unit group, but I can't seem to find a way to do it.

Thanks.

‹ ship constuction mods Minor mount idea ›
» login or register to post comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Unit Groups and AI

Submitted by nesrall on Mon, 2007-04-23 19:57.

Sys_Get_Number_of_Units_In_Space_Sector

returns number of visible units in a specific system and sector.
returns a number count on a specific vehicle type(fighters or satellites etc. etc.) or if desired a number count of all units in sector.

» login or register to post comments
Mod Designer

Re: Unit Groups and AI

Submitted by Gideon on Tue, 2007-04-24 15:07.

I tried this, and it doesn't do what I want. I need to be able to check the design_id, or the general_type. This returns the unit type, as defined in VehicleSizes.txt. Unfortunatly, this means that it sees all satellites (for example, Recon Satellites) as exactly the same thing, Satellite.

Thanks for the suggestion, however.

» login or register to post comments
Captain Kwok's picture
Mod Designer

Re: Unit Groups and AI

Submitted by Captain Kwok on Wed, 2007-04-25 07:39.

Try identifying the space object as a unitgroup, then you might be able to cycle through the units as individual cargo items (Sys_Get_Space_Object_Cargo_Item_ID) which would give the the item ID that you could use to get the design ID etc.

-----

Space Empires Depot | SE:V Balance Mod

» login or register to post comments
Mod Designer

Re: Unit Groups and AI

Submitted by Gideon on Wed, 2007-04-25 19:52.

Captain Kwok wrote:
Try identifying the space object as a unitgroup, then you might be able to cycle through the units as individual cargo items (Sys_Get_Space_Object_Cargo_Item_ID) which would give the the item ID that you could use to get the design ID etc.

-----

Space Empires Depot | SE:V Balance Mod

Hrm, I'll give this a shot. I don't think it counts member units as cargo, but maybe it does.

» login or register to post comments
Mod Designer

Re: Unit Groups and AI

Submitted by Gideon on Wed, 2007-04-25 23:11.

That did it, thanks Kwok.

If anyone is interested, this bit of code will tell the AI to count objects by general type.

Count_Units_In_Cargo

Desired_cargo is the general_type of the desired object, as set in Script_AI_DesignCreation.txt and defined in Script_AI_GlobalConstants_DesignTypes.txt.
Object_id is the object id of the object holding the cargo.

//------------------------------------------------------------------------
// Count_Units_In_Cargo
//------------------------------------------------------------------------
function Count_Units_In_Cargo returns long
params
desired_cargo: string
object_id: long
vars
cargo_count: long
cargo_index: long
cargo_item_id: long
cargo_design_id: long
cargo_general_type: string
total_count: long
begin
set total_count := 0

// --- Count the ammount of cargo on the object.
set cargo_count := Sys_Get_Space_Object_Cargo_Item_Count(object_id)
if (cargo_count > 0) then
for cargo_index := 1 to cargo_count do

// --- Check each object against the desired type, and count the number present
set cargo_item_id := Sys_Get_Space_Object_Cargo_Item_ID(object_id, cargo_index)
set cargo_design_id := Sys_Get_Space_Object_Cargo_Item_Design_ID(object_id, cargo_item_id)
set cargo_general_type := Sys_Get_Vehicle_Design_General_Type(sys_long_Player_ID, cargo_design_id)

if (cargo_general_type = desired_cargo) then
set total_count := total_count + 1
endif

endfor
endif
return total_count
end

Returns total count in the target cargo.
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Count_Units_In_Space_Sector counts the units in a space sector by general type.

Target_design_type is the general_type of the desired object, as set in Script_AI_DesignCreation.txt and defined in Script_AI_GlobalConstants_DesignTypes.txt.
Target_system is the system you want to check.
Target_sector is the sector in the above system you want to check.

If it encounters a unitgroup, it calls Count_Units_In_Cargo, with the id of the unit group and the general type of the desired object.

Returns total count in the target sector.

//------------------------------------------------------------------------
// Count_Units_In_Space_Sector
//------------------------------------------------------------------------
function Count_Units_In_Space_Sector returns long
params
target_design_type: string
target_system: long
target_sector: long
vars
object_list: longlist
object_count: long
object_index: long
object_id: long
object_sector: long
object_owner: long
object_design_id: long
object_general_type: string
total_count: long
begin
set total_count := 0

// --- List the objects in the system.
call Sys_Get_All_Visible_Space_Objects_In_System(sys_long_Player_ID, target_system, object_list)

// --- Fill up our object stats.
set object_count := object_list.count()
if (object_count > 0) then
for object_index := 1 to object_count do
set object_id := object_list.get(object_index)
set object_sector := Sys_Get_Space_Object_Sector_Location(object_id)
set object_owner := Sys_Get_Space_Object_Owner(object_id)
set object_design_id := Sys_Get_Space_Object_Vehicle_Design_ID(object_id)
set object_general_type := Sys_Get_Vehicle_Design_General_Type(sys_long_Player_ID, object_design_id)

// --- Check if it is in our desired sector, if we own it, and if it's the kind we want. If so, increment count.
if (object_sector = target_sector) and (object_owner = sys_long_Player_ID) and (object_general_type = target_design_type) then
set total_count := total_count + 1
endif

// --- If its a unit group, count all the units as cargo.
if (Sys_Get_Space_Object_Type(object_id) = SPACE_OBJECT_TYPE_UNITGROUP) then
set total_count := total_count + Count_Units_In_Cargo(target_design_type, object_id)
endif
endfor
endif

return total_count
end

Anyone is free to use any part of this code in their mods.

» login or register to post comments
Captain Kwok's picture
Mod Designer

Re: Unit Groups and AI

Submitted by Captain Kwok on Thu, 2007-04-26 07:46.

I'm glad it worked out. I had used a variation on my suggestion to return the type of unitgroup in order to give it orders, but I hadn't had the opportunity to see if it actually worked as intended.

-----

Space Empires Depot | SE:V Balance Mod

» login or register to post comments
Mod Designer

Re: Unit Groups and AI

Submitted by Gideon on Thu, 2007-04-26 11:40.

Cool, I'm using this as part of a separate build queue for units, so the AI builds them more often and efficiently.

» login or register to post comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Now on STEAM

Now on STEAM!Space Empires V via STEAMSpace Empires IV via STEAMSTEAM online by Valve Corporation

Popular content

Today's:

  • The mod simply knowns as "New Stuff"
  • Research By Percentage SUCKS
  • Star Trek Trailers.....
  • Space Empires V and VI: Expansions and the Future: Tell the Company What's on Your Wish List
  • Modding How to?

All time:

  • Space Empires V and VI: Expansions and the Future: Tell the Company What's on Your Wish List
  • Space Empires V
  • Gritty Galaxy Fleet Clash
  • Damn Dirty Bugs/Annoyances
  • Space Empires V: General Thoughts, Observations, and Suggestions

Last viewed:

  • Question about shipsets/new races
  • Freighter Use
  • Fate Shrine sabotage protection
  • drone combat?!
  • Help with AI, Getting it to react to player/ other empires Tech advancements
(c) Strategy First, Inc. All rights reserved.