Skip to content

Commit

Permalink
fix #174 (#175)
Browse files Browse the repository at this point in the history
* add an unholy number of debug log messages if DEBUG_MODE_FULL
* aand fix a bug where ppl in small houses would never move
* oh, added transition from meetneighbor to housemove
  • Loading branch information
Fusselwurm authored Aug 12, 2022
1 parent 4c70e2b commit 8bbbeec
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 73 deletions.
2 changes: 2 additions & 0 deletions addons/residents/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PREP(sm_business_state_chat_enter);
PREP(sm_business_state_chat_exit);
PREP(sm_business_state_chat_loop);
PREP(sm_business_state_housemove_enter);
PREP(sm_business_state_housemove_loop);
PREP(sm_business_state_housework_enter);
PREP(sm_business_state_housework_exit);
PREP(sm_business_state_meetNeighbor_enter);
Expand All @@ -15,4 +16,5 @@ PREP(sm_business_trans_housemove_housework_condition);
PREP(sm_business_trans_housework_housemove_condition);
PREP(sm_business_trans_housework_meetNeighbor_condition);
PREP(sm_business_trans_meetNeighbor_chat_condition);
PREP(sm_business_trans_meetNeighbor_housemove_condition);
PREP(sm_business_trans_rally_housemove_condition);
10 changes: 9 additions & 1 deletion addons/residents/functions/fnc_sm_business.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private _bus_rally = "bus_rally";

private _bus_housemove = [
_business,
{},
{ _this call FUNC(sm_business_state_housemove_loop) },
{ _this call FUNC(sm_business_state_housemove_enter) },
{ _this call FUNC(sm_business_state_housemove_exit) },
"bus_housemove"
Expand Down Expand Up @@ -71,6 +71,14 @@ assert ([
_bus_meetNeighbor + _bus_chat
] call EFUNC(cba_statemachine,addTransition));

assert ([
_business,
_bus_meetNeighbor, _bus_housemove,
{ _this call FUNC(sm_business_trans_meetNeighbor_housemove_condition) },
{},
_bus_meetNeighbor + _bus_housemove
] call EFUNC(cba_statemachine,addTransition));

assert ([
_business,
_bus_chat, _bus_housework,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
private _baseChatTime = GVAR(chatTime);

private _chatTime = _baseChatTime * random [0.2, 1, 5];
_this setVariable ["grad_civs_chat_time", _chatTime];
_this setVariable [QGVAR(chatDuration), _chatTime];

private _neighbor = _this getVariable ["grad_civs_neighborToMeet", objNull];
if (isNull _neighbor) exitWith {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "..\script_component.hpp"

_this setVariable["grad_civs_lastSocialContact", CBA_missionTime];
_this setVariable ["grad_civs_chat_time", nil];
_this setVariable[QGVAR(lastChat), CBA_missionTime];
_this setVariable [QGVAR(chatDuration), nil];
_this setVariable ["grad_civs_neighborToMeet", nil];
_this setRandomLip false;
20 changes: 18 additions & 2 deletions addons/residents/functions/fnc_sm_business_state_chat_loop.sqf
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#include "..\script_component.hpp"

doStop _this;
_this lookAt (_this getVariable ["grad_civs_neighborToMeet", objNull]);
private _neighbor = _this getVariable ["grad_civs_neighborToMeet", objNull];
if (isNull _neighbor) exitWith {
LOG_1("%1 : I dont remember my chat partner", _this);
};
if (!(alive _neighbor)) exitWith {
LOG_2("%1 : My chat partner %2 is dead", _this, _neighbor);
};

/*get closer than 2m to have a conversation*/
/* note: this must be fulfilled to even enter the chat state BUT that neighbor may be on the move somewhere else, so follow them if necessary*/
if ((_this distance _neighbor) < 2) then {
doStop _this;
_this lookAt (_this getVariable ["grad_civs_neighborToMeet", objNull]);
} else {
LOG_2("%1 : Will move closer as my chat partner %2 is too far away", _this, _neighbor);
_this moveTo (getPos _neighbor);
};

_this setRandomLip (selectRandom [false, false, false, true]);
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ private _house = _this getVariable ["grad_civs_home", objNull];
_this call EFUNC(activities,forceEmotionSpeed);

if (isNull _house) exitWith {
LOG_1("%1 should be doing housemove, but does not have a house");
WARNING_1("%1 should be doing housemove, but dont have a house", _this);
};

doStop _this;
Expand All @@ -14,7 +14,9 @@ private _positions = [_house] call BIS_fnc_buildingPositions;
if (!(_this call EFUNC(activities,isSleepingTime))) then {
// add one random really close position to house positions
private _currentPos = getPos _house;
private _nearPos = [random 10, random 10, (_currentPos select 2)] vectorAdd _currentPos;
private _offsetFromHouse = [random 10, random 10, (_currentPos select 2)];
LOG_2("%1 its day so lets add one housework position outside the house", _this, _offsetFromHouse);
private _nearPos = _offsetFromHouse vectorAdd _currentPos;
_positions = _positions + [_nearPos];
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "..\script_component.hpp"

if (speed _this == 0) then {
private _targetPos = _this getVariable [QGVAR(targetPos), getPos _this];
LOG_3("%1 : Ordering myself to move from %2 to %3 as my speed was 0 during housemove", _this, getPos _this, _targetPos);
_this moveTo _targetPos;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
private _isSleepingTime = _this call EFUNC(activities,isSleepingTime);

private _house = _this getVariable ["grad_civs_home", objNull];
_this setVariable [QGVAR(housework_time), random (if (_isSleepingTime) then [{GVAR(houseworkTimesNight)},{GVAR(houseworkTimesDay)}])];
_this call EFUNC(activities,forceEmotionSpeed);

if (isNull _house) exitWith {
LOG_1("%1 should be doing housework, but does not have a house");
LOG_1("%1 should enter doing housework but does not have a house", _this);
};
_this setVariable [QGVAR(housework_time), random (if (_isSleepingTime) then [{GVAR(houseworkTimesNight)},{GVAR(houseworkTimesDay)}])];
_this call EFUNC(activities,forceEmotionSpeed);

private _animSets = if (_this call EFUNC(activities,isInHouse))
then {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

[QEGVAR(common,switchMove), [_this, ""]] call CBA_fnc_globalEvent;
doStop _this;
_this setVariable ["grad_civs_stopDistance", random [3, 7, 20]];
private _stopDistance = random [3, 7, 20];
LOG_2("%1 : stop distance for chat if senior is %2", _this, _stopDistance);
_this setVariable [QGVAR(seniorStopDistance), _stopDistance];
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
#include "..\script_component.hpp"

private _neighbor = _this getVariable ["grad_civs_neighborToMeet", objNull];
if (isNull _neighbor) exitWith {WARNING("wanted to meet neighbor, but now he's null!")};
if (isNull _neighbor) exitWith {
WARNING_1("%1 : wanted to meet neighbor but now he's null!", _this);
};

private _isSenior = ([_this, _neighbor] call FUNC(compare)) > 0;
private _stopDistance = _this getVariable ["grad_civs_stopDistance", 5];
if (!(isOnRoad _this) && _isSenior && (_this distance _neighbor) < _stopDistance && (random 10 > 1)) exitWith {doStop _this}; // one of both may wait the last meters
private _stopDistance = _this getVariable [QGVAR(seniorStopDistance), 5];
if (
!(isOnRoad _this) &&
_isSenior &&
(_this distance _neighbor) < _stopDistance &&
(random 10 > 1)
) exitWith {
LOG_2("%1 : as the senior talking to %2 im stopping early", _this, _neighbor);
doStop _this;
}; // one of both may wait the last meters

private _knownNeighborPos = _this getVariable ["grad_civs_neighborPos", [0, 0, 0]];
private _neighborPos = getPos _neighbor;
if ((_knownNeighborPos distance _neighborPos) > 1) then {
LOG_2("%1 : need to move closer to %2 to meet them", _this, _neighbor);
_this setVariable ["grad_civs_neighborPos", _neighborPos];
_this doMove _neighborPos;
_this call EFUNC(activities,forceEmotionSpeed);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#include "..\script_component.hpp"

private _neighbor = _this getVariable ["grad_civs_neighborToMeet", objNull];
if (isNull _neighbor) exitWith {true};
if (isNull (_neighbor getVariable ["grad_civs_neighborToMeet", objNull])) exitWith {true};
if (isNull _neighbor) exitWith {
LOG_1("%1 : my current chat partner has ceased existing", _this);
true
};
if (isNull (_neighbor getVariable ["grad_civs_neighborToMeet", objNull])) exitWith {
LOG_2("%1 : current chat partner %2 does not want to chat anymore", _this, _neighbor);
true
};

(_this getVariable ["grad_civs_chat_time", 0]) + _thisStateTime < CBA_missionTime
(_this getVariable [QGVAR(chatDuration), 0]) + _thisStateTime < CBA_missionTime
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#include "..\script_component.hpp"

private _targetPos = _this getVariable [QGVAR(targetPos), getPos _this];

private _distance = _this distance _targetPos;

(_distance < 2) ||
(_thisStateTime > 120 && _distance < 10)
if (_distance < 2) exitWith {
LOG_3("%1 : entering housework as distance to %2 is %3", _this, _targetPos, _distance);
true
};

if ((_thisStateTime + 120) < CBA_missionTime && (_distance < 10)) exitWith {
LOG_3("%1 : trying to reach destination for >120s and distance to %2 is %3 - entering housework for a change", _this, _targetPos, _distance);
true
};

false
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

private _result = (_this getVariable [QGVAR(housework_time), 0]) + _thisStateTime < CBA_missionTime;

LOG_2("%1 : is housework over? %2", _this, _result);

_result
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

if (_this call EFUNC(activities,isSleepingTime)) exitWith {false};

private _neighborCooldown = GVAR(meetNeighborCooldown);

if ((_this getVariable ["grad_civs_lastSocialContact", 0]) + _neighborCooldown > CBA_missionTime) exitWith {false};
if ((_this getVariable [QGVAR(lastChat), 0]) + GVAR(meetNeighborCooldown) > CBA_missionTime) exitWith {false};

private _neighborToMeet = _this getVariable ["grad_civs_neighborToMeet", objNull];
if (!(isNull _neighborToMeet)) exitWith {
Expand All @@ -24,10 +22,10 @@ private _neighborToMeet = {
(_x getVariable ["grad_civs_primaryTask", ""] == "reside") &&
(
(_x getVariable ["grad_civs_neighborToMeet", objNull] == _this) ||
((_x getVariable ["grad_civs_lastSocialContact", 0]) + _neighborCooldown < CBA_missionTime)
((_x getVariable [QGVAR(lastChat), 0]) + GVAR(meetNeighborCooldown) < CBA_missionTime)
)
};
if (count _socialNeighbors > 0) exitWith {_socialNeighbors select 0};
if (count _socialNeighbors > 0) exitWith {_socialNeighbors#0};
} forEach [50, 100, 150];

if (isNil "_neighborToMeet") exitWith {false};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#include "..\script_component.hpp"

private _neighbor = _this getVariable ["grad_civs_neighborToMeet", objNull];
if (isNull _neighbor) exitWith {true}; // go to chat only so that chat can lead to housework in the next tick
if (!(alive _neighbor)) exitWith {true};
if (isNull _neighbor) exitWith {
LOG_1("%1 : cannot enter conversation because neighbor ceased to exist", _this);
false
};
if (!(alive _neighbor)) exitWith {
LOG_2("%1 : cannot enter conversation because %2 is dead", _this, _neighbor);
false
};

/*get closer than 2m to have a conversation*/
(_this distance _neighbor) < 2 || ((_thisStateTime + 60) < CBA_missionTime)
if ((_this distance _neighbor) < 2) exitWith {
LOG_2("%1 : entering conversation after being closer than 2m from %2", _this, _neighbor);
true
};

false
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "..\script_component.hpp"

private _neighbor = _this getVariable ["grad_civs_neighborToMeet", objNull];
if (isNull _neighbor) exitWith {
LOG_1("%1 : revertin to housemove because neighbor ceased to exist", _this);
true
};
if (!(alive _neighbor)) exitWith {
LOG_2("%1 : reverting to housemove because %2 is dead", _this, _neighbor);
true
};

if ((_thisStateTime + 60) < CBA_missionTime) exitWith {
LOG_1("%1 : reverting to housemove after trying to meet neighbor for 60s", _this);
true
};

false
1 change: 1 addition & 0 deletions docs/states.gv
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ digraph lifecycle {
bus_rideInBack -> bus_rally;
bus_housemove -> bus_meetNeighbor;
bus_meetNeighbor -> bus_chat;
bus_meetNeighbor -> bus_housemove;
bus_chat -> bus_housemove;
bus_housemove -> bus_housework;
bus_housework -> bus_housemove;
Expand Down
Binary file modified docs/states.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8bbbeec

Please sign in to comment.