Skip to content

Commit

Permalink
use CBA state machine
Browse files Browse the repository at this point in the history
	* create state machines for emotions, activities and cleanup
	  (despawning)
	* create state graphs as documentation

	CHANGES
	* you cannot point your car as a weapon – so civs will
	  not surrender to cars
	* also you cannot point your weapon from your car,
	  as far as civs are concerned
	* civs dont disembark when shot at in their vehicles
	* player civilians will see 'getDown' and 'sendAway'
	  commands as hints
	* some variability in civ behavior concerning panic cooldown
	  and chance to surrender
	* require ACE3
  • Loading branch information
Fusselwurm authored and Moritz Schmidt committed Mar 2, 2019
1 parent 5ddb58f commit b7971ac
Show file tree
Hide file tree
Showing 79 changed files with 1,386 additions and 367 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs/
55 changes: 32 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class CfgFunctions {
};
```

# Config
## Config
Add the class `cfgGradCivs` to your `description.ext`. Use the following attributes to configure the module:

## Attributes
### Attributes

Attribute | Default Value | Explanation
-------------------------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -54,10 +54,11 @@ faces | [] | All classnames of faces that civilian
goggles | [] | All classnames of goggles that civilians may wear.
headgear | [] | All classnames of headgear that civilians may wear.
backpacks | [] | All classnames of backpacks that civilians may wear.
panicCooldown | [15,120,240] | Time it takes until a civilian relaxes after panicking (trivariate: [lowest, median, highest])
vehicles | [] | All classnames of vehicles that civilians may drive.
backpackProbability | 0.5 | Probability that a civilian will wear a backpack.
backpackProbability | 50 | Probability that a civilian will wear a backpack, in percent

## Example
### Example

```sqf
class CfgGradCivs {
Expand Down Expand Up @@ -100,95 +101,95 @@ class CfgGradCivs {
};
```

# Functions
## Functions

## grad_civs_fnc_setClothes
### grad_civs_fnc_setClothes
Sets all clothes that civilians may wear. Overwrites `cfgGradCivs` value. Effect is global.

### Syntax
#### Syntax
`[clothes] call grad_civs_fnc_setClothes`

Parameter | Explanation
----------|-----------------------------------------------------------
clothes | Array - All classnames of clothes that civilians may wear.

## grad_civs_fnc_setFaces
### grad_civs_fnc_setFaces
Sets all faces that civilians may have. Overwrites `cfgGradCivs` value. Effect is global.

### Syntax
#### Syntax
`[faces] call grad_civs_fnc_setFaces`

Parameter | Explanation
----------|---------------------------------------------------------
faces | Array - All classnames of faces that civilians may have.


## grad_civs_fnc_setGoggles
### grad_civs_fnc_setGoggles
Sets all goggles that civilians may wear. Overwrites `cfgGradCivs` value. Effect is global.

### Syntax
#### Syntax
`[goggles] call grad_civs_fnc_setGoggles`

Parameter | Explanation
----------|-----------------------------------------------------------
goggles | Array - All classnames of goggles that civilians may wear.

## grad_civs_fnc_setHeadgear
### grad_civs_fnc_setHeadgear
Sets all headgear that civilians may wear. Overwrites `cfgGradCivs` value. Effect is global.

### Syntax
#### Syntax
`[headgear] call grad_civs_fnc_setHeadgear`

Parameter | Explanation
----------|-----------------------------------------------------------
headgear | Array - All classnames of clothes that civilians may wear.

## grad_civs_fnc_setBackpacks
### grad_civs_fnc_setBackpacks
Sets all backpacks that civilians may wear and sets probability. Overwrites `cfgGradCivs` value. Effect is global.

### Syntax
#### Syntax
`[backpacks,probability] call grad_civs_fnc_setHeadgear`

Parameter | Explanation
------------|-----------------------------------------------------------------------
backpacks | Array - All classnames of clothes that civilians may wear.
probability | Number - Probability that civilian will wear a backpack. Default: 0.5.

## grad_civs_fnc_setVehicles
### grad_civs_fnc_setVehicles
Sets all vehicles that civilians may drive. Overwrites `cfgGradCivs` value. Effect is global.

### Syntax
#### Syntax
`[vehicles] call grad_civs_fnc_setVehicles`

Parameter | Explanation
----------|-------------------------------------------------------------
vehicles | Array - All classnames of vehicles that civilians may drive.

## grad_civs_fnc_setDebugMode
### grad_civs_fnc_setDebugMode
Sets debug mode. Overwrites `cfgGradCivs` value. Effect is global.

### Syntax
#### Syntax
`[debugMode] call grad_civs_fnc_setDebugMode`

Parameter | Explanation
----------|--------------------------
debugMode | Bool - Debug mode on/off.

## grad_civs_fnc_initModule
### grad_civs_fnc_initModule
Used to manually initialize module. Has to be executed on clients and server. Effect is local.

### Syntax
#### Syntax
`[] call grad_civs_fnc_initModule`
`[] remoteExec ["grad_civs_fnc_initModule",0,true]`

Parameter | Explanation
----------|-----------------------------------------------------------
headgear | Array - All classnames of clothes that civilians may wear.

## grad_civs_fnc_populateArea
### grad_civs_fnc_populateArea
Manually populates an area with civilians. These civilians count towards the maximum amount.

### Syntax
#### Syntax
`[area,amount,excludeFromCleanup,staticVehicles,staticVehiclesMax] call grad_civs_fnc_populateArea`

Parameter | Explanation
Expand All @@ -199,4 +200,12 @@ excludeFromCleanup (optional) | Bool - Sets if these civilians will be excluded
staticVehicles (optional) | Bool - Sets if static vehicles will be created in the area. (default: false)
staticVehiclesMax (optional) | Number - Maximum amount of static vehicles to create. Actual amount is based on number of roads and houses in area.


![](http://i.imgur.com/Cimaz4c.jpg)

## Development

* we're using the CBA state machine implementation, see `/functions/sm_*/`
* if you add states or transitions, please update the DOT files in `/docs`
* which is where you'll find the compiled SVG files, too.
* install [Graphviz](https://graphviz.gitlab.io/) and generate them using `dot -Tsvg states.gv > states.svg` or use an online editor
82 changes: 76 additions & 6 deletions cfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@

class grad_civs {

class accessors {
file = MODULES_DIRECTORY\grad-civs\functions\accessors;

class clearCurrentlyThinking {};
class getCurrentlyThinking {};
class getGroupVehicle {};
class setCurrentlyThinking {};
class setGroupVehicle {};
};

class behaviour {
file = MODULES_DIRECTORY\grad-civs\functions\behaviour;

class flee {};
class stopCiv {};
class addCycleWaypoint {};
class taskPatrol {};
class taskPatrolAddWaypoint {};
};

class common {
Expand All @@ -35,6 +45,7 @@ class grad_civs {
class drawCivs {};
class mapMarkers {};
class showWhatTheyThink {};
class updateInfoLine {};
};

class init {
Expand All @@ -49,20 +60,79 @@ class grad_civs {
class addPointerTick {};
class checkWeaponOnCivilianPointer {};
class playerLoop {};
class registerAceInteractionHandler {};
class removePointerTick {};
};

class spawn {
file = MODULES_DIRECTORY\grad-civs\functions\spawn;

class spawnCivilian {};
class cleanup {};
class dressAndBehave {};
class addCarCrew {};
class addFootsy {};
class createSideRoadVehicles {};
class deleteIfDamaged {};
class dressAndBehave {};
class findSpawnPosition {};
class addToVehicle {};
class serverLoop {};
class spawnCivilian {};
class spawnCivilianGroup {};
class spawnPass {};
class spawnVehicle {};
};

class sm_activities {
file = MODULES_DIRECTORY\grad-civs\functions\sm_activities;

class sm_activities {};
class sm_activities_helper_freeCondition {};
class sm_activities_helper_surrenderCondition {};
class sm_activities_state_asOrdered_enter {};
class sm_activities_state_asOrdered_exit {};
class sm_activities_state_asOrdered_loop {};
class sm_activities_state_dismount_enter {};
class sm_activities_state_flight_enter {};
class sm_activities_state_flight_exit {};
class sm_activities_state_flight_loop {};
class sm_activities_state_hidden_enter {};
class sm_activities_state_hide_enter {};
class sm_activities_state_hide_exit {};
class sm_activities_state_mountUp_enter {};
class sm_activities_state_mountUp_exit {};
class sm_activities_state_patrol_enter {};
class sm_activities_state_patrol_exit {};
class sm_activities_state_rally_enter {};
class sm_activities_state_rally_loop {};
class sm_activities_state_surrendered_enter {};
class sm_activities_state_surrendered_exit {};
class sm_activities_state_voyage_enter {};
class sm_activities_state_voyage_exit {};
class sm_activities_state_voyage_loop {};
class sm_activities_trans_asOrdered_rally_condition {};
class sm_activities_trans_dismount_flight_condition {};
class sm_activities_trans_dismount_rally_condition {};
class sm_activities_trans_dismount_surrendered_condition {};
class sm_activities_trans_hidden_rally_handler {};
class sm_activities_trans_hide_hidden_condition {};
class sm_activities_trans_hide_hidden_handler {};
class sm_activities_trans_mountUp_flight_condition {};
class sm_activities_trans_mountUp_voyage_condition {};
class sm_activities_trans_rally_mountUp_condition {};
class sm_activities_trans_rally_patrol_condition {};
class sm_activities_trans_surrendered_hide_condition {};
class sm_activities_trans_surrendered_rally_condition {};
};

class sm_cleanup {
file = MODULES_DIRECTORY\grad-civs\functions\sm_cleanup;

class sm_cleanup {};
class sm_cleanup_state_despawn_enter {};
class sm_cleanup_trans_init_despawn_condition {};
};

class sm_emotions {
file = MODULES_DIRECTORY\grad-civs\functions\sm_emotions;

class sm_emotions {};
};
};
8 changes: 5 additions & 3 deletions component.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#define PREFIX GRAD
#define COMPONENT civs

/*#define DEBUG_MODE_FULL*/
//#define DEBUG_MODE_FULL
#include "\x\cba\addons\main\script_macros_mission.hpp"



#ifdef DEBUG_MODE_FULL

#define LOGTIME_START(var1) missionNamespace setVariable [var1,diag_tickTime]
#define LOGTIME_DELTAT(var1) diag_tickTime - (missionNamespace getVariable [var1,diag_tickTime])
#define LOGTIME_END(var1) LOG_SYS('PERFORMANCE',format [ARR_3('%1 took %2s',var1,LOGTIME_DELTAT(var1))]); missionNamespace setVariable [var1,nil]
#define ASSERT_SERVER(var1) if (!assert(!hasInterface || isServer)) exitWith { diag_log(var1); }
#define ASSERT_PLAYER(var1) if (!assert(hasInterface)) exitWith { diag_log(var1); }

#else

#define LOGTIME_START(var1)
#define LOGTIME_END(var1)
#define ASSERT_SERVER(var1) if (!(!hasInterface || isServer)) exitWith { diag_log(var1); }
#define ASSERT_PLAYER(var1) if (!hasInterface) exitWith { diag_log(var1); }

#endif
42 changes: 42 additions & 0 deletions docs/states.gv
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
digraph civs {
compound=true;

subgraph cluster_emotions {
clusterrank="local";
bgcolor="yellow";
emo_relaxed -> emo_wary;
{emo_wary, emo_relaxed} -> emo_panic;
emo_panic -> emo_wary -> emo_relaxed;
}

subgraph cluster_activities {
bgcolor="green";
act_rally -> act_patrol;
act_rally -> act_mountUp;
act_mountUp -> act_voyage;
act_mountUp -> act_dismount;

act_flight -> act_hide;
act_hide -> act_hidden;

{act_hidden, act_rally, act_patrol, act_dismount} -> act_surrendered;
{act_rally, act_patrol, act_asOrdered} -> act_flight [color=red];

act_voyage -> act_dismount [color=red]; # panic event
act_voyage -> act_dismount;

act_dismount -> act_flight;
act_mountUp -> act_flight;

{act_flight, act_hide, act_hidden} -> act_rally [color=blue] #de-panic event

{act_init, act_dismount, act_surrendered} -> act_rally;

act_surrendered -> act_hide;

{act_rally, act_patrol, act_surrendered} -> act_asOrdered [color=red];

act_asOrdered -> act_rally
}
}
<
Loading

0 comments on commit b7971ac

Please sign in to comment.