PseudoCode Characters - Milowan/WarChildPort GitHub Wiki

PseudoCode for all Character Scripts

BaseCharacter : public ACharacter

CharacterStats* stats Weapon* equippedWeapon position of weapon

OnStart()

connect to the pause and unpause events

Pause()

stop updating unit

UnPause()

start updating unit if active

GetStats()

get a reference to the character stats

GetWeapon()

get a reference to the equipped weapon

PullTrigger()

call the equipped weapon's trigger function

TakeDamage(float damage)

reduce character's health and check to see if is below zero if so; die

GetHealthFraction()

return current HP / max HP

virtual Die()

override for independent deaths

DefensePoint : public Character

DefensePoint()

initialize stats and set health to max

override Die()

fail mission

Player : public Character

OnAwake()

activate game object instantiate the player's selected weapon instantiate stats initialize health

Die()

trigger game over

PlayerInventory

static Weapon* equippedWeapon static Coin coin static Minerals minerals static Plastics plastics

CollectResource(Resource resource)

add resource amount to resource with matching type and delete/disable resource object

ConsumeResource(Resource resource)

remove resource amount from resource with matching type and delete resource object

Enemy : public Character

Vector3D destination float wanderRangeMin float wanderRangeMax bool alert bool isLast static int liveEnemies

OnAwake()

initialize attributes call SetStats()

virtual SetStats()

override with specific stat variants

FixedUpdate()

Check in front of character if character is alert check alignment to fire UpdateWeapon()

CheckFire()

check if target is in the line of fire if so; pull the trigger

Wander()

if active set destination to random point in range

Chase()

if active set destination to target's destination

Spawn()

activate self and weapon set health to max ++liveEnemies

Initialize(Transform tf)

set position and rotation to match tf set destination to somewhere random within reach

CheckTarget()

check if target is seen if so; commence chasing behaviour

SetTarget(Character target)

set scanner's target if target is not null start chasing it

Die()

--liveEnemies disable object and weapon

GameOver()

Disable

BasicRifleman : Enemy

override SetStats()

stats = new BasicRiflemanStats();

AdvancedRifleman : Enemy

override SetStats()

stats = new AdvancedRiflemanStats();

MachinePistoler : Enemy

override SetStats()

stats = new MachinePistolerStats();

AIController

Update

call function for character's current behaviour

Scanner

float FoV float sightRange Character* target

Initialize()

assign FoV and sightRange

Update()

Raycast ahead to see if target can be found

GetTarget()

return target character

SetTarget(Character* target)

this target = target