Skip to content

Commit

Permalink
Updated conditions doc to be more informative and look better in xrf …
Browse files Browse the repository at this point in the history
…exports viewer.
  • Loading branch information
Neloreck committed Mar 26, 2024
1 parent 2eea691 commit a792450
Show file tree
Hide file tree
Showing 32 changed files with 249 additions and 196 deletions.
6 changes: 3 additions & 3 deletions src/engine/core/objects/creature/Actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class Actor extends cse_alife_creature_actor implements ISimulationTarget
if (zone !== null && zone.inside(this.position)) {
const smartTerrain: Optional<SmartTerrain> = getManager(SimulationManager).getSmartTerrainByName(smartName);

if (smartTerrain && smartTerrain.smartTerrainActorControl?.status !== ESmartTerrainStatus.ALARM) {
if (smartTerrain && smartTerrain.terrainControl?.status !== ESmartTerrainStatus.ALARM) {
return false;
}
}
Expand All @@ -145,8 +145,8 @@ export class Actor extends cse_alife_creature_actor implements ISimulationTarget
) as SmartTerrain;

if (
activeSmartTerrain.smartTerrainActorControl?.status === ESmartTerrainStatus.NORMAL &&
registry.zones.get(activeSmartTerrain.smartTerrainActorControl.noWeaponZone).inside(this.position)
activeSmartTerrain.terrainControl?.status === ESmartTerrainStatus.NORMAL &&
registry.zones.get(activeSmartTerrain.terrainControl.noWeaponZone).inside(this.position)
) {
return false;
}
Expand Down
16 changes: 8 additions & 8 deletions src/engine/core/objects/smart_terrain/SmartTerrain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("SmartTerrain generic logic", () => {
expect(terrain.attackRestrictor).toBeNull();
expect(terrain.safeRestrictor).toBeNull();
expect(terrain.spawnPointName).toBeNull();
expect(terrain.smartTerrainActorControl).toBeNull();
expect(terrain.terrainControl).toBeNull();

expect(terrain.arrivingObjects.length()).toBe(0);
expect(terrain.jobs.length()).toBe(0);
Expand Down Expand Up @@ -183,7 +183,7 @@ describe("SmartTerrain generic logic", () => {

terrain.jobDeadTimeById.set(50, MockCTime.mock(2004, 7, 19, 13, 30, 10, 200));

terrain.smartTerrainActorControl = new SmartTerrainControl(
terrain.terrainControl = new SmartTerrainControl(
terrain,
MockIniFile.mock("test.ltx", {
test_save: {
Expand Down Expand Up @@ -310,9 +310,9 @@ describe("SmartTerrain generic logic", () => {
MockCTime.mock(2004, 7, 19, 13, 30, 10, 200).toString()
);

expect(anotherTerrain.smartTerrainActorControl).toBeDefined();
expect(anotherTerrain.smartTerrainActorControl?.status).toBe(ESmartTerrainStatus.NORMAL);
expect(anotherTerrain.smartTerrainActorControl?.alarmStartedAt).toBeNull();
expect(anotherTerrain.terrainControl).toBeDefined();
expect(anotherTerrain.terrainControl?.status).toBe(ESmartTerrainStatus.NORMAL);
expect(anotherTerrain.terrainControl?.alarmStartedAt).toBeNull();
expect(anotherTerrain.isRespawnPoint).toBe(true);
expect(anotherTerrain.spawnedSquadsList).toEqualLuaTables({
test_squad_novice: {
Expand Down Expand Up @@ -355,9 +355,9 @@ describe("SmartTerrain generic logic", () => {
expect(anotherTerrain.objectJobDescriptors.length()).toBe(0);
expect(anotherTerrain.jobDeadTimeById.length()).toBe(0);

expect(anotherTerrain.smartTerrainActorControl).toBeDefined();
expect(anotherTerrain.smartTerrainActorControl?.status).toBe(ESmartTerrainStatus.NORMAL);
expect(anotherTerrain.smartTerrainActorControl?.alarmStartedAt).toBeNull();
expect(anotherTerrain.terrainControl).toBeDefined();
expect(anotherTerrain.terrainControl?.status).toBe(ESmartTerrainStatus.NORMAL);
expect(anotherTerrain.terrainControl?.alarmStartedAt).toBeNull();
expect(anotherTerrain.isRespawnPoint).toBe(true);
expect(anotherTerrain.spawnedSquadsList).toEqualLuaTables({
test_squad_novice: {
Expand Down
16 changes: 7 additions & 9 deletions src/engine/core/objects/smart_terrain/SmartTerrain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class SmartTerrain extends cse_alife_smart_zone implements ISimulationTar
public safeRestrictor: Optional<TName> = null; // Name of restrictor where objects are considered safe.
public spawnPointName: Optional<TName> = null; // Name of patrol point override to spawn objects.

public smartTerrainActorControl: Optional<SmartTerrainControl> = null;
public terrainControl: Optional<SmartTerrainControl> = null;

// Stalkers that are entering smart, but still not in correct vertex
public arrivingObjects: LuaTable<TNumberId, ServerCreatureObject> = new LuaTable();
Expand Down Expand Up @@ -344,9 +344,9 @@ export class SmartTerrain extends cse_alife_smart_zone implements ISimulationTar
writeTimeToPacket(packet, time);
}

if (this.smartTerrainActorControl) {
if (this.terrainControl) {
packet.w_bool(true);
this.smartTerrainActorControl.save(packet);
this.terrainControl.save(packet);
} else {
packet.w_bool(false);
}
Expand Down Expand Up @@ -431,7 +431,7 @@ export class SmartTerrain extends cse_alife_smart_zone implements ISimulationTar
this.isObjectsInitializationNeeded = true;

if (packet.r_bool()) {
this.smartTerrainActorControl?.load(packet);
this.terrainControl?.load(packet);
}

const isRespawnPoint: boolean = packet.r_bool();
Expand Down Expand Up @@ -509,7 +509,7 @@ export class SmartTerrain extends cse_alife_smart_zone implements ISimulationTar
updateSmartTerrainJobs(this);
updateSimulationObjectAvailability(this);

this.smartTerrainActorControl?.update();
this.terrainControl?.update();
}

/**
Expand Down Expand Up @@ -601,7 +601,7 @@ export class SmartTerrain extends cse_alife_smart_zone implements ISimulationTar
);

if (smartControlSection) {
this.smartTerrainActorControl = new SmartTerrainControl(this, this.ini, smartControlSection);
this.terrainControl = new SmartTerrainControl(this, this.ini, smartControlSection);
}

if (respawnSection) {
Expand Down Expand Up @@ -710,9 +710,7 @@ export class SmartTerrain extends cse_alife_smart_zone implements ISimulationTar
return false;
}

return !(
this.smartTerrainActorControl !== null && this.smartTerrainActorControl.status !== ESmartTerrainStatus.NORMAL
);
return !(this.terrainControl !== null && this.terrainControl.status !== ESmartTerrainStatus.NORMAL);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("should correctly generate stalker animpoint jobs", () => {
const cover: SmartCover = mockSmartCover("test_smart_animpoint_1");

terrain.defendRestrictor = "test_defend_restrictor";
terrain.smartTerrainActorControl = { ignoreZone: "test_ignore_zone" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "test_ignore_zone" } as SmartTerrainControl;

registerSmartCover(cover);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ cover_name = %s
builder.append("invulnerable = {=npc_in_zone(smart.safe_restr)} true\n");
}

if (smartTerrain.smartTerrainActorControl !== null && smartTerrain.smartTerrainActorControl.ignoreZone !== null) {
if (smartTerrain.terrainControl !== null && smartTerrain.terrainControl.ignoreZone !== null) {
// todo: Bad smart.base_on_actor_control.ignore_zone?
builder.append(
`combat_ignore_cond = {=npc_in_zone(smart.base_on_actor_control.ignore_zone)} true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("should correctly generate stalker collector jobs", () => {
const terrain: SmartTerrain = MockSmartTerrain.mock("test_smart");

terrain.defendRestrictor = "test_defend_restrictor";
terrain.smartTerrainActorControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;

const object: GameObject = MockGameObject.mock({ name: "some_restrictor" });

Expand Down Expand Up @@ -108,7 +108,7 @@ describe("should correctly generate stalker collector jobs", () => {
const terrain: SmartTerrain = MockSmartTerrain.mock("test_smart");

terrain.defendRestrictor = "test_defend_restrictor";
terrain.smartTerrainActorControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.safeRestrictor = "safe_restrictor_test";

const object: GameObject = MockGameObject.mock({ name: "safe_restrictor_test" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def_state_moving = patrol
}

if (
smartTerrain.smartTerrainActorControl !== null &&
smartTerrain.smartTerrainActorControl.ignoreZone !== null &&
isPatrolInRestrictor(smartTerrain.smartTerrainActorControl.ignoreZone, patrolName)
smartTerrain.terrainControl !== null &&
smartTerrain.terrainControl.ignoreZone !== null &&
isPatrolInRestrictor(smartTerrain.terrainControl.ignoreZone, patrolName)
) {
builder.append(
`combat_ignore_cond = {=npc_in_zone(smart.base_on_actor_control.ignore_zone)} true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe("should correctly generate stalker guard jobs", () => {
const terrain: SmartTerrain = MockSmartTerrain.mock("test_smart");

terrain.defendRestrictor = "test_defend_restrictor";
terrain.smartTerrainActorControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;

const object: GameObject = MockGameObject.mock({ name: "some_restrictor" });

Expand Down Expand Up @@ -151,7 +151,7 @@ describe("should correctly generate stalker guard jobs", () => {
const terrain: SmartTerrain = MockSmartTerrain.mock("test_smart");

terrain.defendRestrictor = "test_defend_restrictor";
terrain.smartTerrainActorControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.safeRestrictor = "safe_restrictor_test";

const object: GameObject = MockGameObject.mock({ name: "safe_restrictor_test" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe("should correctly generate stalker patrol jobs", () => {
const terrain: SmartTerrain = MockSmartTerrain.mock("test_smart");

terrain.defendRestrictor = "test_defend_restrictor";
terrain.smartTerrainActorControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;

const object: GameObject = MockGameObject.mock({ name: "some_restrictor" });

Expand Down Expand Up @@ -117,7 +117,7 @@ describe("should correctly generate stalker patrol jobs", () => {
const terrain: SmartTerrain = MockSmartTerrain.mock("test_smart");

terrain.defendRestrictor = "test_defend_restrictor";
terrain.smartTerrainActorControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.safeRestrictor = "safe_restrictor_test";

const object: GameObject = MockGameObject.mock({ name: "safe_restrictor_test" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("should correctly generate stalkers point jobs", () => {
const terrain: SmartTerrain = MockSmartTerrain.mock("test_smart");

terrain.defendRestrictor = "def_restrictor_test";
terrain.smartTerrainActorControl = { ignoreZone: "test_ignore_zone" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "test_ignore_zone" } as SmartTerrainControl;

const [jobs, builder] = createStalkerPointJobs(terrain, new LuaTable(), new StringBuilder());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ anim = {!npc_community(zombied)} sit, guard
builder.append(string.format("out_restr = %s\n", smartTerrain.defendRestrictor));
}

if (smartTerrain.smartTerrainActorControl !== null && smartTerrain.smartTerrainActorControl.ignoreZone !== null) {
if (smartTerrain.terrainControl !== null && smartTerrain.terrainControl.ignoreZone !== null) {
// todo: Probably smart.base_on_actor_control.ignore_zone should be injected? Original issue.
builder.append(
`combat_ignore_cond = {=npc_in_zone(smart.base_on_actor_control.ignore_zone)} true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("jobs_general should correctly generate stalkers sleep jobs", () => {
const terrain: SmartTerrain = MockSmartTerrain.mock("test_smart");

terrain.defendRestrictor = "def_restrictor_test";
terrain.smartTerrainActorControl = { ignoreZone: "test_ignore_zone" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "test_ignore_zone" } as SmartTerrainControl;

const [jobs, builder] = createStalkerSleepJobs(terrain, new LuaTable(), new StringBuilder());

Expand Down Expand Up @@ -89,7 +89,7 @@ describe("jobs_general should correctly generate stalkers sleep jobs", () => {
jest.spyOn(object, "inside").mockImplementation(() => true);

terrain.defendRestrictor = "def_restrictor_test";
terrain.smartTerrainActorControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;

const [jobs, builder] = createStalkerSleepJobs(terrain, new LuaTable(), new StringBuilder());

Expand Down Expand Up @@ -122,7 +122,7 @@ describe("jobs_general should correctly generate stalkers sleep jobs", () => {
jest.spyOn(object, "inside").mockImplementation(() => true);

terrain.safeRestrictor = "safe_restrictor_test";
terrain.smartTerrainActorControl = { ignoreZone: "test_ignore_zone" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "test_ignore_zone" } as SmartTerrainControl;

const [jobs, builder] = createStalkerSleepJobs(terrain, new LuaTable(), new StringBuilder());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ path_main = sleep_%s
}

if (
smartTerrain.smartTerrainActorControl !== null &&
smartTerrain.smartTerrainActorControl.ignoreZone !== null &&
isPatrolInRestrictor(smartTerrain.smartTerrainActorControl.ignoreZone, patrolName)
smartTerrain.terrainControl !== null &&
smartTerrain.terrainControl.ignoreZone !== null &&
isPatrolInRestrictor(smartTerrain.terrainControl.ignoreZone, patrolName)
) {
builder.append(
`combat_ignore_cond = {=npc_in_zone(smart.base_on_actor_control.ignore_zone)} true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("jobs_general should correctly generate stalkers surge jobs", () => {
const terrain: SmartTerrain = MockSmartTerrain.mock("test_smart");

terrain.defendRestrictor = "def_restrictor_test";
terrain.smartTerrainActorControl = { ignoreZone: "test_ignore_zone" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "test_ignore_zone" } as SmartTerrainControl;

const [jobs, builder] = createStalkerSurgeJobs(terrain, new LuaTable(), new StringBuilder());

Expand Down Expand Up @@ -84,7 +84,7 @@ describe("jobs_general should correctly generate stalkers surge jobs", () => {
registerZone(object);

terrain.defendRestrictor = "def_restrictor_test";
terrain.smartTerrainActorControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;

const [jobs, builder] = createStalkerSurgeJobs(terrain, new LuaTable(), new StringBuilder());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def_state_moving = patrol

// Check for combat ignore restrictions.
if (
smartTerrain.smartTerrainActorControl !== null &&
smartTerrain.smartTerrainActorControl.ignoreZone !== null &&
isPatrolInRestrictor(smartTerrain.smartTerrainActorControl.ignoreZone, patrolName)
smartTerrain.terrainControl !== null &&
smartTerrain.terrainControl.ignoreZone !== null &&
isPatrolInRestrictor(smartTerrain.terrainControl.ignoreZone, patrolName)
) {
builder.append(
`combat_ignore_cond = {=npc_in_zone(smart.base_on_actor_control.ignore_zone)} true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe("jobs_general should correctly generate stalker walker jobs", () => {
const terrain: SmartTerrain = MockSmartTerrain.mock("test_smart");

terrain.defendRestrictor = "test_defend_restrictor";
terrain.smartTerrainActorControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;

const object: GameObject = MockGameObject.mock({ name: "some_restrictor" });

Expand Down Expand Up @@ -119,7 +119,7 @@ describe("jobs_general should correctly generate stalker walker jobs", () => {
const terrain: SmartTerrain = MockSmartTerrain.mock("test_smart");

terrain.defendRestrictor = "test_defend_restrictor";
terrain.smartTerrainActorControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.terrainControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl;
terrain.safeRestrictor = "safe_restrictor_test";

const object: GameObject = MockGameObject.mock({ name: "safe_restrictor_test" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def_state_moving = patrol
}

if (
smartTerrain.smartTerrainActorControl !== null &&
smartTerrain.smartTerrainActorControl.ignoreZone !== null &&
isPatrolInRestrictor(smartTerrain.smartTerrainActorControl.ignoreZone, patrolName)
smartTerrain.terrainControl !== null &&
smartTerrain.terrainControl.ignoreZone !== null &&
isPatrolInRestrictor(smartTerrain.terrainControl.ignoreZone, patrolName)
) {
builder.append(
`combat_ignore_cond = {=npc_in_zone(smart.base_on_actor_control.ignore_zone)} true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("syncObjectHitSmartTerrainAlert", () => {

syncObjectHitSmartTerrainAlert(object);

third.smartTerrainActorControl = new SmartTerrainControl(
third.terrainControl = new SmartTerrainControl(
third,
MockIniFile.mock("test.ltx", {
test_control: {
Expand All @@ -41,27 +41,27 @@ describe("syncObjectHitSmartTerrainAlert", () => {
}),
"test_control"
);
third.smartTerrainActorControl.status = ESmartTerrainStatus.NORMAL;
third.terrainControl.status = ESmartTerrainStatus.NORMAL;

jest.spyOn(third.smartTerrainActorControl, "onActorAttackSmartTerrain").mockImplementation(jest.fn());
jest.spyOn(third.terrainControl, "onActorAttackSmartTerrain").mockImplementation(jest.fn());
jest.spyOn(object.position(), "distance_to_sqr").mockImplementation(() => 6_401);

syncObjectHitSmartTerrainAlert(object);

expect(third.smartTerrainActorControl.onActorAttackSmartTerrain).not.toHaveBeenCalled();
expect(third.terrainControl.onActorAttackSmartTerrain).not.toHaveBeenCalled();

jest.spyOn(object.position(), "distance_to_sqr").mockImplementation(() => 6_400);
jest.spyOn(object, "relation").mockImplementation(() => EGameObjectRelation.ENEMY as TRelationType);

syncObjectHitSmartTerrainAlert(object);

expect(third.smartTerrainActorControl.onActorAttackSmartTerrain).toHaveBeenCalledTimes(0);
expect(third.terrainControl.onActorAttackSmartTerrain).toHaveBeenCalledTimes(0);

jest.spyOn(object.position(), "distance_to_sqr").mockImplementation(() => 6_400);
jest.spyOn(object, "relation").mockImplementation(() => EGameObjectRelation.NEUTRAL as TRelationType);

syncObjectHitSmartTerrainAlert(object);

expect(third.smartTerrainActorControl.onActorAttackSmartTerrain).toHaveBeenCalledTimes(1);
expect(third.terrainControl.onActorAttackSmartTerrain).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export function syncObjectHitSmartTerrainAlert(object: GameObject): void {
const terrain: SmartTerrain = descriptor.smartTerrain;

if (
terrain.smartTerrainActorControl &&
terrain.terrainControl &&
graph.vertex(terrain.m_game_vertex_id).level_id() === actorVertexLevelId &&
object.position().distance_to_sqr(terrain.position) <= 6_400
) {
terrain.smartTerrainActorControl.onActorAttackSmartTerrain();
terrain.terrainControl.onActorAttackSmartTerrain();

return;
}
Expand Down
Loading

0 comments on commit a792450

Please sign in to comment.