Water depth && Unit type values

Water depth && Unit type values

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Water depth && Unit type values

Post by AF »

I'm working on my unviersal build routiens for NTai and I have no way of telling the difference between submarines amphibious units, and udnerwater structures, save wether they're mobile or not.

So, based on maxWaterDepth and MinWaterDepth, what would I expect for:

A submarine

A pelican/hvoercraft

A triton/croc/Gimp

An underwater mex

A normal building.

A normal unit
Egarwaen
Posts: 1207
Joined: 27 Feb 2006, 21:19

Re: Water depth && Unit type values

Post by Egarwaen »

AF wrote:A pelican/hvoercraft
Don't these totally ignore water depth?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

I think if it has a minimum depth it can be classified as a sub, if it doesn't it can obviously move on land and is amphibious. Also I'd check more for underwater weapons as those matter more for submarine combat than the movement type. E.g. a construction sub shouldn't try to approach a torpedo-equipped amphibious unit.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

The problem is, regardless of wether you define the tag, when i look through the AI itnerface it always has a value, so I need to know what that value represents and how ti works.

And I think floater=1 is used for hovercraft and pelicans, but it doesnt tell me anything about how MinWaterDepth and maxWaterDepth work
User avatar
Rafal99
Posts: 162
Joined: 14 Jan 2006, 04:09

Re: Water depth && Unit type values

Post by Rafal99 »

AF wrote:So, based on maxWaterDepth and MinWaterDepth, what would I expect for:
Also Floater, WaterLine and CanHover tags are useful here.
Try something like this:

Code: Select all

if (ud->canhover) {
  //it is a hovercraft
}
 
if (ud->minWaterDepth > 0) {
  //it is a water-only unit or building
  if (ud->floater || ud->waterline) {
    if (ud->waterline > 10) {
      //it is a sub
    } else {
      //it is a ship 
    }
  }
  else {
    //it is something like underwater mex and stays at the bottom
  }
}

if (ud->minWaterDepth <= 0) {
  //it is a ground unit or building
  if (ud->floater) {
    //unit can float, like Pelican for example
  }
  else if (ud->maxWaterDepth > 30) {
    //unit can move underwater
  }
  else {
    //unit is ground only
  }
}
Also try using min(ud->maxWaterDepth, ud->movedata->depth) instead ud->maxWaterDepth, otherwise it gives wrong results for some units.

Everything was tested and worked prefectly for AA and XTA but it was some time ago, so some values might need a little tweaking.

Btw it wasn't so hard find out with a look at mod files and some testing.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

wow, that wasnt just exactly what i needed it was the code too!!!!!!!!!!

*10 cookies to rafal*
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Post by bobthedinosaur »

wouldnt planes become ground only then?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

for a plane

ud->canfly=true && ud->movedata==0

planes simply dont obey the same set of movement rules.
esteroth12
Posts: 501
Joined: 18 May 2006, 21:19

Post by esteroth12 »

isnt there also something like, "taairmovetype" or something like that? a patch got rejected because it assumed all flying units used canfly=1
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

hmmm I thoguht all flying untis had canfly=1;.....

I know for deffo both static buildings and aircraft have ud->movedata==0/null though
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post by Bobcatben »

does ud->canfly only work for the globalai interface? cause whenever i try with the groupai interface it always returns the same value no matter if its a building or a plane or my commander, i was trying to make my group ai only accept planes, never did get that part to work.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

this check should be enough

Code: Select all

if(ud->canfly && (ud->movedata==0))
also

Code: Select all

if(ud->type == string("Fighter"))
if(ud->type == string("Bomber"))
with

Code: Select all

if(ud->type == string("Fighter")){
    if(ud->hoverattack == true){
        //gunship
    }else{
        // fighter
    }
}
Could this be moved to the AI forum now?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

So if my tags list says e.g. Gunship instead of Fighter it won't get recognized?
Gnomre
Imperial Winter Developer
Posts: 1754
Joined: 06 Feb 2005, 13:42

Post by Gnomre »

IIRC SJ said the engine handles con aircraft and air transports with the same pathfinding as gunships as well.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

ud->type is defined based on which Unit AI was assigned to the unit.

Gunships and fighters both have the same Unti AI and thus are assigned the Fighter value.

You need to check anythign with the Fighter value for the hoverattack value, which dictates wether a fighter circles its target like a gunship or if it atatcks like a hawk..

Factory
Builder
MetalExtractor
Ground
Fighter
Bomber

not sure about Ground and there may be another one to be added
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post by Bobcatben »

does ud->type work with groupai's? mine always return (null) :?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

in that case you are doing something wrong.

GroupAI's and the Skirmish AI's have identical itnerfaces, infact they're the same interface.

Always check for error codes.

if the unit you're trying to check is out of LOS/radar and you shouldnt be able to tell what type of unit it is then cb->getUnitDef will return a null pointer.

Thus check if(ud){do stuff}else{skip}
Post Reply

Return to “Game Development”