Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add scripted garrison waypoint #438

Merged
merged 1 commit into from
Jul 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions addons/ai/CfgWaypoints.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

class CfgWaypoints {
class A3 { // called "Advanced"
class CBA_Task_Garrison {
displayName = "GARRISON"; // all caps
Copy link
Contributor

@Killswitch00 Killswitch00 Jul 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the display string in the stringtable.xml so it can be translated

EDIT: Hmm...the core game ones are not stringtable:d ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was about to write that. unlocalized and all caps. probably to get consistency with the scripting commands. https://community.bistudio.com/wiki/setWaypointType

displayNameDebug = "CBA_Task_Garrison";
file = QPATHTOF(fnc_waypointGarrison.sqf);
icon = "\a3\3DEN\Data\CfgWaypoints\GetInNearest_ca.paa";
};
};
};
1 change: 1 addition & 0 deletions addons/ai/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ class CfgPatches {
};

#include "CfgFunctions.hpp"
#include "CfgWaypoints.hpp"
60 changes: 60 additions & 0 deletions addons/ai/fnc_waypointGarrison.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_waypointGarrison

Description:
Scripted waypoint that makes group garrision nearby buildings and static weapons.

Parameters:
0: Group <GROUP>
1: Waypoint position <ARRAY>

Returns:
true <BOOLEAN>

Author:
commy2
---------------------------------------------------------------------------- */
#include "script_component.hpp"

#define POP_RAND(array) (array deleteAt floor random count array)

params ["_group", "_position"];

// leader should not issue attack orders
_group enableAttack false;

private _staticWeapons = _position nearObjects ["StaticWeapon", 50] select {_x emptyPositions "gunner" > 0};
private _buildings = (_position nearObjects ["Building", 50]) apply {_x buildingPos -1} select {count _x > 0};

{
if (count _staticWeapons > 0 && {random 1 < 0.31}) then {
_x assignAsGunner (_staticWeapons deleteAt 0);
[_x] orderGetIn true;
} else {
if (count _buildings > 0 && {random 1 < 0.93}) then {
private _building = selectRandom _buildings;
private _position = POP_RAND(_building);

// if building positions are all taken, remove from possible buildings
if (_building isEqualTo []) then {
_buildings = _buildings select {count _x > 0};
};

// prevent units from crouching or going prone
_x setUnitPos "UP";

// doMoveAndStay
[_x, _position] spawn {
params ["_unit", "_position"];

_unit doMove _position;
waitUntil {unitReady _unit};
doStop _unit;
};
} else {
_x doMove _position;
};
};
} forEach units _group;

true