Skip to content

Commit

Permalink
[SYNC] Synchronize dev and main branches, relation utils tests and im…
Browse files Browse the repository at this point in the history
…provement (#5)
  • Loading branch information
Neloreck authored Jun 23, 2023
2 parents 1793718 + cea6ec1 commit 47e5799
Show file tree
Hide file tree
Showing 70 changed files with 1,674 additions and 808 deletions.
6 changes: 3 additions & 3 deletions cli/test/jest_global.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mockEngineGlobals } from "@/fixtures/engine";
import { mockLuaLib } from "@/fixtures/lua";
import { mockXRay16 } from "@/fixtures/xray";
import { mockEngineGlobals } from "@/fixtures/engine/mockEngineGlobals";
import { mockLuaLib } from "@/fixtures/lua/mockLuaLib";
import { mockXRay16 } from "@/fixtures/xray/mockXRay16";

mockEngineGlobals();
mockLuaLib();
Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/database/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { CampStoryManager } from "@/engine/core/schemes/camper";
import type { PatrolManager } from "@/engine/core/schemes/patrol";
import type { ReachTaskPatrolManager } from "@/engine/core/schemes/reach_task";
import type { LightManager } from "@/engine/core/schemes/sr_light";
import type { ERelation } from "@/engine/lib/constants/relations";
import type { ERelation } from "@/engine/core/utils/relation";
import { storyNames, TStoryName } from "@/engine/lib/constants/story_names";
import type {
ClientObject,
Expand Down
4 changes: 2 additions & 2 deletions src/engine/core/database/story_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export function registerObjectStoryLinks(serverObject: ServerObject): void {
const spawnIni: IniFile = serverObject.spawn_ini();

if (spawnIni.section_exist("story_object")) {
const [result, id, value] = spawnIni.r_line("story_object", 0, "", "");
const [, field, value] = spawnIni.r_line("story_object", 0, "", "");

assert(id === "story_id", "There is no 'story_id' field in [story_object] section [%s].", serverObject.name());
assert(field === "story_id", "There is no 'story_id' field in [story_object] section [%s].", serverObject.name());
assert(value !== "", "Field 'story_id' in [story_object] section got no value: [%s].", serverObject.name());

registerStoryLink(serverObject.id, value);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/managers/debug/DebugManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EStateActionId } from "@/engine/core/objects/state";
import { StalkerStateManager } from "@/engine/core/objects/state/StalkerStateManager";
import { EActionId } from "@/engine/core/schemes";
import { LuaLogger } from "@/engine/core/utils/logging";
import { getNumberRelationBetweenCommunities } from "@/engine/core/utils/relation";
import { getNumberRelationBetweenCommunities } from "@/engine/core/utils/relation/get";
import { gameTimeToString } from "@/engine/core/utils/time";
import { toJSON } from "@/engine/core/utils/transform/json";
import { stalkerCommunities, TCommunity } from "@/engine/lib/constants/communities";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { abort } from "@/engine/core/utils/assertion";
import { parseStringsList } from "@/engine/core/utils/ini/parse";
import { LuaLogger } from "@/engine/core/utils/logging";
import { changeTeamSquadGroup } from "@/engine/core/utils/object/object_general";
import { setSquadRelationToActor } from "@/engine/core/utils/relation";
import { TCommunity } from "@/engine/lib/constants/communities";
import { levels, TLevel } from "@/engine/lib/constants/levels";
import {
Expand Down Expand Up @@ -255,7 +256,10 @@ export class SimulationBoardManager extends AbstractCoreManager {
logger.info("Creating squad in smart:", squad.name(), smartTerrain.name());

squad.createSquadMembers(smartTerrain);
squad.updateSquadRelationToActor();

if (squad.relationship) {
setSquadRelationToActor(squad, squad.relationship);
}

this.assignSquadToSmartTerrain(squad, smartTerrain.id);

Expand Down
4 changes: 1 addition & 3 deletions src/engine/core/managers/interaction/TravelManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { Squad } from "@/engine/core/objects/server/squad/Squad";
import { TSimulationObject } from "@/engine/core/objects/server/types";
import { abort } from "@/engine/core/utils/assertion";
import { createAutoSave } from "@/engine/core/utils/game_save";
import { pickSectionFromCondList } from "@/engine/core/utils/ini/config";
import { parseConditionsList } from "@/engine/core/utils/ini/parse";
import { TConditionList } from "@/engine/core/utils/ini/types";
import { parseConditionsList, pickSectionFromCondList, TConditionList } from "@/engine/core/utils/ini";
import { LuaLogger } from "@/engine/core/utils/logging";
import {
getAlifeCharacterCommunity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { StatisticsManager } from "@/engine/core/managers/interface/StatisticsManager";
import { giveInfo, hasAlifeInfo, hasAlifeInfos, hasFewAlifeInfos } from "@/engine/core/utils/info_portion";
import { LuaLogger } from "@/engine/core/utils/logging";
import { increaseNumberRelationBetweenCommunityAndId } from "@/engine/core/utils/relation";
import { increaseCommunityGoodwillToId } from "@/engine/core/utils/relation";
import { spawnItemsForObjectFromList } from "@/engine/core/utils/spawn";
import { readTimeFromPacket, writeTimeToPacket } from "@/engine/core/utils/time";
import { captions } from "@/engine/lib/constants/captions/captions";
Expand Down Expand Up @@ -246,7 +246,7 @@ export class AchievementsManager extends AbstractCoreManager {
}

giveInfo(infoPortions.sim_bandit_attack_harder);
increaseNumberRelationBetweenCommunityAndId(communities.stalker, registry.actor.id(), 200);
increaseCommunityGoodwillToId(communities.stalker, registry.actor.id(), 200);

EventsManager.getInstance().emitEvent<ITipNotification>(EGameEvent.NOTIFICATION, {
type: ENotificationType.TIP,
Expand Down Expand Up @@ -364,10 +364,10 @@ export class AchievementsManager extends AbstractCoreManager {

const actorId: TNumberId = registry.actor.id();

increaseNumberRelationBetweenCommunityAndId(communities.stalker, actorId, 200);
increaseNumberRelationBetweenCommunityAndId(communities.freedom, actorId, 200);
increaseNumberRelationBetweenCommunityAndId(communities.dolg, actorId, 200);
increaseNumberRelationBetweenCommunityAndId(communities.bandit, actorId, 200);
increaseCommunityGoodwillToId(communities.stalker, actorId, 200);
increaseCommunityGoodwillToId(communities.freedom, actorId, 200);
increaseCommunityGoodwillToId(communities.dolg, actorId, 200);
increaseCommunityGoodwillToId(communities.bandit, actorId, 200);

EventsManager.getInstance().emitEvent<ITipNotification>(EGameEvent.NOTIFICATION, {
type: ENotificationType.TIP,
Expand Down Expand Up @@ -605,7 +605,7 @@ export class AchievementsManager extends AbstractCoreManager {
])
) {
giveInfo(infoPortions.sim_stalker_help_harder);
increaseNumberRelationBetweenCommunityAndId(communities.stalker, registry.actor.id(), 100);
increaseCommunityGoodwillToId(communities.stalker, registry.actor.id(), 100);

EventsManager.getInstance().emitEvent<ITipNotification>(EGameEvent.NOTIFICATION, {
type: ENotificationType.TIP,
Expand Down
5 changes: 2 additions & 3 deletions src/engine/core/objects/binders/creature/StalkerBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ import {
getObjectSquad,
updateObjectInvulnerability,
} from "@/engine/core/utils/object/object_general";
import { setObjectsRelation, setObjectSympathy } from "@/engine/core/utils/relation";
import { ERelation, setClientObjectRelation, setObjectSympathy } from "@/engine/core/utils/relation";
import { emitSchemeEvent, trySwitchToAnotherSection } from "@/engine/core/utils/scheme";
import { createEmptyVector } from "@/engine/core/utils/vector";
import { communities, TCommunity } from "@/engine/lib/constants/communities";
import { MAX_U16 } from "@/engine/lib/constants/memory";
import { ERelation } from "@/engine/lib/constants/relations";
import {
ActionPlanner,
ALifeSmartTerrainTask,
Expand Down Expand Up @@ -162,7 +161,7 @@ export class StalkerBinder extends object_binder {
const relation: Optional<ERelation> = registry.goodwill.relations.get(objectId);

if (relation !== null && actor) {
setObjectsRelation(this.object, actor, relation);
setClientObjectRelation(this.object, actor, relation);
}

const sympathy: Optional<TCount> = registry.goodwill.sympathy.get(objectId);
Expand Down
17 changes: 12 additions & 5 deletions src/engine/core/objects/server/smart_terrain/SmartTerrain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,20 @@ import {
} from "@/engine/core/objects/server/types";
import { abort, assert, assertDefined } from "@/engine/core/utils/assertion";
import { isMonster, isStalker } from "@/engine/core/utils/check/is";
import { pickSectionFromCondList } from "@/engine/core/utils/ini/config";
import { getSchemeFromSection, parseConditionsList, parseStringsList } from "@/engine/core/utils/ini/parse";
import { readIniBoolean, readIniNumber, readIniString } from "@/engine/core/utils/ini/read";
import { IConfigSwitchCondition, TConditionList } from "@/engine/core/utils/ini/types";
import {
getSchemeFromSection,
IConfigSwitchCondition,
parseConditionsList,
parseStringsList,
pickSectionFromCondList,
readIniBoolean,
readIniNumber,
readIniString,
TConditionList,
} from "@/engine/core/utils/ini";
import { LuaLogger } from "@/engine/core/utils/logging";
import { areObjectsOnSameLevel } from "@/engine/core/utils/object/object_general";
import { ERelation } from "@/engine/core/utils/relation";
import {
activateSchemeBySection,
configureObjectSchemes,
Expand All @@ -76,7 +84,6 @@ import { gameConfig } from "@/engine/lib/configs/GameConfig";
import { logicsConfig } from "@/engine/lib/configs/LogicsConfig";
import { TCaption } from "@/engine/lib/constants/captions/captions";
import { MAX_U8 } from "@/engine/lib/constants/memory";
import { ERelation } from "@/engine/lib/constants/relations";
import { roots } from "@/engine/lib/constants/roots";
import { SMART_TERRAIN_SECTION } from "@/engine/lib/constants/sections";
import { NIL, TRUE } from "@/engine/lib/constants/words";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import { GlobalSoundManager } from "@/engine/core/managers/sounds/GlobalSoundMan
import { SmartTerrain } from "@/engine/core/objects/server/smart_terrain/SmartTerrain";
import { ESmartTerrainStatus } from "@/engine/core/objects/server/smart_terrain/types";
import { isWeapon } from "@/engine/core/utils/check/is";
import { pickSectionFromCondList } from "@/engine/core/utils/ini/config";
import { parseConditionsList } from "@/engine/core/utils/ini/parse";
import { readIniString } from "@/engine/core/utils/ini/read";
import { TConditionList } from "@/engine/core/utils/ini/types";
import { parseConditionsList, pickSectionFromCondList, readIniString, TConditionList } from "@/engine/core/utils/ini";
import { LuaLogger } from "@/engine/core/utils/logging";
import { setSquadGoodwill } from "@/engine/core/utils/relation";
import { ERelation, updateSquadIdRelationToActor } from "@/engine/core/utils/relation";
import { readTimeFromPacket, writeTimeToPacket } from "@/engine/core/utils/time";
import { logicsConfig } from "@/engine/lib/configs/LogicsConfig";
import { ERelation } from "@/engine/lib/constants/relations";
import {
ClientObject,
IniFile,
Expand Down Expand Up @@ -79,7 +75,7 @@ export class SmartTerrainControl {
for (const [id, squad] of SimulationBoardManager.getInstance().getSmartTerrainDescriptorById(
this.smartTerrain.id
)!.assignedSquads) {
setSquadGoodwill(id, ERelation.NEUTRAL);
updateSquadIdRelationToActor(id, ERelation.NEUTRAL);
}

this.alarmStartedAt = null;
Expand Down Expand Up @@ -146,7 +142,7 @@ export class SmartTerrainControl {

for (const [squadId] of SimulationBoardManager.getInstance().getSmartTerrainDescriptorById(this.smartTerrain.id)!
.assignedSquads) {
setSquadGoodwill(squadId, ERelation.ENEMY);
updateSquadIdRelationToActor(squadId, ERelation.ENEMY);
}
}

Expand Down
49 changes: 18 additions & 31 deletions src/engine/core/objects/server/squad/Squad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,26 @@ import { StoryManager } from "@/engine/core/objects/sounds/stories";
import { abort, assertDefined } from "@/engine/core/utils/assertion";
import { isSquadMonsterCommunity } from "@/engine/core/utils/check/is";
import { hasAlifeInfo } from "@/engine/core/utils/info_portion";
import { pickSectionFromCondList } from "@/engine/core/utils/ini/config";
import { parseConditionsList, parseStringsList } from "@/engine/core/utils/ini/parse";
import { readIniBoolean, readIniNumber, readIniString, readIniTwoNumbers } from "@/engine/core/utils/ini/read";
import { TConditionList } from "@/engine/core/utils/ini/types";
import {
parseConditionsList,
parseStringsList,
pickSectionFromCondList,
readIniBoolean,
readIniNumber,
readIniString,
readIniTwoNumbers,
TConditionList,
} from "@/engine/core/utils/ini";
import { LuaLogger } from "@/engine/core/utils/logging";
import { areObjectsOnSameLevel } from "@/engine/core/utils/object/object_general";
import {
areCommunitiesEnemies,
ERelation,
getSquadMembersRelationToActor,
getSquadRelationToActor,
isFactionsEnemies,
setObjectsRelation,
getSquadMembersRelationToActorSafe,
setClientObjectRelation,
setObjectSympathy,
setServerObjectsRelation,
setServerObjectRelation,
} from "@/engine/core/utils/relation";
import { isEmpty } from "@/engine/core/utils/table";
import { gameConfig } from "@/engine/lib/configs/GameConfig";
Expand All @@ -65,10 +72,10 @@ import { communities, TCommunity } from "@/engine/lib/constants/communities";
import { infoPortions } from "@/engine/lib/constants/info_portions";
import { mapMarks } from "@/engine/lib/constants/map_marks";
import { MAX_U16 } from "@/engine/lib/constants/memory";
import { ERelation } from "@/engine/lib/constants/relations";
import { SMART_TERRAIN_SECTION } from "@/engine/lib/constants/sections";
import { FALSE, NIL, TRUE } from "@/engine/lib/constants/words";
import {
AlifeSimulator,
ALifeSmartTerrainTask,
AnyObject,
ClientObject,
Expand Down Expand Up @@ -823,26 +830,6 @@ export class Squad extends cse_alife_online_offline_group implements ISimulation
}
}

/**
* Set relation of squad to object with desired parameter.
* In case of no parameter provided squad members relation will be updated with already in-memory stored value.
*
* @param relation - optional, new relation between squad and actor
*/
public updateSquadRelationToActor(relation: Optional<ERelation> = this.relationship): void {
if (relation !== null) {
for (const squadMember of this.squad_members()) {
const object: Optional<ClientObject> = registry.objects.get(squadMember.id)?.object;

if (object !== null) {
setObjectsRelation(object, registry.actor, relation);
} else {
setServerObjectsRelation(alife().object(squadMember.id), alife().actor(), relation);
}
}
}
}

/**
* Set squad position in current level by supplied vector.
*/
Expand Down Expand Up @@ -955,7 +942,7 @@ export class Squad extends cse_alife_online_offline_group implements ISimulation
if (isSquadMonsterCommunity(this.faction)) {
spot = mapMarks.alife_presentation_squad_monster_debug;
} else {
const relation: ERelation = getSquadRelationToActor(this);
const relation: ERelation = getSquadMembersRelationToActorSafe(this);

switch (relation) {
case ERelation.FRIEND:
Expand Down Expand Up @@ -1056,7 +1043,7 @@ export class Squad extends cse_alife_online_offline_group implements ISimulation
if (
targetSquad &&
this.position.distance_to_sqr(targetSquad.position) < 150 * 150 &&
isFactionsEnemies(currentCommunity, targetSquad.getCommunity())
areCommunitiesEnemies(currentCommunity, targetSquad.getCommunity())
) {
return enemySquadId;
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/schemes/meet/SchemeMeet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { pickSectionFromCondList } from "@/engine/core/utils/ini/config";
import { parseConditionsList } from "@/engine/core/utils/ini/parse";
import { readIniString } from "@/engine/core/utils/ini/read";
import { LuaLogger } from "@/engine/core/utils/logging";
import { getObjectsRelationSafe } from "@/engine/core/utils/relation";
import { getObjectsRelationSafe } from "@/engine/core/utils/relation/get";
import { logicsConfig } from "@/engine/lib/configs/LogicsConfig";
import { FALSE, NIL, TRUE } from "@/engine/lib/constants/words";
import {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/schemes/sr_teleport/SchemeTeleport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ISchemeTeleportState } from "@/engine/core/schemes/sr_teleport/ISchemeT
import { SchemeTeleport } from "@/engine/core/schemes/sr_teleport/SchemeTeleport";
import { loadSchemeImplementation } from "@/engine/core/utils/scheme/setup";
import { ClientObject, EScheme, ESchemeType, IniFile } from "@/engine/lib/types";
import { luaTableToArray } from "@/fixtures/lua/mocks/utils";
import { luaTableToArray } from "@/fixtures/lua/mocks/lua_utils";
import { mockClientGameObject, mockIniFile } from "@/fixtures/xray";

describe("SchemeTeleport functionality", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/schemes/sr_timer/SchemeTimer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ETimerType, ISchemeTimerState } from "@/engine/core/schemes/sr_timer/IS
import { SchemeTimer } from "@/engine/core/schemes/sr_timer/SchemeTimer";
import { loadSchemeImplementation } from "@/engine/core/utils/scheme/setup";
import { ClientObject, EScheme, ESchemeType, IniFile } from "@/engine/lib/types";
import { luaTableToObject } from "@/fixtures/lua/mocks/utils";
import { luaTableToObject } from "@/fixtures/lua/mocks/lua_utils";
import { mockClientGameObject, mockIniFile } from "@/fixtures/xray";

describe("SchemeTimer functionality", () => {
Expand Down
12 changes: 8 additions & 4 deletions src/engine/core/ui/debug/sections/DebugObjectSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import { isGameStarted } from "@/engine/core/utils/check";
import { LuaLogger } from "@/engine/core/utils/logging";
import { getNearestClientObject } from "@/engine/core/utils/object/object_find";
import { getObjectSquad } from "@/engine/core/utils/object/object_general";
import { getObjectsRelationSafe, getSquadRelationToActor, setObjectsRelation } from "@/engine/core/utils/relation";
import {
ERelation,
getObjectsRelationSafe,
getSquadMembersRelationToActorSafe,
setClientObjectRelation,
} from "@/engine/core/utils/relation";
import { resolveXmlFile } from "@/engine/core/utils/ui";
import { ERelation } from "@/engine/lib/constants/relations";
import { NIL } from "@/engine/lib/constants/words";
import { ClientObject, Optional, TPath } from "@/engine/lib/types";

Expand Down Expand Up @@ -115,7 +119,7 @@ export class DebugObjectSection extends AbstractDebugSection {
"object relation: " + getObjectsRelationSafe(targetStalker, registry.actor)
);
this.uiTargetStalkerSquadRelationLabel.SetText(
"squad relation: " + (squad ? getSquadRelationToActor(squad) : NIL)
"squad relation: " + (squad ? getSquadMembersRelationToActorSafe(squad) : NIL)
);
} else {
this.uiNearestStalkerLabel.SetText("Nearest: " + NIL);
Expand Down Expand Up @@ -206,7 +210,7 @@ export class DebugObjectSection extends AbstractDebugSection {

if (targetObject) {
logger.info("Set actor relation for:", targetObject.name(), relation);
setObjectsRelation(targetObject, registry.actor, relation);
setClientObjectRelation(targetObject, registry.actor, relation);
this.initializeState();
} else {
logger.info("No object found for relation change");
Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/utils/assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const logger: LuaLogger = new LuaLogger($filename);
export function abort(format: string, ...rest: AnyArgs): never {
const reason: string = string.format(format, ...rest);

logger.error("[abort] Aborting:", reason);
logger.error("Aborting:", reason);

print_stack();
error(reason, 1);
Expand Down
Loading

0 comments on commit 47e5799

Please sign in to comment.