Skip to content

Commit 9861540

Browse files
authored
Merge pull request #189 from Cre8or/runningstuff
Fix object positioning when saving/loading games
2 parents f949925 + ed233ba commit 9861540

7 files changed

Lines changed: 148 additions & 63 deletions

File tree

addons/overthrow_main/functions/UI/dialogs/fn_mainMenu.sqf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ if(typename _b isEqualTo "ARRAY") then {
8585
_txt = "";
8686

8787
if(_building call OT_fnc_hasOwner) then {
88-
8988
_owner = _building call OT_fnc_getOwner;
9089
_ownername = players_NS getVariable format["name%1",_owner];
9190
if(isNil "_ownername") then {_ownername = "Someone"};
@@ -309,7 +308,9 @@ if(typename _b isEqualTo "ARRAY") then {
309308
};
310309
};
311310

312-
if(!((typeof _building) in OT_allRealEstate + [OT_flag_IND])) then {
311+
// Fetch the list of buildable houses
312+
private _buildableHouses = (OT_Buildables param [9, []]) param [2, []];
313+
if(!((typeof _building) in OT_allRealEstate + [OT_flag_IND]) and {!(typeOf _building in _buildableHouses)}) then {
313314
ctrlEnable [1609,false];
314315
ctrlEnable [1610,false];
315316
ctrlEnable [1608,false];

addons/overthrow_main/functions/actions/fn_build.sqf

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ canBuildHere = false;
9292
modeCenter = _center;
9393

9494
buildOnMouseMove = {
95-
params ["_control","_relX","_relY"];
95+
params ["_control","_mouseX","_mouseY"];
9696
modeValue = screenToWorld getMousePosition;
9797
modeValue = [modeValue select 0,modeValue select 1,0];
9898
if(!isNull modeTarget) then {
@@ -129,31 +129,44 @@ buildOnMouseMove = {
129129
};
130130
};
131131
if(buildCamRotating && buildCamMoving) exitWith {
132-
_pos = getpos buildcam;
133-
buildcam camSetPos [(_pos select 0)+_relX,(_pos select 1)+_relY,(_pos select 2)];
134-
buildcam camSetTarget buildFocus;
135-
buildcam camCommit 0;
132+
private _mouseVec = [-_mouseX, _mouseY, 0];
133+
private _dist = (vectorMagnitude _mouseVec) * (buildCam distance buildFocus) / 200;
134+
private _dir = [0,0,0] getDir _mouseVec;
135+
_dir = _dir + getDir buildCam;
136+
([sin _dir, cos _dir, 0] vectorMultiply _dist) params ["_relX","_relY"];
137+
138+
private _camATL = getPosATL buildCam;
139+
private _camWaterDepth = (getTerrainHeightASL _camATL) min 0;
140+
buildCam camSetPos (_camATL vectorAdd [_relX, _relY, _camWaterDepth]);
141+
buildCam camSetTarget buildFocus;
142+
buildCam camCommit 0;
136143
};
137144
if(buildCamMoving) exitWith {
138-
_pos = getpos buildcam;
139-
buildcam camSetPos [(_pos select 0)+_relX,(_pos select 1)-_relY,(_pos select 2)];
140-
_pos = getpos buildFocus;
141-
buildFocus setPos [(_pos select 0)+_relX,(_pos select 1)-_relY,_pos select 2];
142-
buildcam camSetTarget buildFocus;
143-
buildcam camCommit 0;
145+
private _mouseVec = [-_mouseX, _mouseY, 0];
146+
private _dist = (vectorMagnitude _mouseVec) * (buildCam distance buildFocus) / 200;
147+
private _dir = [0,0,0] getDir _mouseVec;
148+
_dir = _dir + getDir buildCam;
149+
([sin _dir, cos _dir, 0] vectorMultiply _dist) params ["_relX","_relY"];
150+
151+
private _camATL = getPosATL buildCam;
152+
private _camWaterDepth = (getTerrainHeightASL _camATL) min 0;
153+
buildFocus setPosATL ((getPosATL buildFocus) vectorAdd [_relX, _relY, 0]);
154+
buildCam camSetPos (_camATL vectorAdd [_relX, _relY, _camWaterDepth]);
155+
buildCam camSetTarget buildFocus;
156+
buildCam camCommit 0;
144157
};
145158

146159
};
147-
148160
buildMoveCam = {
149-
params ["_relX","_relY","_relZ"];
161+
params ["_dir", "_dist"];
150162

151-
private _pos = getpos buildcam;
152-
buildcam camSetPos [(_pos select 0)+_relX,(_pos select 1)-_relY,(_pos select 2)+_relZ];
153-
_pos = getpos buildFocus;
154-
buildFocus setPos [(_pos select 0)+_relX,(_pos select 1)-_relY,(_pos select 2)+_relZ];
155-
buildcam camSetTarget buildFocus;
156-
buildcam camCommit 0;
163+
_dir = _dir + getDir buildCam;
164+
([sin _dir, cos _dir, 0] vectorMultiply _dist) params ["_relX","_relY"];
165+
166+
buildFocus setPosATL ((getPosATL buildFocus) vectorAdd [_relX, _relY, 0]);
167+
buildCam camSetPos ((getPosATL buildCam) vectorAdd [_relX, _relY, 0]);
168+
buildCam camSetTarget buildFocus;
169+
buildCam camCommit 0;
157170
};
158171

159172
buildOnKeyUp = {
@@ -186,26 +199,22 @@ buildOnKeyDown = {
186199
if (_key isEqualTo 17) exitWith {
187200
//W
188201
_handled = true;
189-
_rel = [[0,0,0],2,(getDir buildCam)+90] call BIS_fnc_relPos;
190-
_rel call buildMoveCam;
202+
[0, 2] call buildMoveCam;
191203
};
192204
if (_key isEqualTo 31) exitWith {
193205
//S
194206
_handled = true;
195-
_rel = [[0,0,0],-2,(getDir buildCam)+90] call BIS_fnc_relPos;
196-
_rel call buildMoveCam;
207+
[180, 2] call buildMoveCam;
197208
};
198209
if (_key isEqualTo 30) exitWith {
199210
//A
200211
_handled = true;
201-
_rel = [[0,0,0],-2,(getDir buildCam)] call BIS_fnc_relPos;
202-
_rel call buildMoveCam;
212+
[270, 2] call buildMoveCam;
203213
};
204214
if (_key isEqualTo 32) exitWith {
205215
//D
206216
_handled = true;
207-
_rel = [[0,0,0],2,(getDir buildCam)] call BIS_fnc_relPos;
208-
_rel call buildMoveCam;
217+
[90, 2] call buildMoveCam;
209218
};
210219

211220
if(isNull modeTarget) exitWith {};
@@ -267,6 +276,7 @@ buildOnMouseUp = {
267276
if(_money < modePrice) then {
268277
"You cannot afford that" call OT_fnc_notifyMinor;
269278
}else{
279+
270280
_created = objNULL;
271281
playSound "3DEN_notificationDefault";
272282
player setVariable ["money",_money-modePrice,true];
@@ -279,6 +289,7 @@ buildOnMouseUp = {
279289
clearItemCargoGlobal _x;
280290
[_x,getplayeruid player] call OT_fnc_setOwner;
281291
_x call OT_fnc_initObjectLocal;
292+
282293
}foreach(_objects);
283294
_created = _objects select 0;
284295
deleteVehicle modeTarget;
@@ -288,6 +299,12 @@ buildOnMouseUp = {
288299
modeTarget = objNull;
289300
};
290301

302+
// If the object is a house, mark it as being player-built (will be used to save the leasing status)
303+
private _buildableHouses = (OT_Buildables param [9, []]) param [2, []];
304+
if ((typeof _created) in _buildableHouses) then {
305+
_created setVariable ["OT_house_isPlayerBuilt", true, true];
306+
};
307+
291308
if(modeCode != "") then {
292309
_created setVariable ["OT_init",modeCode,true];
293310
[_created,modeValue,modeCode] remoteExec ["OT_fnc_initBuilding",2];
@@ -309,21 +326,12 @@ buildOnMouseUp = {
309326
buildOnMouseWheel = {
310327
_z = _this select 1;
311328
_pos = position buildcam;
329+
private _distMul = 0.25 + (buildCam distance buildFocus) / 100;
312330

313331
if(_z < 0) then {
314-
if((_pos select 2) < 30) exitWith {
315-
buildcam camSetPos [(_pos select 0),(_pos select 1),(_pos select 2)+5];
316-
};
317-
if((_pos select 2) < 200) exitWith {
318-
buildcam camSetPos [(_pos select 0),(_pos select 1),(_pos select 2)+20];
319-
};
332+
buildcam camSetPos [(_pos select 0),(_pos select 1),(_pos select 2) + 10 * _distMul];
320333
}else{
321-
if((_pos select 2) > 30) exitWith {
322-
buildcam camSetPos [(_pos select 0),(_pos select 1),(_pos select 2)-20];
323-
};
324-
if((_pos select 2) > 10) exitWith {
325-
buildcam camSetPos [(_pos select 0),(_pos select 1),(_pos select 2)-5];
326-
};
334+
buildcam camSetPos [(_pos select 0),(_pos select 1),(_pos select 2) - 10 * _distMul];
327335
};
328336
buildcam camSetTarget buildFocus;
329337
buildCam camCommit 0.1;

addons/overthrow_main/functions/actions/fn_buyBuilding.sqf

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,32 @@ if(_handled) then {
4343
[player,"Building Purchased",format["Bought: %1 in %2 for $%3",getText(configFile >> "CfgVehicles" >> (typeof _building) >> "displayName"),(getpos _building) call OT_fnc_nearestTown,_price]] call BIS_fnc_createLogRecord;
4444
_building addEventHandler ["Dammaged",OT_fnc_buildingDamagedHandler];
4545
}else{
46-
if ((typeof _building) in OT_allRealEstate) then {
46+
// Fetch the list of buildable houses
47+
private _buildableHouses = (OT_Buildables param [9, []]) param [2, []];
48+
if((typeof _building) in OT_allRealEstate or {((typeOf _building) in _buildableHouses)}) then {
4749
private _id = [_building] call OT_fnc_getBuildID;
4850
[_building,nil] call OT_fnc_setOwner;
4951
private _leased = player getVariable ["leased",[]];
5052
_leased deleteAt (_leased find _id);
5153
player setVariable ["leased",_leased,true];
54+
55+
private _leasedata = player getVariable ["leasedata",[]];
56+
private _leasedataID = (_leasedata apply {_x select 0}) findIf {_x == _id};
57+
_leasedata deleteAt _leasedataID;
58+
player setVariable ["leasedata",_leasedata,true];
59+
5260
deleteMarker _mrkid;
5361
_owned deleteAt (_owned find _id);
5462
[player,"Building Sold",format["Sold: %1 in %2 for $%3",getText(configFile >> "CfgVehicles" >> (typeof _building) >> "displayName"),(getpos _building) call OT_fnc_nearestTown,_sell]] call BIS_fnc_createLogRecord;
5563
[_sell] call OT_fnc_money;
64+
65+
// Fallback for unknown buildings
5666
}else{
57-
deleteVehicle _building;
5867
_owned deleteAt (_owned find ([_building] call OT_fnc_getBuildID));
5968
};
69+
70+
// Always attempt to remove the building, because it might be played-placed (for map-placed buildings, this won't do anything)
71+
deleteVehicle _building;
6072
};
6173

6274
player setVariable ["owned",_owned,true];

addons/overthrow_main/functions/actions/fn_leaseBuilding.sqf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ if(typename _b isEqualTo "ARRAY") then {
5656
};
5757
if(_err) exitWith {};
5858
if(_handled) then {
59+
60+
// If the house is player-built, we set its lease variable to true
61+
if (_building getVariable ["OT_house_isPlayerBuilt", false]) then {
62+
_building setVariable ["OT_house_isLeased", true, true];
63+
};
64+
5965
private _id = ([_building] call OT_fnc_getBuildID);
6066
_leased = player getvariable ["leased",[]];
6167
_leased pushback _id;

addons/overthrow_main/functions/factions/GUER/fn_GUERLoop.sqf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,11 @@ if ((date select 4) != _lastmin) then {
332332
[-_costtoproduce] call OT_fnc_resistanceFunds;
333333
_timespent = _timespent + 1;
334334
}else{
335-
_need = "";
336-
if !(_dowood) then {_need = _need + format["%1 x wood ",_wood]};
337-
if !(_dosteel) then {_need = _need + format["%1 x steel ",_steel]};
338-
if !(_doplastic) then {_need = _need + format["%1 x plastic ",_plastic]};
339-
if !(_domoney) then {_need = _need + format["$%1 resistance funds",_costtoproduce]};
335+
_need = "";
336+
if !(_dowood) then {_need = _need + format["%1 x wood ",_wood]};
337+
if !(_dosteel) then {_need = _need + format["%1 x steel ",_steel]};
338+
if !(_doplastic) then {_need = _need + format["%1 x plastic ",_plastic]};
339+
if !(_domoney) then {_need = _need + format["$%1 resistance funds",_costtoproduce]};
340340
format["Factory has insufficient resources to produce item (need: %1)",_need] remoteExec["OT_fnc_notifyMinor",0,false];
341341
spawner setVariable ["GEURproduceerror",format["Factory has insufficient resources to produce item (need: %1)",_need],true];
342342
};
@@ -363,7 +363,8 @@ if ((date select 4) != _lastmin) then {
363363
_p = OT_factoryVehicleSpawn findEmptyPosition [5,100,_currentCls];
364364
if(count _p > 0) then {
365365
_veh = _currentCls createVehicle _p;
366-
[_veh,(server getVariable ["generals",[]]) select 0] call OT_fnc_setOwner;
366+
//[_veh,(server getVariable ["generals",[]]) select 0] call OT_fnc_setOwner;
367+
_veh setVariable ["OT_forceSaveUnowned", true, true]; // Save this vehicle even if it is unowned (we know somebody must have requested it at the factory, so they'll come back and claim it... eventually)
367368
clearWeaponCargoGlobal _veh;
368369
clearMagazineCargoGlobal _veh;
369370
clearBackpackCargoGlobal _veh;

addons/overthrow_main/functions/save/fn_loadGame.sqf

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ private _cc = 0;
2828

2929
sleep 0.3;
3030

31+
3132
//now do everything else
33+
private _buildableHouses = [];
34+
private _hasList_buildableHouses = false;
3235
{
3336
_x params ["_key","_val"];
3437

@@ -142,14 +145,14 @@ sleep 0.3;
142145
if !(_type isKindOf "Man") then {
143146
_pos = ((_x select 1)#0);
144147
_simulation = ((_x select 1)#1);
148+
_posFormat = (_x select 1) param [2, 0]; // Assume format 0 by default (posATL)
145149
_dir = _x select 2;
146150
_stock = _x select 3;
147151
_owner = _x select 4;
148152
_name = "";
149153
if(count _x > 5) then {
150154
_name = _x select 5;
151155
};
152-
private _p = _pos;
153156
_veh = createVehicle [_type, [0,0,1000], [], 0, "CAN_COLLIDE"];
154157
if !(_type isKindOf "LandVehicle" || _type isKindOf "Air" || _type isKindOf "Ship") then {
155158
_veh enableDynamicSimulation true;
@@ -162,7 +165,7 @@ sleep 0.3;
162165
};
163166
*/
164167

165-
if(count _x > 7) then {
168+
if(count _x > 7) then { // index range 0..6
166169
(_x select 7) params ["_fuel","_dmg"];
167170
//Fuel in tank
168171
_veh setFuel _fuel;
@@ -197,13 +200,42 @@ sleep 0.3;
197200
};
198201
};
199202
};
200-
if(typename _dir isEqualTo "SCALAR") then {
203+
204+
// Fetch the list of buildable houses
205+
if (!_hasList_buildableHouses) then {
206+
if (!isNil "OT_Buildables") then {
207+
_buildableHouses = (OT_Buildables param [9, []]) param [2, []];
208+
_hasList_buildableHouses = true;
209+
};
210+
};
211+
212+
// If the object is a player-built house, fetch its variables
213+
private _houseParams = _x param [8, []];
214+
if (!(_houseParams isEqualTo []) or {_type in _buildableHouses}) then {
215+
_veh setVariable ["OT_house_isPlayerBuilt", true, true];
216+
217+
private _isLeased = _houseParams param [0, false];
218+
if (_isLeased) then {
219+
_veh setVariable ["OT_house_isLeased", true, true];
220+
221+
private _leasedBuilt = [_owner,"leasedBuilt",[]] call OT_fnc_getOfflinePlayerAttribute;
222+
_leasedBuilt pushBack _veh;
223+
[_owner,"leasedBuilt",_leasedBuilt] call OT_fnc_setOfflinePlayerAttribute;
224+
};
225+
};
226+
227+
if (_posFormat == 1) then {
228+
_veh setPosWorld _pos; // format 1 is the new posWorld format
229+
} else {
230+
_veh setPosATL _pos; // <= v0.7.8.5 save - use the old posATL format
231+
};
232+
233+
if(_dir isEqualType 0) then {
201234
//Pre 0.6.8 save, scalar direction
202235
_veh setDir _dir;
203236
}else{
204237
_veh setVectorDirAndUp _dir;
205238
};
206-
_veh setPosATL _p;
207239
if(_type isKindOf "Building") then {
208240
_clu = createVehicle ["Land_ClutterCutter_large_F", _pos, [], 0, "CAN_COLLIDE"];
209241
_clu enableDynamicSimulation true;
@@ -215,7 +247,14 @@ sleep 0.3;
215247
clearItemCargoGlobal _veh;
216248
_veh setVariable ["name",_name,true];
217249

218-
[_veh,_owner] call OT_fnc_setOwner;
250+
// If this vehicle doesn't have an owner, set the forceSaveunowned flag to true so it gets saved again (until somebody owns it)
251+
if (_owner isEqualTo "") then {
252+
_veh setVariable ["OT_forceSaveUnowned", true, true];
253+
// Otherwise, set the owner (as per usual)
254+
} else {
255+
[_veh,_owner] call OT_fnc_setOwner;
256+
};
257+
219258
{
220259
[_x,_veh] call {
221260
params ["_it", "_veh"];
@@ -419,6 +458,7 @@ private _built = (allMissionObjects "Static");
419458
private _vars = players_NS getVariable [_uid,[]];
420459
private _leased = [_uid,"leased",[]] call OT_fnc_getOfflinePlayerAttribute;
421460
private _leasedata = [];
461+
private _leasedNew = [];
422462
{
423463
_x params ["_name","_val"];
424464
if(_name isEqualTo "owned") then {
@@ -446,12 +486,24 @@ private _built = (allMissionObjects "Static");
446486
};
447487
if(_x in _leased) then {
448488
_leasedata pushback [_x,typeof _bdg,_pos,_pos call OT_fnc_nearestTown];
489+
_leasedNew pushBack _x;
449490
};
450491
};
451492
}foreach(_val);
452493
};
453494
}foreach(_vars);
495+
496+
// Add the built houses
497+
{
498+
private _ID = [_x] call OT_fnc_getBuildID;
499+
private _pos = position _x;
500+
_leasedata pushBack [_ID, typeof _x,_pos,_pos call OT_fnc_nearestTown];
501+
_leasedNew pushBack _ID;
502+
} forEach ([_uid,"leasedBuilt",[]] call OT_fnc_getOfflinePlayerAttribute);
503+
454504
[_uid,"leasedata",_leasedata] call OT_fnc_setOfflinePlayerAttribute;
505+
[_uid,"leased",_leasedNew] call OT_fnc_setOfflinePlayerAttribute; // Overwrite the "leased" data to get rid of the IDs that point to buildings which no longer exist (player-built houses)
506+
[_uid,"leasedBuilt",[]] call OT_fnc_setOfflinePlayerAttribute;
455507
}foreach(players_NS getvariable ["OT_allPlayers",[]]);
456508
sleep 2; //let the variables propagate
457509
server setVariable ["StartupType","LOAD",true];

0 commit comments

Comments
 (0)