Missing Files

This commit is contained in:
icomrade
2016-02-29 00:55:29 -05:00
parent 64c251d95d
commit 84eb6f815a
75 changed files with 6780 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
#ifndef _INCLUDE_GUARD_LOOT
#define _INCLUDE_GUARD_LOOT
#include "\z\addons\dayz_code\Configs\CfgLoot\LootDefines.hpp"
#define Loot_GetGroup(name) (dz_loot_groups find (name))
#define Loot_Select(group, count) ([group, count] call dz_fn_loot_select)
#define Loot_SelectSingle(group) (Loot_Select(group, 1) select 0)
#define Loot_Spawn(def, loc) ([def, loc] call dz_fn_loot_spawn)
#define Loot_SpawnGroup(group, loc) ([group, loc] call dz_fn_loot_spawnGroup)
#define Loot_Insert(unit, group, count) ([unit, group, count] call dz_fn_loot_insert)
#define Loot_InsertCargo(object, group, count) ([object, group, count] call dz_fn_loot_insertCargo)
#endif

View File

@@ -0,0 +1,13 @@
#define STRINGIFY(x) #x
#define NAME(name) dz_fn_loot_##name
#define PATH(sub_path) STRINGIFY(\z\addons\dayz_code\loot\sub_path)
#define CPP compile preprocessFileLineNumbers
NAME(select) = CPP PATH(select.sqf);
NAME(spawn) = CPP (if (isServer) then { PATH(spawn_server.sqf) } else { PATH(spawn.sqf) });
NAME(spawnGroup) = CPP PATH(spawnGroup.sqf);
NAME(insert) = CPP PATH(insert.sqf);
NAME(insertCargo) = CPP PATH(insertCargo.sqf);
//Loot init
call CPP PATH(init.sqf);

141
SQF/dayz_code/loot/init.sqf Normal file
View File

@@ -0,0 +1,141 @@
#include "\z\addons\dayz_code\util\math.hpp"
#include "Loot.hpp"
//If defined, minimizes memory usage at the expense of initialization time.
//#define MINIMIZE_MEMORY
private
[
"_cfgGroups",
"_cfg",
"_lootGroup",
"_weight",
"_weighted",
"_index",
"_indices",
"_count",
"_gcd"
];
#ifdef MINIMIZE_MEMORY
private ["_lootDefCompare", "_y", "_a", "_b", "_r"];
_lootDefCompare =
{
_a = _this select 0;
_b = _this select 1;
if ((_a select 0) != (_b select 0)) exitWith { false };
if ((_a select 1) != (_b select 1)) exitWith { false };
_r = true;
switch (_a select 0) do
{
case Loot_PILE:
{
_r = ((_a select 2) == (_b select 2)) &&
{(_a select 3) == (_b select 3)};
};
case Loot_CONTAINER:
{
_r = ((_a select 2) == (_b select 2)) &&
{(_a select 3) == (_b select 3)} &&
{(_a select 4) == (_b select 4)};
};
};
_r
};
#endif
dz_loot_groups = [];
dz_loot_weighted = [];
dz_loot_definitions = [];
_cfgGroups = (configFile >> "CfgLoot" >> "Groups");
for "_i" from 0 to (count _cfgGroups) - 1 do
{
_cfg = _cfgGroups select _i;
dz_loot_groups set [_i, configName _cfg];
};
dz_loot_weighted resize count dz_loot_groups;
for "_i" from 0 to (count _cfgGroups) - 1 do
{
_lootGroup = getArray (_cfgGroups select _i);
_weighted = [];
if ((count _lootGroup) > 0) then
{
_indices = [];
_indices resize count _lootGroup;
{
_weight = _x select 1;
//Remove weight from _x
for "_j" from 1 to (count _x) - 2 do { _x set [_j, _x select (_j + 1)]; };
_x resize ((count _x) - 1);
_index = -1;
//Search for an existing identical loot definition
#ifdef MINIMIZE_MEMORY
_y = _x;
{
if ([_y, _x] call _lootDefCompare) exitWith
{
_index = _forEachIndex;
};
}
foreach dz_loot_definitions;
#endif
//Existing loot definition not found, add it and set the index to point to the new definition
if (_index == -1) then
{
_index = count dz_loot_definitions;
dz_loot_definitions set [_index, _x];
};
_lootGroup set [_forEachIndex, round(_weight * 100)];
_indices set [_forEachIndex, _index];
}
foreach _lootGroup;
//Calculate GCD of all the weights
_gcd = Math_GCDArray(_lootGroup);
//_gcd = _lootGroup call math_gcdx;
_count = 0;
{
_weight = _x / _gcd;
_weighted resize (_count + _weight);
for "_j" from _count to (_count + _weight - 1) do
{
_weighted set [_j, _indices select _forEachIndex];
};
_count = _count + _weight;
}
foreach _lootGroup;
};
dz_loot_weighted set [_i, _weighted];
};
{
switch (_x select 0) do
{
case Loot_GROUP: { _x set [1, dz_loot_groups find (_x select 1)]; };
case Loot_PILE: { _x set [1, dz_loot_groups find (_x select 1)]; };
case Loot_CONTAINER: { _x set [2, dz_loot_groups find (_x select 2)]; };
case Loot_CUSTOM: { _x set [1, compile (_x select 1)]; };
};
}
foreach dz_loot_definitions;

View File

@@ -0,0 +1,48 @@
/*
Selects random loot from specified group and inserts into a unit.
Loot group should only contain Loot_WEAPON and Loot_MAGAZINE definitions. Others, if selected, will be ignored.
Parameters:
object Unit to insert into.
integer Loot group index in dayz_lootGroups
integer Number of items to insert.
Author:
Foxy
*/
#include "\z\addons\dayz_code\util\debug.hpp"
#include "Loot.hpp"
if (!local (_this select 0)) exitWith
{
diag_log format ["ERROR: Loot_Insert unit must be local. (%1)", _this select 0];
};
{
switch (_x select 0) do
{
case Loot_WEAPON:
{
(_this select 0) addWeapon (_x select 1);
Debug_Assert(typeName (_x select 1) == typeName "" && { (_x select 1) != "" });
//Debug_Log(String_Format2("DEBUG: Loot_Insert Weapon: %1 Unit: %2", _x select 1, _this select 0));
};
case Loot_MAGAZINE:
{
(_this select 0) addMagazine (_x select 1);
};
case Loot_BACKPACK:
{
if (!isNull unitBackpack (_this select 0)) then
{
(_this select 0) addBackpack (_x select 1);
};
};
};
}
foreach Loot_Select(_this select 1, _this select 2);
//foreach ([_this select 1, _this select 2] call loot_select);

View File

@@ -0,0 +1,40 @@
/*
Selects random loot from specified group and inserts into a container.
Loot group should only contain Loot_WEAPON and Loot_MAGAZINE definitions. Others, if selected, will be ignored.
Parameters:
object Vehicle to insert into.
integer Loot group index in dayz_lootGroups
integer Number of items to insert.
Author:
Foxy
*/
#include "\z\addons\dayz_code\util\debug.hpp"
#include "Loot.hpp"
{
switch (_x select 0) do
{
case Loot_WEAPON:
{
(_this select 0) addWeaponCargoGlobal [_x select 1, 1];
Debug_Assert(typeName (_x select 1) == typeName "" && { (_x select 1) != "" });
//Debug_Log(String_Format2("DEBUG: Loot_Insert Weapon: %1 Vehicle: %2", _x select 1, _this select 0));
};
case Loot_MAGAZINE:
{
(_this select 0) addMagazineCargoGlobal [_x select 1, 1];
};
case Loot_BACKPACK:
{
(_this select 0) addBackpackCargoGlobal [_x select 1, 1];
};
};
}
foreach Loot_Select(_this select 1, _this select 2);
//foreach ([_this select 1, _this select 2] call loot_select);

View File

@@ -0,0 +1,48 @@
/*
Selects random items from loot tables defined in bin\config.bin/CfgLoot/Groups
Parameters:
integer Loot group index
integer Number of items to select.
Author:
Foxy
*/
#include "Loot.hpp"
private
[
"_lootGroup",
"_lootNum",
"_result",
"_weighted",
"_def",
"_sub"
];
_lootGroup = _this select 0;
_lootNum = _this select 1;
if (_lootNum < 1 || _lootGroup < 0) exitWith { [] };
//Initialize the result array
_result = [];
_result resize _lootNum;
_weighted = dz_loot_weighted select _lootGroup;
for "_i" from 0 to _lootNum - 1 do
{
_def = dz_loot_definitions select (_weighted select floor random count _weighted);
while {(_def select 0) == Loot_GROUP} do
{
_sub = dz_loot_weighted select (_def select 1);
_def = dz_loot_definitions select (_sub select floor random count _sub);
};
_result set [_i, _def];
};
_result

View File

@@ -0,0 +1,149 @@
/*
Spawns the specified loot definition at the specified location.
Parameters:
array Loot definition
vector Spawn position relative to world
Return value:
object Spawned vehicle.
Author:
Foxy
*/
#include "\z\addons\dayz_code\util\debug.hpp"
#include "\z\addons\dayz_code\util\vector.hpp"
#include "Loot.hpp"
//Maximum number of magazines spawned along with weapons
#define MAX_WEAPON_MAGAZINES 2
//If defined spawns random (but applicable) magazines along with weapons instead of their primary type.
//#define COMPLEX_WEAPON_MAGAZINES
//If defined calculates better placement for backpacks
//#define COMPLEX_BACKPACK_POSITION
#ifdef SERVER
#define INCREMENT_WEAPON_HOLDERS()
#else
#define INCREMENT_WEAPON_HOLDERS() dayz_currentWeaponHolders = dayz_currentWeaponHolders + 1
#endif
private
[
"_lootInfo",
"_vehicle",
"_spawnCount",
"_magazines"
];
_lootInfo = _this select 0;
_vehicle = objNull;
//Switch on type of loot
switch (_lootInfo select 0) do
{
//Spawn a single weapon with [0,MAX_WEAPON_MAGAZINES] magazines.
case Loot_WEAPON:
{
_vehicle = createVehicle ["WeaponHolder", _this select 1, [], 0, "CAN_COLLIDE"];
_vehicle addWeaponCargoGlobal [_lootInfo select 1, 1];
Debug_Assert(typeName (_lootInfo select 1) == typeName "" && { (_lootInfo select 1) != "" });
//Debug_Log(String_Format2("DEBUG: Loot_Spawn Weapon: %1 Position: %2", _lootInfo select 1, _this select 1));
_vehicle setPosATL (_this select 1);
INCREMENT_WEAPON_HOLDERS();
_magazines = getArray (configFile >> "CfgWeapons" >> _lootInfo select 1 >> "magazines");
if (count _magazines > 0 && {getNumber (configFile >> "CfgWeapons" >> _lootInfo select 1 >> "melee") != 1}) then
{
#ifdef COMPLEX_WEAPON_MAGAZINES
for "_i" from 1 to (floor random (MAX_WEAPON_MAGAZINES + 1)) do
{
_vehicle addMagazineCargoGlobal [_magazines select floor random count _magazines, 1];
};
#else
_vehicle addMagazineCargoGlobal [_magazines select 0, floor random (MAX_WEAPON_MAGAZINES + 1)];
#endif
};
};
//Spawn a single magazine
case Loot_MAGAZINE:
{
_vehicle = createVehicle ["WeaponHolder", _this select 1, [], 0, "CAN_COLLIDE"];
_vehicle addMagazineCargoGlobal [_lootInfo select 1, 1];
_vehicle setPosATL (_this select 1);
INCREMENT_WEAPON_HOLDERS();
};
//Spawn backpack
case Loot_BACKPACK:
{
#ifdef COMPLEX_BACKPACK_POSITION
private ["_b", "_p", "_d"];
_vehicle = createVehicle [_lootInfo select 1, [-10000,0,0], [], 0, "CAN_COLLIDE"];
_b = boundingBox _vehicle;
_b = ((_b select 1) select 1) - ((_b select 0) select 1);
_d = Vector_Rotate2D(Vector_NORTH, random 360);
_p = Vector_Subtract(_this select 1, Vector_Multiply_Fast(_d, _b));
_p = Vector_SetZ(_p, Vector_Z(_p) + Vector_Z(getPosATL _vehicle));
_vehicle setVectorDirAndUp [Vector_DOWN, _d];
_vehicle setPosATL _p;
#else
_vehicle = createVehicle [_lootInfo select 1, _this select 1, [], 0, "CAN_COLLIDE"];
_vehicle setPosATL (_this select 1);
#endif
};
//Spawn multiple items from a given group. All but weapons and magazines are ignored.
case Loot_PILE:
{
_spawnCount = (_lootInfo select 2) + floor random ((_lootInfo select 3) - (_lootInfo select 2) + 1);
_vehicle = createVehicle ["WeaponHolder", _this select 1, [], 0, "CAN_COLLIDE"];
Loot_InsertCargo(_vehicle, _lootInfo select 1, _spawnCount);
_vehicle setPosATL (_this select 1);
INCREMENT_WEAPON_HOLDERS();
};
//Spawn a vehicle
case Loot_VEHICLE:
{
_vehicle = createVehicle [_lootInfo select 1, _this select 1, [], 0, "CAN_COLLIDE"];
_vehicle setDir random 360;
_vehicle setPosATL (_this select 1);
};
//Spawn a container and populate it with loot from a given group
case Loot_CONTAINER:
{
_vehicle = createVehicle [_lootInfo select 1, _this select 1, [], 0, "CAN_COLLIDE"];
INCREMENT_WEAPON_HOLDERS();
//Number of items to spawn
_spawnCount = (_lootInfo select 3) + floor random ((_lootInfo select 4) - (_lootInfo select 3) + 1);
Loot_InsertCargo(_vehicle, _lootInfo select 2, _spawnCount);
_vehicle setDir random 360;
_vehicle setPosATL (_this select 1);
};
//Call a function which is assumed to return an object reference.
case Loot_CUSTOM:
{
_vehicle = call (_lootInfo select 1);
if ((typeName _vehicle) != "OBJECT") exitWith {};
if (!isNull _vehicle) then { _vehicle setPosATL (_this select 1); };
};
};
_vehicle

View File

@@ -0,0 +1,18 @@
/*
Spawns randomly selected loot from given group.
Parameters:
integer Loot group index in dayz_lootGroups
vector Spawn position relative to world
Return value:
object Spawned vehicle.
Author:
Foxy
*/
#include "Loot.hpp"
Loot_Spawn(Loot_Select(_this select 0, 1) select 0, _this select 1);
//[([_this select 0, 1] call loot_select) select 0, _this select 1] call loot_spawn

View File

@@ -0,0 +1,2 @@
#define SERVER
#include "spawn.sqf"