Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
Adjusted logics of help wounded/search corpse when few corpses exist.
Removed unused imports / comments.
Merge latest dev changes.
Updated logics schemes.
Update state manager generation tests.
  • Loading branch information
Neloreck committed Aug 23, 2023
1 parent 092bef7 commit ccd3eb9
Show file tree
Hide file tree
Showing 35 changed files with 514 additions and 320 deletions.
21 changes: 20 additions & 1 deletion src/engine/core/database/objects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { setPortableStoreValue } from "@/engine/core/database/portable_store";
import { registry } from "@/engine/core/database/registry";
import { IRegistryObjectState } from "@/engine/core/database/types";
import { ClientObject, Optional } from "@/engine/lib/types";
import { HELPING_WOUNDED_OBJECT_KEY } from "@/engine/lib/constants/portable_store_keys";
import { ClientObject, Optional, TNumberId } from "@/engine/lib/types";

/**
* Register client object in RAM registry.
Expand Down Expand Up @@ -47,3 +49,20 @@ export function resetObject(object: ClientObject, state: Partial<IRegistryObject

return state as IRegistryObjectState;
}

/**
* todo;
*/
export function registerWoundedObject(object: ClientObject): void {
const objectId: TNumberId = object.id();

registry.objectsWounded.set(objectId, registry.objects.get(objectId));
}

/**
* todo;
*/
export function unRegisterWoundedObject(object: ClientObject): void {
setPortableStoreValue(object.id(), HELPING_WOUNDED_OBJECT_KEY, null);
registry.objectsWounded.delete(object.id());
}
3 changes: 2 additions & 1 deletion src/engine/core/database/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { registry } from "@/engine/core/database/registry";

describe("registry storage", () => {
it("storage to contain all fields", () => {
expect(Object.keys(registry)).toHaveLength(38);
expect(Object.keys(registry)).toHaveLength(39);
});

it("storage to initialize with correct data", () => {
Expand All @@ -16,6 +16,7 @@ describe("registry storage", () => {
expect(registry.cache.conditionLists instanceof LuaTable).toBeTruthy();
expect(registry.actorCombat instanceof LuaTable).toBeTruthy();
expect(registry.objects instanceof LuaTable).toBeTruthy();
expect(registry.objectsWounded instanceof LuaTable).toBeTruthy();
expect(registry.offlineObjects instanceof LuaTable).toBeTruthy();
expect(registry.simulationObjects instanceof LuaTable).toBeTruthy();
expect(registry.storyLink.sidById instanceof LuaTable).toBeTruthy();
Expand Down
4 changes: 4 additions & 0 deletions src/engine/core/database/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export const registry = {
* List of offline objects.
*/
offlineObjects: new LuaTable<TNumberId, IStoredOfflineObject>(),
/**
* List of wounded objects.
*/
objectsWounded: new LuaTable<TNumberId, IRegistryObjectState>(),
/**
* List of objects participating in alife simulation.
*/
Expand Down
11 changes: 0 additions & 11 deletions src/engine/core/database/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,6 @@ export interface IRegistryObjectState extends Record<EScheme, Optional<IBaseSche
* todo;
*/
mute: Optional<boolean>;
/**
* ID of object currently looting object.
* Used to prevent looting of same object by multiple objects at once.
*
* todo: Move to loot scheme state, not store it in global. Probaly pstore is correct place.
*/
lootedByObject: Optional<TNumberId>;
/**
* todo;
*/
wounded_already_selected: Optional<TNumberId>;
/**
* todo;
*/
Expand Down
5 changes: 3 additions & 2 deletions src/engine/core/objects/animation/animations/base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IAnimationDescriptor } from "@/engine/core/objects/animation/animation_types";
import { EStalkerState } from "@/engine/core/objects/animation/state_types";
import { finishCorpseLooting } from "@/engine/core/schemes/corpse_detection/utils";
import { finishHelpWounded } from "@/engine/core/schemes/help_wounded/utils";
import { finishObjectHelpWounded } from "@/engine/core/schemes/help_wounded/utils";
import { createSequence } from "@/engine/core/utils/animation";
import { getExtern } from "@/engine/core/utils/binding";
import { startPlayingGuitar, startPlayingHarmonica } from "@/engine/core/utils/camp";
Expand Down Expand Up @@ -1017,8 +1017,9 @@ export const baseAnimations: LuaTable<TName, IAnimationDescriptor> = $fromObject
"dinamit_1",
{
// When animation ends, finish help wounded and heal up.
// todo: Probably just handle as callback in action object? Why setting globally?
f: (object: ClientObject) => {
finishHelpWounded(object);
finishObjectHelpWounded(object);
},
},
]),
Expand Down
4 changes: 2 additions & 2 deletions src/engine/core/objects/binders/camp/CampBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class CampBinder extends object_binder {
return false;
}

logger.info("Spawn camp:", this.object.name());
// logger.info("Spawn camp:", this.object.name());

const ini: IniFile = this.object.spawn_ini();

Expand All @@ -62,7 +62,7 @@ export class CampBinder extends object_binder {
* Handle net destroy event.
*/
public override net_destroy(): void {
logger.info("Destroy camp:", this.object.name());
// logger.info("Destroy camp:", this.object.name());

unregisterCamp(this.object);
super.net_destroy();
Expand Down
9 changes: 5 additions & 4 deletions src/engine/core/objects/binders/creature/StalkerBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ export class StalkerBinder extends object_binder {
this.state.stateManager!.animation.setState(null, true);
}

this.updateLightState(this.object);
DropManager.getInstance().onObjectDeath(this.object);

if (this.state[EScheme.REACH_TASK]) {
emitSchemeEvent(this.object, this.state[EScheme.REACH_TASK], ESchemeEvent.DEATH, victim, who);
}
Expand All @@ -507,9 +510,6 @@ export class StalkerBinder extends object_binder {
emitSchemeEvent(this.object, this.state[this.state.activeScheme!]!, ESchemeEvent.DEATH, victim, who);
}

this.updateLightState(this.object);
DropManager.getInstance().onObjectDeath(this.object);

unregisterHelicopterEnemy(this.helicopterEnemyIndex!);
unregisterStalker(this, false);

Expand All @@ -526,14 +526,15 @@ export class StalkerBinder extends object_binder {
}

EventsManager.emitEvent(EGameEvent.STALKER_KILLED, this.object, who);

ReleaseBodyManager.getInstance().addDeadBody(this.object);
}

/**
* todo: Description.
*/
public onUse(object: ClientObject, who: ClientObject): void {
logger.info("Stalker use:", this.object.name(), "by", who.name());
logger.info("Stalker used:", this.object.name(), "by", who.name());

if (this.object.alive()) {
EventsManager.emitEvent(EGameEvent.STALKER_INTERACTION, object, who);
Expand Down
14 changes: 7 additions & 7 deletions src/engine/core/objects/binders/zones/AnomalyZoneBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class AnomalyZoneBinder extends object_binder {

const filename: Optional<string> = readIniString(this.ini, ANOMAL_ZONE_SECTION, "cfg", false, "", null);

logger.info("Init anomaly zone from file:", object.name(), filename);
// logger.info("Init anomaly zone from file:", object.name(), filename);

if (filename !== null) {
this.ini = new ini_file(filename);
Expand Down Expand Up @@ -146,12 +146,12 @@ export class AnomalyZoneBinder extends object_binder {
"{+actor_was_in_many_bad_places} coeff2, coeff"
);

logger.info("Init zone layers (picked/count):", this.currentZoneLayer, this.zoneLayersCount);
// logger.info("Init zone layers (picked/count):", this.currentZoneLayer, this.zoneLayersCount);

for (const i of $range(1, this.zoneLayersCount)) {
const section: string = ANOMAL_ZONE_LAYER + i;

logger.info("Init layer:", section);
// logger.info("Init layer:", section);

this.layersRespawnTriesTable.set(
section,
Expand Down Expand Up @@ -231,7 +231,7 @@ export class AnomalyZoneBinder extends object_binder {
this.minesTable.set(section, new LuaTable());

if (ini.line_count(minesSection) > 0) {
logger.info("Init mines for section:", section, minesSection);
// logger.info("Init mines for section:", section, minesSection);
for (const i of $range(0, ini.line_count(minesSection) - 1)) {
const [temp1, mineName, temp2] = ini.r_line(minesSection, i, "", "");

Expand Down Expand Up @@ -291,7 +291,7 @@ export class AnomalyZoneBinder extends object_binder {
* todo: Description.
*/
public disableAnomalyFields(): void {
logger.info("Disable anomaly fields:", this.object.name());
// logger.info("Disable anomaly fields:", this.object.name());

if (!this.isCustomPlacement) {
this.isDisabled = true;
Expand Down Expand Up @@ -398,7 +398,7 @@ export class AnomalyZoneBinder extends object_binder {
* todo: Description.
*/
public spawnRandomArtefact(): void {
logger.info("Spawn random artefact:", this.object.name(), this.currentZoneLayer);
// logger.info("Spawn random artefact:", this.object.name(), this.currentZoneLayer);

const layer: string = this.currentZoneLayer;
let randomArtefact: string = "";
Expand Down Expand Up @@ -466,7 +466,7 @@ export class AnomalyZoneBinder extends object_binder {
* todo: Description.
*/
public getRandomArtefactPath(): string {
logger.info("Get artefact path:", this.object.name());
// logger.info("Get artefact path:", this.object.name());

const paths: LuaArray<string> = new LuaTable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class LevelChangerBinder extends object_binder {
this.object.enable_level_changer(serverObject.isEnabled);
this.object.set_level_changer_invitation(serverObject.invitationHint);

logger.info("Net spawned:", this.object.id(), serverObject.isEnabled, serverObject.invitationHint);
logger.info("Net spawned level changer:", this.object.id(), serverObject.isEnabled, serverObject.invitationHint);

return true;
}
Expand Down
8 changes: 0 additions & 8 deletions src/engine/core/objects/server/smart_terrain/SmartTerrain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,14 +752,6 @@ export class SmartTerrain extends cse_alife_smart_zone implements ISimulationTar
if (selectedJobId !== objectJobDescriptor.jobId && selectedJobLink !== null) {
this.unlinkObjectJob(objectJobDescriptor);

logger.format(
"Select new job: %s -> %s / %s, in '%s'",
objectJobDescriptor.object.name(),
selectedJobLink.id,
selectedJobLink.section,
this.name()
);

// Link new job.
selectedJobLink.objectId = objectJobDescriptor.object.id;
this.objectByJobSection.set(this.jobs.get(selectedJobLink.id as TNumberId).section, selectedJobLink.objectId);
Expand Down
1 change: 0 additions & 1 deletion src/engine/core/objects/state/StalkerMoveManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ export class StalkerMoveManager {
{ context: this, callback: this.onAnimationUpdate, turnEndCallback: this.onAnimationTurnEnd },
this.ptWaitTime,
{ lookPosition: lookPosition, lookObjectId: null },
null
);
}

Expand Down
12 changes: 11 additions & 1 deletion src/engine/core/objects/state/add_state_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ describe("add_state_manager util", () => {
"ToIdleItems",
[
[EEvaluatorId.IS_STATE_IDLE_ITEMS, false],
[EEvaluatorId.IS_WOUNDED, false],
[EEvaluatorId.IS_WOUNDED_EXISTING, false],
[mockStalkerIds.property_items, true],
[mockStalkerIds.property_enemy, false],
],
Expand All @@ -198,7 +200,15 @@ describe("add_state_manager util", () => {
[[EEvaluatorId.IS_STATE_IDLE_ALIFE, true]]
);

checkAction(planner.action(EActionId.ALIFE), "generic", [[EEvaluatorId.IS_STATE_IDLE_ALIFE, true]], []);
checkAction(
planner.action(EActionId.ALIFE),
"generic",
[
[EEvaluatorId.IS_STATE_IDLE_ALIFE, true],
[mockStalkerIds.property_items, false],
],
[]
);
checkAction(
planner.action(mockStalkerIds.action_gather_items),
"generic",
Expand Down
3 changes: 3 additions & 0 deletions src/engine/core/objects/state/add_state_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export function addStateManager(object: ClientObject): StalkerStateManager {
actionItemsToIdle.add_precondition(new world_property(EEvaluatorId.IS_STATE_IDLE_ITEMS, false));
actionItemsToIdle.add_precondition(new world_property(stalker_ids.property_items, true));
actionItemsToIdle.add_precondition(new world_property(stalker_ids.property_enemy, false));
actionItemsToIdle.add_precondition(new world_property(EEvaluatorId.IS_WOUNDED, false));
actionItemsToIdle.add_precondition(new world_property(EEvaluatorId.IS_WOUNDED_EXISTING, false));
actionItemsToIdle.add_effect(new world_property(EEvaluatorId.IS_STATE_IDLE_ITEMS, true));

planner.add_action(EActionId.STATE_TO_IDLE_ITEMS, actionItemsToIdle);
Expand All @@ -68,6 +70,7 @@ export function addStateManager(object: ClientObject): StalkerStateManager {
planner.add_action(EActionId.STATE_TO_IDLE_ALIFE, actionAlifeToIdle);

planner.action(EActionId.ALIFE).add_precondition(new world_property(EEvaluatorId.IS_STATE_IDLE_ALIFE, true));
planner.action(EActionId.ALIFE).add_precondition(new world_property(stalker_ids.property_items, false));

planner
.action(stalker_ids.action_gather_items)
Expand Down
6 changes: 6 additions & 0 deletions src/engine/core/objects/state/state/ActionStateToIdle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export class ActionStateToIdle extends action_base {
sendToNearestAccessibleVertex(this.object, this.object.level_vertex_id());
}

public override finalize(): void {
super.finalize();

logger.info("End state to idle for:", this.object.name(), this.name);
}

/**
* Rest object state to idle.
*/
Expand Down
21 changes: 12 additions & 9 deletions src/engine/core/objects/state/weapon/EvaluatorWeaponLocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LuabindClass, property_evaluator } from "xray16";

import { StalkerStateManager } from "@/engine/core/objects/state/StalkerStateManager";
import { LuaLogger } from "@/engine/core/utils/logging";
import { isWeapon } from "@/engine/core/utils/object";
import { ClientObject, Optional } from "@/engine/lib/types";

const logger: LuaLogger = new LuaLogger($filename);
Expand All @@ -22,24 +23,26 @@ export class EvaluatorWeaponLocked extends property_evaluator {
* todo: Description.
*/
public override evaluate(): boolean {
const bestWeapon: Optional<ClientObject> = this.object.best_weapon();

if (bestWeapon === null) {
return false;
}

if (!isWeapon(bestWeapon)) {
return false;
}

const isWeaponStrapped: boolean = this.object.weapon_strapped();
const isWeaponUnstrapped: boolean = this.object.weapon_unstrapped();

if (!(isWeaponUnstrapped || isWeaponStrapped)) {
return true;
}

const bestWeapon: Optional<ClientObject> = this.object.best_weapon();

if (bestWeapon === null) {
return false;
}

const isWeaponGoingToBeStrapped: boolean = this.object.is_weapon_going_to_be_strapped(bestWeapon);

if (isWeaponGoingToBeStrapped && !isWeaponStrapped) {
return true;
} else if (!isWeaponGoingToBeStrapped && !isWeaponUnstrapped && this.object.active_item() !== null) {
if (isWeaponGoingToBeStrapped && (!isWeaponStrapped || isWeaponUnstrapped)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/schemes/abuse/actions/ActionAbuseHit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { action_base, LuabindClass } from "xray16";

import { registry, setStalkerState } from "@/engine/core/database";
import { setStalkerState } from "@/engine/core/database";
import { EStalkerState } from "@/engine/core/objects/animation";
import { ISchemeAbuseState } from "@/engine/core/schemes/abuse/ISchemeAbuseState";
import { ACTOR_ID } from "@/engine/lib/constants/ids";
Expand Down
8 changes: 4 additions & 4 deletions src/engine/core/schemes/combat_idle/PostCombatIdle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cast_planner, stalker_ids, world_property } from "xray16";

import { registry } from "@/engine/core/database";
import { ActionPostCombatIdleWait } from "@/engine/core/schemes/combat_idle/actions";
import { EvaluatorPostCombatIdleEnemy } from "@/engine/core/schemes/combat_idle/evaluators";
import { EvaluatorHasEnemy } from "@/engine/core/schemes/combat_idle/evaluators";
import { ISchemePostCombatIdleState } from "@/engine/core/schemes/combat_idle/ISchemePostCombatIdleState";
import { LuaLogger } from "@/engine/core/utils/logging";
import { ActionBase, ActionPlanner, ClientObject } from "@/engine/lib/types";
Expand All @@ -18,7 +18,7 @@ export class PostCombatIdle {
* todo: Description.
*/
public static addPostCombatIdleWait(object: ClientObject): void {
logger.info("Add post-combat idle for:", object.name());
// logger.info("Add post-combat idle for:", object.name());

const actionPlanner: ActionPlanner = object.motivation_action_manager();
const combatAction: ActionBase = actionPlanner.action(stalker_ids.action_combat_planner);
Expand All @@ -34,10 +34,10 @@ export class PostCombatIdle {
registry.objects.get(object.id()).post_combat_wait = state;

actionPlanner.remove_evaluator(stalker_ids.property_enemy);
actionPlanner.add_evaluator(stalker_ids.property_enemy, new EvaluatorPostCombatIdleEnemy(state));
actionPlanner.add_evaluator(stalker_ids.property_enemy, new EvaluatorHasEnemy(state));

combatActionPlanner.remove_evaluator(stalker_ids.property_enemy);
combatActionPlanner.add_evaluator(stalker_ids.property_enemy, new EvaluatorPostCombatIdleEnemy(state));
combatActionPlanner.add_evaluator(stalker_ids.property_enemy, new EvaluatorHasEnemy(state));
combatActionPlanner.remove_action(stalker_ids.action_post_combat_wait);

const actionPostCombatIdleWait: ActionPostCombatIdleWait = new ActionPostCombatIdleWait(state);
Expand Down
Loading

0 comments on commit ccd3eb9

Please sign in to comment.