Unit python

From WiCWiki

Revision as of 15:59, 21 November 2007 by Tabu (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Contents

Unit

Inherits Agent.

The unit module takes care of things related to a single unit in the game. Move it around, making it attack other units or buildings etc. Observe that there is no constructor for the Unit object.


Members

Position

Type
Vector3
Description
The current world position of the Unit.


BodyHeading

Type
float
Description
The current heading of the Unit in radians. 0.0 indicates south. Rotation is clockwise.


MaxSpeed

Type
float
Description
The max velocity of the unit.


Health

Type
int
Description
Current health of the unit.


MaxHealth

Type
int
Description
Maximum health of the unit.


Owner

Type
Player
Description
The player the unit belongs to.


SquadId

Type
int
Description
The id of the units squad.


Team

Type
int
Description
The team the unit belongs to.


Type

Type
int
Description
Hashed name of the type of the unit.


MetaType

Type
int
Description
The meta type of the unit.


Id

Type
int
Description
Agent id of the unit.


HoldFire

Type
bool
Description
Flags whether the unit will acquire and engage targets on it's own.


IsContainer

Type
bool
Description
Flags whether the unit can contain other units.


IsContainable

Type
bool
Description
Flags whether the unit can be carried by other units.


ContainableType

Type
int
Description
Gives the units containable type.


CPC_ContainableType

Type
int
Description
Gives the units CPC containable type.


Invulnerable

Type
bool
Description
Flags whether the unit will sustain damage.


MinRange

Type
float
Description
The minimum distance to attack a target.


MaxRange

Type
float
Description
The maximum distance to attack a target.


Experience

Type
float
Description
The current experience of the unit.


ExperienceLevel

Type
int
Description
The current experience level of the unit.


SpecialAbilities

Type
SpecialAbility
Description
An array of the units special abilities.



Methods

Attack

Syntax
import wic
wic.game.Unit.Attack( aTarget )
Description
Tells the Unit to attack aTarget. Possible targets are Buildings and other Units
Exceptions
TypeError - aTarget wasn't a Building or a Unit.
See also
-



Enter

Syntax
import wic
wic.game.Units[0].Enter( wic.game.Buildings['Mansion_01__0'] )
Description
Makes the unit enter aTarget. Possible containers are Buildings or Units.
Exceptions
TypeError - aTarget isn't a Building or a Unit.
RuntimeError - The Unit isn't containable or aTarget is not a container.
See also
-



Move

Syntax
import wic
wic.game.Unit.Move( aDestination [,aHeading [,aSpeed [, aMoveBackwardsFlag]]] )
Description
Makes the unit move to aDestination.
(Optional) aHeading gives the heading the Unit should face when stopping at adestination.
(Optional) aSpeed can be specified to make the Unit move towards aDestination with a specific speed.
(Optional) aMoveBackwardsFlag tells the Unit to move backwards.
Returns True if the Unit can obey the order ans False if the move cannot be completed.
Exceptions
TypeError - aDestination isn't a Vector3, aHeading isn't a float, aSpeed isn't a float or aMoveBackwardsFlag isn't a bool.
See also
-



Stop

Syntax
import wic
wic.game.Unit.Stop()
Description
Tells the Unit to stop.
Exceptions
-
See also
#Move



UnloadAll

Syntax
import wic
wic.game.Unit.UnloadAll()
Description
Makes the Unit unload all of it's contained Units.
Exceptions
-
See also
-



SetupArmor

Syntax
import wic
wic.game.Unit.SetupArmor( someArmorData )
Description
Sets the Units armor values according to the data in the given Ice.
Exceptions
TypeError - someArmorData isn't an Ice.
See also
-



IsMoving

Syntax
import wic
wic.game.Unit.IsMoving()
Description
Returns True if the Unit is currently moving.
Exceptions
-
See also
-



GetCurrerntSpeed

Syntax
import wic
wic.game.Unit.GetCurrentSpeed()
Description
Returns the current speed of the Unit.
Exceptions
-
See also
-



GetKillerUnitId

Syntax
import wic
wic.game.Unit.GetKillerUnitId()
Description
Returns the id of the Unit which made the killing damage on the Unit.
Exceptions
-
See also
#GetKillerUnit



GetKillerUnit

Syntax
import wic
wic.game.Unit.GetKillerUnit()
Description
Returns the Unit which made the killing damage on the Unit.
Exceptions
-
See also
#GetKillerUnitId



GetKillerHitDirection

Syntax
import wic
wic.game.Unit.GetKillerHitDirection()
Description
Returns the direction Vector2 from which the killing blow came.
Exceptions
-
See also
-



GetKillerPlayerId

Syntax
import wic
wic.game.Unit.GetKillerPlayerId()
Description
Returns the id of the Player that killed the Unit.
Exceptions
-
See also
#GetKillerPlayer



GetKillerPlayer

Syntax
import wic
wic.game.Unit.GetKillerPlayer()
Description
Returns the Player that killed the Unit.
Exceptions
-
See also
#GetKillerPlayerId



GetPrimaryShooter

Syntax
import wic
wic.game.Unit.GetPrimaryShooter()
Description
Returns the primary ShooterBase object of the Unit.
Exceptions
-
See also
ShooterBase



SetPosition

Syntax
import wic
wic.game.Unit.SetPosition( aPosition )
Description
Will instantly move the Unit to aPosition.
Exceptions
-
See also
#Position



SetBodyHeading

Syntax
import wic
wic.game.Unit.SetBodyHeading( aHeading )
Description
Will make the Unit face aHeading.
Exceptions
TypeError
aHeading isn't a float.
See also
#BodyHeading



ChangeHealth

Syntax


Description
Changes the #Health of the Unit by aHealthDelta.
Exceptions
TypeError - aHealthDelta is not an int.
See also
#SetHealth



SetHealth

Syntax
import wic
wic.game.Unit.SetHealth( aHealthValue )
Description
Sets the #Health of the Unit to aHealthValue. Capped by the #MaxHealth.
Exceptions
TypeError - aHealth is not an int.
See also
#ChangeHealth



SetOwner

Syntax
import wic
wic.game.Unit.SetOwner( aPlayer )
Description
Sets the owner of the Unit to aPlayer.
Exceptions
TypeError
anOwner isn't a valid Player.
See also
#Owner



SetTeam

Syntax
import wic
wic.game.Unit.SetTeam( aTeam )
Description
Sets the team the Unit should belong to.
Exceptions
TypeError
aTeam is not an int.
See also
#Team



SetHoldFire

Syntax
import wic
wic.game.Unit.SetHoldFire( True )
Description
If aHoldFireFlag is True the Unit won't acquire any targets on it's own.
Exceptions
TypeError
aHoldFireFlag is not a bool.
See also
#HoldFire



SetInvulnerable

Syntax
import wic
wic.game.Unit.SetInvulnerable( anInvulnerableFlag )
Description
If anInvulnerableFlag is True the Unit will not recieve any damage.
Exceptions
TypeError
anInvulnerableFlag is not a bool.
See also
#Invulnerable



SetExperience

Syntax
import wic
wic.game.Unit.SetExperience( anExperienceValue )
Description
Sets the experience of the Unit to anExperienceValue.
Exceptions
TypeError
anExperienceValue is not a float.
See also
#Experience
#ExperienceLevel
#SetExperienceLevel



SetExperienceLevel

Syntax
import wic
wic.game.Unit.SetExperienceLevel( anExperienceLevel )
Description
Sets the Units experience level to anExperienceLevel. #Experience will be adjusted accordingly.
Exceptions
TypeError
anExperienceLevel is not a float.
See also
#Experience
#ExperienceLevel
#SetExperience



Examples

The below samples presume that you are using doRuins (europe1) as your laboratory. Fire up a multiplayer game on that map and write the below in the console. To tell the console that it's Python you are entering, you have to prefix every line with "py ". Oh, and you have to start the game with the commandline parameter -console for the ingame console to be avaliable.

Lets start with setting up some stuff to make it all a lot easier later on.

py import wic
py from wic.common import StringToInt as s2i
py from wic.common.math import Vector3
py player1 = wic.game.Players[1]

We need a point on the map that's easy to locate. The big white mansion is a nice target.

py mansion = wic.game.Buildings['Mansion_01__0']

creating a new Unit. Lets create a US Marine just outside the Mansion. This is done with a call to a function in the game module.

py marineId = wic.game.CreateUnit( s2i( 'F1_Marine' ), mansion.Position, 0.0, 0, 0 );
py marine = wic.game.Units[marineId]

Wohoo! Now we have a brand new Unit instance. So what do we want to do with it? Hmm... let's give it to player 1 which will be you if you are all alone on the map.

py marine.Owner = player1
py marine.Team = player1.Team

Well, that was easy. Now the first player owns the unit and can do with it whatever he or she likes. So lets do something else with our Marine. Let him get a nice Armored Transport to move around in.

py bradleyId = wic.game.CreateUnit( s2i( 'US_Bradley_APC' ), mansion.Position, 0.0, player1.Id, player1.Team )
py bradley = wic.game.Units[bradleyId]

And then we tell him to enter the transport which will take him to the farm close to the Nato starting area.

py marine.Enter( bradley )

When the marine is safely inside the bradley we can tell it to move to the southmost commandpoint. I happen to know it's index is 2.

py commandPoint = wic.game.CommandPoints[2]
py bradley.Move( commandPoint.Position )

And finally when the APC stops at the destination we can let the marine out into the world again.

py bradley.UnloadAll()

To make a script that does this is a little bit more involved, mostly because we need to wait for the unit to enter the transport, wait for the APC to arrive at the destination but thats for another tutorial.

Personal tools
User Created Content