Palomino - Game Module (Lua and C++)
©2004,2008 Jim E. Brooks
http://www.palomino3d.org
Contents
Overview
[2008/11]
Most of the game logic shall be written in Lua.
The central concept is the actor (game entity).
Unlike old versions, there is no C++ Actor class.
Examples of Game Logic
[2008/10]
SAM detects and fires at player
- SAM actor constructed during mission startup
- SAM actor listens for new actors to appear
- player is notified by HUD if within SAM's radar radius
- SAM actor tries to detect enemy aircraft using radar (exclude friendly aircraft)
- SAM actor selects an enemy
- player is notified by HUD if SAM has locked-on
- SAM actor fires missile when radar-lock becomes strong
New enemy aircraft is spawned
- AircraftActor is constructed
- Enemy's avionics builds initial list of hostile actors (includes player)
- Enemy's avionics tracks certain kinds of actors (aircraft, missiles, radars)
- Enemy AI reacts to nearest actor
- Enemy or its friend may destroy nearest actor, so reassess threating actors
Implementation Partitioned Across Lua and C++
[2008/10]
A goal is to implement the game logic in Lua as much as possible.
The C++ side shall have supporting subroutines.
But the notion of actors and a game class only exist in Lua.
Writing signficant parts in C++ would be difficult to implement (explained below).
Even without those difficulties, the result would be a disorganized implementation.
Difficulties in alternative implementation based on C++ classes
The C++ simulator and Lua are based on reference-counting.
One design that was considered was to implement actor classes in C++
which are exported to Lua, and then Lua would've had classes based on them.
Having actor objects existing in both C++ and Lua would have complications.
If a C++ MissileActor destroys an AircraftActor, Lua may be holding
a reference to the AircraftActor. By design, C++ cannot call Lua,
so Lua would have to actively poll a "zombie list" produced by C++
in order for Lua to release references.
Game Class
[2008/10]
The notion of a Game class exists only in Lua.
Requirements of the Game class
- is THE container of Actors (C++ doesn't know nor hold references to them)
- can decide to attach/detach Actors
- responds to network commands to attach/detach Actors
Actors
[2008/10]
Requirements and characteristics of Actors
Examples of Actor Classes
- generic
- aircraft
- missile
- radar
- SAM
- vehicle
Actor Events
[2008/10]
Destroy Object Event
Both C++ and Lua can hold references to an Object.
If one side decides to destroy an Object,
an event must be broadcast to unreference the Object in all containers.
Collision-Detection Event
C++ does collision-detection.
So, when Lua creates a missile actor, Lua has to poll Dyna::IfCollision()
of an Actor's underlying Object/Dyna.
C++ Support for Lua
[2008/10]
The C++ side of the simulator provides subroutines to support the Lua game logic.
C++ is used for subroutines that must be executed every frame
or cannot be implemented in Lua.
C++ knows nothing about game concepts such as actors.
C++ manipulates an Aircraft without knowing it is part of a Lua Actor.
Example list of specific C++ subroutines for game logic:
- HUD widgets (target boxes)
- Controller class that animates an Object every frame (for missiles and guns)
- sends/receives commands across network (which Lua understands and processes)
- etc
Missiles
[2008/10]
- NOP if no radar lock or Craft has no more missiles
- create Object that inherits launching Craft's matrix
- create SmokeTrailParticleSystem
- register tick functor to animate missile (see Guidance)
- tick functor: create new particles where missile has moved to
- tick functor: do collision-detection of missile
- tick functor: check if target dropped chaff, randomly go off-course
- tick functor: if hit: start ExplosionParticleSystem
- tick functor: if hit: remove target from Game's target list
Guidance
[2007/10:V2]
A basic guidance algorithm is:
- Roll left.
- If angle between up vector (+Y) and target increased,
rolling left was a mistake, so roll right.
- Continue above steps until angle reaches zero.
- Likewise, try to pitch up or down
until the chaser's forward vector (Z) is pointing at the target.
To avoid flip-flopping and jittering, the switching of maneuvers
needs to be moderated and have a tolerance for small angles.
For N frames, continue the same maneuver.
Last modified: Sat Nov 8 08:44:47 EST 2008