added persistant weather mod

This commit is contained in:
Zepheris 2018-03-03 11:32:21 -07:00
parent e3c5e377e7
commit 74d5668d41
13 changed files with 566 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,32 @@
class CfgPatches
{
class PTWS {
units[] = {};
weapons[] = {};
requiredVersion = 0.1;
requiredAddons[] = {"exile_server"};
author[]= {"MajorXAcE"};
};
};
class CfgFunctions {
class PTWS {
class main {
class postInit
{
postInit = 1;
file = "\PTWS\initServer.sqf";
};
};
class compiles
{
file = "\PTWS\scripts";
class saveDate {};
class saveWeather {};
class controlWeather {};
class timeAcc {};
};
};
};

View File

@ -0,0 +1,15 @@
PTWS_ID = "PTWS"; // The name of the id that will be in database, if changed the system will create a new entry and start over.
PTWS_StartingDate = [2016,8,22,12,0]; // The date that the server will start on NOTE: Must be in this format [year, month, day, hour, minute] see https://community.bistudio.com/wiki/date
PTWS_StartingWeather = [0,0,[0,0,0],[0,0,false],0,0,0,0,0]; //The weather parameters that the server will start with. NOTE: Must be in this format [overcast,rain,[fogValue, fogDecay, fogBase],[windx, windy, forced],gusts,lightnings,waves]
PTWS_timeAcc = true; // Enables/Disables the time multipliers for day and night.
PTWS_timeAccNightStart = 18; // The 24hr time that the night multiplier starts. Default: 18 = 6:00PM
PTWS_timeAccDayStart = 6; // The 24hr time that the day multiplier starts. Default:6 = 6:00AM
PTWS_timeAccMultiplierNight = 8; //The multiplier for night time acceleration. Default: 6x = 2 hour nights
PTWS_timeAccMultiplierDay = 8; //The multiplier for day time acceleration. Default: 4x = 3 hour days
PTWS_weatherChangeFast = false; //If set to true, the weather will change every PTWS_weatherChangeMin seconds, if false it will change sometime between PTWS_weatherChangeMax and PTWS_weatherChangeMin.
PTWS_weatherChangeMax = 5400;
PTWS_weatherChangeMin = 900;
PTWS_CompiledOkay = true;

View File

@ -0,0 +1,22 @@
[] spawn
{
waitUntil {time > 0};
diag_log "PTWS - Loading Config";
// Get the config for PTWS
call compile preprocessFileLineNumbers "\PTWS\config.sqf";
//Borrowed from second_coming's occupation mod.
if(isNil "PTWS_CompiledOkay") exitWith { diag_log "PTWS - Failed to read config.sqf, check for typos."; };
diag_log "PTWS - Initialized";
// Start PTWS
//DonkeyPunch - DirtySanchez add database check for known ID if none then populate it with config setup information
_isKnownPTWSDateID = format ["isKnownPTWSID:%1", PTWS_ID] call ExileServer_system_database_query_selectSingleField;
if!(_isKnownPTWSDateID)then
{
_insertPTWSDateID = format["createDate:%1", PTWS_ID] call ExileServer_system_database_query_insertSingle;
};
sleep 1;
[]execVM "\PTWS\scripts\startPTWS.sqf";
};

View File

@ -0,0 +1,66 @@
/*
Author: code34 nicolas_boiteux@yahoo.fr
Copyright (C) 2013-2015 Nicolas BOITEUX
Real weather for MP GAMES v 1.3 adapted for PTWS
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
private ["_lastrain","_rain","_overcast","_fogValue","_fogDecay","_fogHeight","_wind"];
_lastrain = rain;
_rain = 0;
_overcast = 0;
_fogValue = 0;
_fogDecay = 0;
_fogHeight =0;
_wind = [0,0,true];
_overcast = random 1;
if(_overcast > 0.5) then {
_rain = random 0.5;
} else {
_rain = 0;
};
if((date select 3 > 5) and (date select 3 <10)) then {
_fogValue = 0.2 + (random 0.8);
_fogDecay = 0.2;
_fogHeight = random 20;
} else {
if((_lastrain > 0.6) and (_rain < 0.2)) then {
_fogValue = random 0.4;
_fogDecay = 0;
_fogHeight = 0;
} else {
_fogValue = 0;
_fogDecay = 0;
_fogHeight = 0;
};
};
if(random 1 > 0.95) then
{
_wind = [random 7, random 7, true];
}
else
{
_wind = [random 3, random 3, false];
};
wcweather = [_rain, [_fogValue,_fogDecay,_fogHeight], _overcast, _wind, date];
60 setRain (wcweather select 0);
60 setfog (wcweather select 1);
60 setOvercast (wcweather select 2);
setwind (wcweather select 3);

View File

@ -0,0 +1,9 @@
private["_currentdate","_data","_extDB2Message"];
_currentdate = date;
_data =
[
_currentdate,
PTWS_ID
];
_extDB2Message = ["setDate", _data] call ExileServer_util_extDB2_createMessage;
_extDB2Message call ExileServer_system_database_query_fireAndForget;

View File

@ -0,0 +1,10 @@
private["_currentWeather","_data","_extDB2Message"];
_windDB = [wind select 0, wind select 1, false];
_currentWeather = [overcast,rain,fogParams,_windDB,gusts,lightnings,waves];
_data =
[
_currentWeather,
PTWS_ID
];
_extDB2Message = ["setWeather", _data] call ExileServer_util_extDB2_createMessage;
_extDB2Message call ExileServer_system_database_query_fireAndForget;

View File

@ -0,0 +1,12 @@
//Borrowed the the template from second_coming's occupation mod.
private["_timeMultiplier"];
if (daytime > PTWS_timeAccNightStart || daytime < PTWS_timeAccDayStart) then
{
_timeMultiplier = PTWS_timeAccMultiplierNight;
}
else
{
_timeMultiplier = PTWS_timeAccMultiplierDay;
};
if(timeMultiplier != _timeMultiplier) then { setTimeMultiplier _timeMultiplier; };

View File

@ -0,0 +1,12 @@
private["_checkDatabaseID","_insertDatabaseID"];
if (!isServer) exitWith {};
_checkDatabaseID = profileNamespace getVariable ["PTWS_DatabaseID",false];
if !(_checkDatabaseID isEqualTo PTWS_ID) then
{
profileNamespace setVariable ["PTWS_DatabaseID",PTWS_ID];
saveProfileNamespace;
_insertDatabaseID = format["createDate:%1", PTWS_ID] call ExileServer_system_database_query_insertSingle;
_insertDatabaseID;
};

View File

@ -0,0 +1,89 @@
private["_saveddate","_savedWeather","_overcast","_rain","_fog","_wind","_gusts","_lightnings","_waves","_timeforecast","_timeforecastMinutes"];
if (!isServer) exitWith {};
_saveddate = format ["getDate:%1", PTWS_ID] call ExileServer_system_database_query_selectSingleField;
_savedWeather = format ["getWeather:%1", PTWS_ID] call ExileServer_system_database_query_selectSingleField;
diag_log format["PTWSDebug:db data - date:%1 weather:%2",_saveddate,_savedWeather];
if (typeName _saveddate isEqualTo "ARRAY") then
{
diag_log format["PTWS - Loading last saved date : %1", _saveddate];
setDate _saveddate;
}
else
{
setDate PTWS_StartingDate;
diag_log format["PTWS - No saved date found, loading PTWS_StartingDate:%1",PTWS_StartingDate];
};
if (typeName _savedWeather isEqualTo "ARRAY") then
{
diag_log format["PTWS - Loading last saved weather : %1", _savedWeather];
_overcast = _savedWeather select 0;
_rain = _savedWeather select 1;
_fog = _savedWeather select 2;
_wind = _savedWeather select 3;
_gusts = _savedWeather select 4;
_lightnings = _savedWeather select 5;
_waves = _savedWeather select 6;
0 setovercast _overcast;
0 setrain _rain;
0 setfog _fog;
setwind _wind;
0 setgusts _gusts;
0 setlightnings _lightnings;
0 setwaves _waves;
forceWeatherChange;
}
else
{
diag_log format["PTWS - No saved weather found, loading PTWS_StartingWeather:%1",PTWS_StartingWeather];
_overcast = PTWS_StartingWeather select 0;
_rain = PTWS_StartingWeather select 1;
_fog = PTWS_StartingWeather select 2;
_wind = PTWS_StartingWeather select 3;
_gusts = PTWS_StartingWeather select 4;
_lightnings = PTWS_StartingWeather select 5;
_waves = PTWS_StartingWeather select 6;
0 setovercast _overcast;
0 setrain _rain;
0 setfog _fog;
setwind _wind;
0 setgusts _gusts;
0 setlightnings _lightnings;
0 setwaves _waves;
forceWeatherChange;
};
diag_log "PTWS - SaveDate Initialized";
//Thanks WolfkillArcadia!
[60, PTWS_fnc_saveDate, [], true] call ExileServer_system_thread_addTask;
diag_log "PTWS - SaveWeather Initialized";
[60, PTWS_fnc_saveWeather, [], true] call ExileServer_system_thread_addTask;
[] spawn {
diag_log "PTWS - ControlWeather Initialized";
while {true} do {
call PTWS_fnc_controlWeather;
if(PTWS_weatherChangeMin > PTWS_weatherChangeMax) exitwith {hint format["PTWS - Max time: %1 must to be higher than Min time: %2", PTWS_weatherChangeMax, PTWS_weatherChangeMin];};
_timeforecast = PTWS_weatherChangeMin;
if !(PTWS_weatherChangeFast) then {
_timeforecast = PTWS_weatherChangeMin + (random (PTWS_weatherChangeMax - PTWS_weatherChangeMin));
};
_timeforecastMinutes = [_timeforecast,"HH:MM:SS"] call BIS_fnc_secondsToString;
diag_log format ["PTWS - Time until next forecast:%1",_timeforecastMinutes];
uiSleep _timeforecast;
};
};
if (PTWS_timeAcc) then
{
diag_log "PTWS - TimeAcc Initialized";
[60, PTWS_fnc_timeAcc, [], true] call ExileServer_system_thread_addTask;
};

View File

@ -0,0 +1,200 @@
/**
* ExileClient_object_player_stats_updateTemperature
*
* Exile Mod
* www.exilemod.com
* © 2015 Exile Mod Team
*
* This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
*/
private["_timeElapsed","_forcedBodyTemperatureChangePerMinute","_wetnessChangePerMinute","_altitude","_isSwimming","_bodyTemperature","_bodyWetness","_temperatureConfig","_fromDayTimeTemperature","_toDayTimeTemperature","_environmentTemperature","_playerIsInVehicle","_playerVehicle","_isFireNearby","_startPosition","_endPosition","_intersections","_isBelowRoof","_clothingColdProtection","_movementInfluence","_regulation","_environmentInfluence"];
/*
// PTWS Season Temperature Control
*/
_month = date select 1;
_season = "";
_WinterEnd = 1;
_SpringEnd = 4;
_SummerEnd = 7;
_FallEnd = 10;
if ((_month > _WinterEnd) && (_month <= _SpringEnd)) then // The season will be the month after _PreviousSeasonEnd and the months upto and including _ThisSeasonEnd ex. Spring starts on Feb and ends in Apr.
{
_season = "Spring";
};
if ((_month > _SpringEnd) && (_month <= _SummerEnd)) then
{
_season = "Summer";
};
if ((_month > _SummerEnd) && (_month <= _FallEnd)) then
{
_season = "Fall";
};
if (_month == 11 || _month == 12 || _month == 1) then //The previous conditions won't work when the season includes December: 12 and January: 1 because x cannot be both >= 12 and =< 1;
{
_season = "Winter";
};
_mapOverride = true; //Set true if you want the season to stay the same for specific maps, you can add more below.
if (_mapOverride) then
{
switch (toLower worldName) do {
case "tanoa": { _season = "Summer"; };
case "namalsk": { _season = "Fall"; };
};
};
//diag_log format["PTWS - Current Season:%1",_season];
_seasonDaytimeTemperature = [];
//Switches the daytimeTemperature array based on the season, this replace the values in the mission config.
switch (_season) do {
case "Winter": { _seasonDaytimeTemperature = [-6.93,-5.89,-4.42,-3.40,-2.68,-1.10,1.48,2.63,3.40,4.66,5.32,6.80,6.80,5.32,4.66,3.40,2.63,1.48,-1.10,-2.68,-3.40,-4.42,-5.89,-6.93,-7.93]; };
case "Spring": { _seasonDaytimeTemperature = [9,11,14,17,20,24,26,27,28,28,28,27,26,28,28,28,27,26,24,20,17,14,11,9,8]; };
case "Summer": { _seasonDaytimeTemperature = [15.93,16.89,18.42,20.40,22.68,25.10,27.48,29.63,31.40,32.66,33.32,33.80,33.80,33.32,32.66,31.40,29.63,27.48,25.10,22.68,20.40,18.42,16.89,15.93,15.93]; };
case "Fall": { _seasonDaytimeTemperature = [-2.00,-1.77,-1.12,-0.10,1.24,2.78,4.40,6.00,7.46,8.65,9.50,9.90,9.90,9.50,8.65,7.46,6.00,4.40,2.78,1.24,-0.10,-1.12,-1.77,-2.00,-2.00]; };
};
//diag_log format["PTWS - Current Temperature Array:%1",_seasonDaytimeTemperature];
/*
// PTWS Season Temperature Control
*/
_timeElapsed = _this;
_forcedBodyTemperatureChangePerMinute = 0;
_wetnessChangePerMinute = -0.1;
_altitude = ((getPosASL player) select 2) max 0;
_isSwimming = (_altitude < 0.1) || (underwater player);
_bodyTemperature = ExileClientPlayerAttributes select 5;
_bodyWetness = ExileClientPlayerAttributes select 6;
_temperatureConfig = missionConfigFile >> "CfgExileEnvironment" >> worldName >> "Temperature";
//_fromDayTimeTemperature = (getArray (_temperatureConfig >> "daytimeTemperature")) select (date select 3);
//_toDayTimeTemperature = (getArray (_temperatureConfig >> "daytimeTemperature")) select ((date select 3) + 1);
_fromDayTimeTemperature = _seasonDaytimeTemperature select (date select 3);
_toDayTimeTemperature = _seasonDaytimeTemperature select ((date select 3) + 1);
_environmentTemperature = [_fromDayTimeTemperature, _toDayTimeTemperature, (date select 4) / 60] call ExileClient_util_math_lerp;
_environmentTemperature = _environmentTemperature + overcast * (getNumber (_temperatureConfig >> "overcast"));
_environmentTemperature = _environmentTemperature + rain * (getNumber (_temperatureConfig >> "rain"));
_environmentTemperature = _environmentTemperature + windStr * (getNumber (_temperatureConfig >> "wind"));
_environmentTemperature = _environmentTemperature + _altitude / 100 * (getNumber (_temperatureConfig >> "altitude"));
if (_isSwimming) then
{
_environmentTemperature = _environmentTemperature + (getNumber (_temperatureConfig >> "water"));
};
ExileClientEnvironmentTemperature = _environmentTemperature;
_playerIsInVehicle = false;
_playerVehicle = vehicle player;
if !(_playerVehicle isEqualTo player) then
{
try
{
if (_playerVehicle isKindOf "Exile_Bike_QuadBike_Abstract") throw false;
if (_playerVehicle isKindOf "Exile_Bike_OldBike") throw false;
if (_playerVehicle isKindOf "Exile_Bike_MountainBike") throw false;
throw true;
}
catch
{
_playerIsInVehicle = _exception;
};
};
if (_playerIsInVehicle) then
{
if (isEngineOn _playerVehicle) then
{
_forcedBodyTemperatureChangePerMinute = 0.05;
_wetnessChangePerMinute = -0.5;
}
else
{
_forcedBodyTemperatureChangePerMinute = 0.01;
_wetnessChangePerMinute = -0.2;
};
}
else
{
if (_isSwimming) then
{
_wetnessChangePerMinute = 99999;
}
else
{
_isFireNearby = [ASLtoAGL (getPosASL player), 5] call ExileClient_util_world_isFireInRange;
if (_isFireNearby) then
{
_forcedBodyTemperatureChangePerMinute = 1;
_wetnessChangePerMinute = -0.5;
}
else
{
if (rain > 0.1) then
{
_startPosition = getPosASL player;
_endPosition = [_startPosition select 0, _startPosition select 1, (_startPosition select 2 ) + 10];
_intersections = lineIntersectsSurfaces [_startPosition, _endPosition, player, objNull, false, 1, "GEOM", "VIEW"];
_isBelowRoof = !(_intersections isEqualTo []);
if !(_isBelowRoof) then
{
_wetnessChangePerMinute = rain;
};
};
};
};
};
_bodyWetness = ((_bodyWetness + _wetnessChangePerMinute / 60 * _timeElapsed) max 0) min 1;
if (ExileClientEnvironmentTemperature > 25) then
{
_forcedBodyTemperatureChangePerMinute = 0.5;
};
if (_forcedBodyTemperatureChangePerMinute > 0) then
{
_bodyTemperature = _bodyTemperature + _forcedBodyTemperatureChangePerMinute / 60 *_timeElapsed;
}
else
{
_clothingColdProtection = 0;
if !((uniform player) isEqualTo "") then
{
_clothingColdProtection = _clothingColdProtection + 0.25;
};
if !((headgear player) isEqualTo "") then
{
_clothingColdProtection = _clothingColdProtection + 0.05;
};
if !((vest player) isEqualTo "") then
{
_clothingColdProtection = _clothingColdProtection + 0.10;
};
_clothingColdProtection = ((_clothingColdProtection * (1 - (_bodyWetness * 0.5))) max 0) min 1;
_movementInfluence = 0;
if ((getPos player) select 2 < 0.1) then
{
_movementInfluence = (37 - _bodyTemperature) * (1 - (_bodyWetness * 0.5)) * 0.075 * (vectorMagnitude (velocity player))/6.4;
};
if (_bodyTemperature < 37) then
{
_regulation = 0.1;
}
else
{
_regulation = -0.1;
};
_environmentInfluence = (1 - _clothingColdProtection) * (-0.2 + 0.008 * ExileClientEnvironmentTemperature);
_bodyTemperature = _bodyTemperature + (_regulation + _movementInfluence + _environmentInfluence) / 60 *_timeElapsed;
};
_bodyTemperature = _bodyTemperature min 37;
if (_bodyTemperature < 35) then
{
player setDamage ((damage player) + 0.1/60*_timeElapsed);
};
ExileClientPlayerAttributes set [6, _bodyWetness];
ExileClientPlayerAttributes set [5, _bodyTemperature];

View File

@ -0,0 +1,68 @@
/**
* ExileClient_system_snow_thread_update
*
* Exile Mod
* www.exilemod.com
* © 2015 Exile Mod Team
*
* This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
*/
private["_enableSnow","_surfaceTypes","_posASL"];
_enableSnow = false;
_posASL = (getPosASL player select 2);
/*
if (rain < 0.01) then
{
_surfaceTypes = getArray (missionConfigFile >> "CfgExileEnvironment" >> worldName >> "Snow" >> "surfaces");
if ((surfaceType (getPos player)) in _surfaceTypes) then
{
_enableSnow = true;
ExileSnowClose attachTo [vehicle player, [0, 4, 1]];
ExileSnowNear attachTo [vehicle player, [0, 4, 1.5]];
ExileSnowFar attachTo [vehicle player, [0, 4, 2]];
};
};
if (_enableSnow) then
{
ExileSnowClose attachTo [vehicle player, [0, 4, 1]];
ExileSnowNear attachTo [vehicle player, [0, 4, 1.5]];
ExileSnowFar attachTo [vehicle player, [0, 4, 2]];
ExileSnowClose setDropInterval 0.01;
ExileSnowNear setDropInterval 0.01;
ExileSnowFar setDropInterval 0.01;
}
else
{
ExileSnowClose setDropInterval 0;
ExileSnowNear setDropInterval 0;
ExileSnowFar setDropInterval 0;
};
*/
_environmentTemperatureValue = format ["%1", [ExileClientEnvironmentTemperature, 1] call ExileClient_util_math_round];
_environmentTemperature = parseNumber _environmentTemperatureValue;
//diag_log format["PTWS - Current Temperature:%1",_environmentTemperature];
if ((0 >= _environmentTemperature) && (overcast >= 0.3)) then
{
_enableSnow = true;
ExileSnowClose attachTo [vehicle player, [0, 4, 1]];
ExileSnowNear attachTo [vehicle player, [0, 4, 1.5]];
ExileSnowFar attachTo [vehicle player, [0, 4, 2]];
};
if (_enableSnow) then
{
ExileSnowClose attachTo [vehicle player, [0, 4, 1]];
ExileSnowNear attachTo [vehicle player, [0, 4, 1.5]];
ExileSnowFar attachTo [vehicle player, [0, 4, 2]];
ExileSnowClose setDropInterval 0.01;
ExileSnowNear setDropInterval 0.01;
ExileSnowFar setDropInterval 0.01;
}
else
{
ExileSnowClose setDropInterval 0;
ExileSnowNear setDropInterval 0;
ExileSnowFar setDropInterval 0;
};

View File

@ -0,0 +1,31 @@
/**
* ExileServer_system_weather_initialize
*
* Exile Mod
* www.exilemod.com
* © 2015 Exile Mod Team
*
* This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
*/
private["_useRealTime","_useStaticTime","_staticTime","_changetime"];
//call ExileServer_system_weather_thread_weatherSimulation;
_useRealTime = getNumber (configFile >> "CfgSettings" >> "Time" >> "useRealTime");
_useStaticTime = getNumber (configFile >> "CfgSettings" >> "Time" >> "useStaticTime");
_staticTime = getArray (configFile >> "CfgSettings" >> "Time" >> "staticTime");
if(_useStaticTime isEqualTo 1)then
{
//setDate _staticTime;
}
else
{
if(_useRealTime isEqualTo 1)then
{
//setDate ExileServerStartTime;
};
};
forceWeatherChange;
_changetime = round(getNumber (configFile >> "CfgSettings" >> "Weather" >> "interval") * 60);
//[_changetime, ExileServer_system_weather_thread_weatherSimulation, [], true] call ExileServer_system_thread_addTask;
true