MoverBase python

From WiCWiki

Jump to: navigation, search

Contents

MoverBase

Members

Position

Type
Vector3
Description
The current position of the MoverBase.


CurrentSpeed

Type
float
Description
The current speed of the MoverBase.


Heading

Type
float
Description
The current heading of the MoverBase.


LookHeading

Type
float
Description
The current direction the MoverBase is looking. Will only differ from #Heading if the host have a tower (like a tank).



DesiredSpeed

Type
float
Description
The speed the MoverBase is aiming to travel with.


Velocity

Type
Vector3
Description
The velocity of the MoverBase expressed as a Vector3.


Destination

Type
Vector3
Description
The destination of the MoverBase.


CurrentWaypoint

Type
Vector3
Description
The waypoint the MoverBase is currently moving towards.



Methods

IsMoving

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



IsBreak

Syntax
import wic
wic.game.MoverBase.IsBreak()
Description
-
Exceptions
-
See also
-



IsForceTurn

Syntax
import wic
wic.game.MoverBase.IsForceTurn()
Description
-
Exceptions
-
See also
-



IsTurnToHeading

Syntax
import wic
wic.game.MoverBase.IsTurnToHeading()
Description
-
Exceptions
-
See also
-



GetMaxSpeed

Syntax
import wic
wic.game.MoverBase.GetMaxSpeed()
Description
-
Exceptions
-
See also
-



GetDesiredHeading

Syntax
import wic
wic.game.MoverBase.GetDesiredHeading()
Description
-
Exceptions
-
See also
-



GetPosition

Syntax
import wic
wic.game.MoverBase.GetPosition()
Description
-
Exceptions
-
See also
-



SetPosition

Syntax
import wic
wic.game.MoverBase.SetPosition( aPosition )
Description
-
Exceptions
-
See also
-



GetCurrentSpeed

Syntax
import wic
wic.game.MoverBase.GetCurrentSpeed()
Description
-
Exceptions
-
See also
-



SetCurrentSpeed

Syntax
import wic
wic.game.MoverBase.SetCurrentSpeed( aSpeed )
Description
-
Exceptions
-
See also
-



GetHeading

Syntax
import wic
wic.game.MoverBase.GetHeading()
Description
-
Exceptions
-
See also
-



SetHeading

Syntax
import wic
wic.game.MoverBase.SetHeading( aHeading )
Description
-
Exceptions
-
See also
-



GetLookHeading

Syntax
import wic
wic.game.MoverBase.GetLookHeading()
Description
-
Exceptions
-
See also
-



SetLookHeading

Syntax
import wic
wic.game.MoverBase.SetLookHeading( aHeading )
Description
-
Exceptions
-
See also
-



GetDesiredSpeed

Syntax
import wic
wic.game.MoverBase.GetDesiredSpeed()
Description
-
Exceptions
-
See also
-



SetDesiredSpeed

Syntax
import wic
wic.game.MoverBase.SetDesiredSpeed( aDesiredSeed )
Description
-
Exceptions
-
See also
-



GetMoveBackwardsFlag

Syntax
import wic
wic.game.MoverBase.GetMoveBackwardsFlag()
Description
-
Exceptions
-
See also
-



SetMoveBackwardsFlag

Syntax
import wic
wic.game.MoverBase.SetMoveBackwardsFlag( aMoveBackwardsFlag )
Description
-
Exceptions
-
See also
-



GetVelocity

Syntax
import wic
wic.game.MoverBase.GetVelocity()
Description
-
Exceptions
-
See also
-



SetVelocity

Syntax
import wic
wic.game.MoverBase.SetVelocity( aVelocityVector )
Description
-
Exceptions
-
See also
-



GetDestintation

Syntax
import wic
wic.game.MoverBase.GetDestination()
Description
-
Exceptions
-
See also
-



SetDestination

Syntax
import wic
wic.game.MoverBase.SetDestination( aPosition )
Description
-
Exceptions
-
See also
-



GetMoveBackwardsFlag

Syntax
import wic
wic.game.MoverBase.GetMoveBackwardsFlag()
Description
-
Exceptions
-
See also
-



Examples

Making a Python mover

Lets modify a Humvee with a new mover. First we open /units/unittypes_wic.juice with the JuiceMaker tool. In the juice locate /UnitTypes/US_HUMWEE/myParasites. Select the VehicleMover parasite and press del to delete it. Right click myParasites and choose Add among the buttons to the Right. Select PythonMover and press OK. Now use these settings for the new PythonMover parasite:

mySpeed = 10
myPythonClientModule = humveemover
myPythonClientClass = ClientHumveeMover
myPythonServerModule = humveemover
myPythonServerClass = ServerHumveeMover
myPathType = VEHICLES

Then we create a python file for the mover. It will look like this:

import wic


class ClientHumveeMover( wic.player.MoverBase ):
	""" This class inherits the wic.player.MoverBase. In this mover we will
	not do anything special on the client side but we still have to do some
	initialization."""
	
	def Init( self ):
		""" This function will be called when the mover is initialized
		in the game.
		"""
		
		# We need to init the physics for the mover. 
		self.InitSpringVehicle( 2, 0 )
	

	def Update( self ):
		""" This function is mandatory. It's called every frame.
		"""
		
		# We need to update the physics representation of the vehicle every frame. Otherwise it will be pulled to y-coordinate 0.0
		self.UpdatePhysVehicle()


class ServerHumveeMover( wic.game.MoverBase ):
	""" This is the server side of the mover. It must inherit from wic.game.MoverBase.
	This is an attempt to make a really simple mover.
	"""


	def NewMoveOrder( self, aDestination, aFirstWaypoint, aSpeed, aMoveBackwardsFlag ):
		""" This method is mandatory. It will be called whenever a new move order
		is issued.
		"""
		
		# In this case we just make sure to update the mover with the new data
		self.Destination		= aDestination
		self.CurrentWaypoint	= aFirstWaypoint
		self.DesiredSpeed		= aSpeed
		self.MoveBackwardsFlag	= aMoveBackwardsFlag
	
	
	def Stop( self ):
		""" This method is mandatory. It will be called whenever a stop order
		is issued.
		"""
		
		# In this case we just make sure to update the mover with the new info.
		self.Destination		= self.Position
		self.CurrentSpeed		= 0.0
		self.Velocity			= wic.common.math.Vector3( 0.0, 0.0, 0.0 )
		self.MoveBackwardsFlag	= False
		
		# And return the position the mover stopped at.
		return self.Destination
	
	
	def UpdatePositionState( self, aTime ):
		""" This method is mandatory. It will be called every frame the mover is moving.
		"""
		
		# Calculate the vector between the current waypoint and the mover
		toWaypoint = self.CurrentWaypoint - self.Position
		
		# Movement for ground units are pretty 2 dimensional so we make sure we clear the y-coordinate
		toWaypoint.Y = 0.0
		
		# Normalize the vector
		toWaypoint.Normalize()
		
		# Scale the vector by the speed of the mover and the time of the last frame.
		toWaypoint *= ( self.DesiredSpeed * wic.common.GetElapsedTime() )
		
		# Append the vector to the movers position
		self.Position += toWaypoint
		
		# Set the mover y-coodinate to the height of the ground beneath the mover
		self.Position.Y = wic.common.GetY( self.Position.X, self.Position.Z, True, True )
		
		# Face the waypoint
		self.Heading = wic.common.math.VectorToAngle( toWaypoint.X, toWaypoint.Z )
		
		# If the mover is within 4 meters of it's destination we issue a stop order. It's close enough.
		if (self.Position - self.Destination).Length() < 4.0:
			self.Stop()
	
	
	def UpdateHeadingState( self, aTime ):
		""" This method is mandatory. It will be called every frame.
		"""
		
		# We can ignore this for now so we just insert a pass statement.
		pass

( Be sure to read the comments in the code for more info on what they do. )

The above code is then placed in a python file /python/humveemover.py. Now all we have to do is start the game and crate a Humvee.

Personal tools
User Created Content