Below is the routine where the the GetSpriteHitGroup() command is used. This is the top level AI routine for a turn based tank/vehicle strategy game. It breaks down like this:
1 Check if new units can be produced
2 Check for enemy targets
3 Display text
4 For loop that examines each AI unit one at a time:
Check if a unit is alive
Check if the unit is stunned
Set a goal for this turn and setup a goal node (location) for movement
Here is the critical code - check if ANY other unit occupies the goal node - If so, then skip this turn (don't go there)
Check if the unit can fly, if so then fly, else move ground unit
5 Delete Text
6 For loop to check if each unit can be repaired.
function AIOps()
if AISurviving < UnitLimit then AIBaseProduction()
AITarget()
Text(MovingText,"moving",MiddleX,MiddleY,255,255,255,36,255,1,On)
tt = TweenText( MovingText,Null,Null,Null,Null,255,0,Null,Null,Null,Null,1,0,2,On )
for i = 0 to AIPlayerLast
if not AITank[i].alive
continue
elseif AITank[i].stunned
dec AITank[i].stunned
continue
else
GoalSet(i,AITank[i].vehicle)
x = ScreenToWorldX(mapTable[AITank[i].goalNode].x)
y = ScreenToWorldY(mapTable[AITank[i].goalNode].y)
g1 = GetSpriteHitGroup( PlayerTankGroup,x,y )
g2 = GetSpriteHitGroup( AITankGroup,x,y )
if (g1>0) or (g2>0) then continue
endif
if AITank[i].vehicle = Hovercraft
if AITank[i].node <> AITank[i].goalNode
SetSpriteVisible(AITank[i].healthID,Off)
Fly( i,AITank,AITank[i].node,AITank[i].goalNode )
if GetSpriteVisible( AITank[i].bodyID ) then Hover( i,AITank,AITank[i].goalNode )
AIFOW(i)
MineField( i,AITank )
PlayerBaseCapture()
endif
else
while AITank[i].index < AITank[i].parentNode.length
SetSpriteVisible(AITank[i].healthID,Off)
nextMove = AITank[i].parentNode[AITank[i].index+1]
Move( i,AITank,AITank[i].parentNode[AITank[i].index],nextMove )
AIFOW(i)
if MineField( i,AITank ) then exit
if not GetTweenTextPlaying( tt,MovingText ) then tt = TweenText( MovingText,Null,Null,Null,Null,255,0,Null,Null,Null,Null,1,0,2,Off )
endwhile
PlayerBaseCapture()
endif
next i
DeleteText(MovingText)
for i = 0 to AIPlayerLast
if not AITank[i].alive then continue
if maptable[ AITank[i].parentNode[AITank[i].index] ].terrain = AIDepot
Repair(i,AITank,AIDepotNode,AITank[i].maximumHealth) `at depot?
endif
AIFOW(i)
next i
SetRawMouseVisible(On)
endfunction