Skip to content

Commit

Permalink
Fixed issue with frozen monster logics. Monster script capturing norm…
Browse files Browse the repository at this point in the history
…alized. Moved related utils to scheme/monster. Added tests for monster capturing utils.
  • Loading branch information
Neloreck committed Jun 20, 2023
1 parent 270f847 commit 1b4eb37
Show file tree
Hide file tree
Showing 24 changed files with 286 additions and 205 deletions.
1 change: 1 addition & 0 deletions src/engine/core/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from "@/engine/core/database/doors";
export * from "@/engine/core/database/helicopters";
export * from "@/engine/core/database/ini";
export * from "@/engine/core/database/ini_registry";
export * from "@/engine/core/database/logic";
export * from "@/engine/core/database/managers";
export * from "@/engine/core/database/monster";
export * from "@/engine/core/database/objects";
Expand Down
18 changes: 6 additions & 12 deletions src/engine/core/database/logic.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { time_global } from "xray16";

import {
closeLoadMarker,
closeSaveMarker,
IRegistryObjectState,
loadPortableStore,
openSaveMarker,
registry,
savePortableStore,
} from "@/engine/core/database";
import { openLoadMarker } from "@/engine/core/database/save_markers";
import { ESchemeEvent, IBaseSchemeState } from "@/engine/core/schemes";
import { emitSchemeEvent } from "@/engine/core/utils/scheme/logic";
import { loadPortableStore, savePortableStore } from "@/engine/core/database/portable_store";
import { registry } from "@/engine/core/database/registry";
import { closeLoadMarker, closeSaveMarker, openLoadMarker, openSaveMarker } from "@/engine/core/database/save_markers";
import { IRegistryObjectState } from "@/engine/core/database/types";
import { ESchemeEvent, IBaseSchemeState } from "@/engine/core/schemes/base/types";
import { emitSchemeEvent } from "@/engine/core/utils/scheme/event";
import { readTimeFromPacket, writeTimeToPacket } from "@/engine/core/utils/time";
import { NIL } from "@/engine/lib/constants/words";
import {
Expand Down
28 changes: 14 additions & 14 deletions src/engine/core/objects/binders/creature/MonsterBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {
closeSaveMarker,
IRegistryObjectState,
IStoredOfflineObject,
loadObjectLogic,
openLoadMarker,
openSaveMarker,
registerObject,
registry,
resetObject,
saveObjectLogic,
unregisterObject,
} from "@/engine/core/database";
import { loadObjectLogic, saveObjectLogic } from "@/engine/core/database/logic";
import { openLoadMarker } from "@/engine/core/database/save_markers";
import { StatisticsManager } from "@/engine/core/managers/interface/StatisticsManager";
import { GlobalSoundManager } from "@/engine/core/managers/sounds/GlobalSoundManager";
import { setupSmartJobsAndLogicOnSpawn } from "@/engine/core/objects/server/smart_terrain/jobs_general";
Expand All @@ -22,18 +23,17 @@ import { Squad } from "@/engine/core/objects/server/squad/Squad";
import { TSimulationObject } from "@/engine/core/objects/server/types";
import { ESchemeEvent, IBaseSchemeState } from "@/engine/core/schemes";
import { SchemeHear } from "@/engine/core/schemes/hear/SchemeHear";
import { pickSectionFromCondList } from "@/engine/core/utils/ini/config";
import { pickSectionFromCondList } from "@/engine/core/utils/ini";
import { TConditionList } from "@/engine/core/utils/ini/types";
import { LuaLogger } from "@/engine/core/utils/logging";
import { action, getObjectSquad } from "@/engine/core/utils/object/object_general";
import {
action,
getObjectSquad,
isObjectScriptCaptured,
scriptCaptureObject,
scriptReleaseObject,
} from "@/engine/core/utils/object/object_general";
import { emitSchemeEvent } from "@/engine/core/utils/scheme/logic";
import { trySwitchToAnotherSection } from "@/engine/core/utils/scheme/switch";
emitSchemeEvent,
isMonsterScriptCaptured,
scriptCaptureMonster,
scriptReleaseMonster,
trySwitchToAnotherSection,
} from "@/engine/core/utils/scheme";
import { createEmptyVector } from "@/engine/core/utils/vector";
import { MAX_U16 } from "@/engine/lib/constants/memory";
import {
Expand Down Expand Up @@ -106,8 +106,8 @@ export class MonsterBinder extends object_binder {
}

if (this.object.get_enemy()) {
if (isObjectScriptCaptured(this.object)) {
scriptReleaseObject(this.object, MonsterBinder.__name);
if (isMonsterScriptCaptured(this.object)) {
scriptReleaseMonster(this.object);
}

return;
Expand All @@ -122,7 +122,7 @@ export class MonsterBinder extends object_binder {

const [targetPosition] = currentTarget.getGameLocation();

scriptCaptureObject(this.object, true, MonsterBinder.__name);
scriptCaptureMonster(this.object, true);

if (squad.commander_id() === this.object.id()) {
action(this.object, new move(move.walk_with_leader, targetPosition), new cond(cond.move_end));
Expand Down
3 changes: 1 addition & 2 deletions src/engine/core/objects/binders/creature/StalkerBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ import {
updateObjectInvulnerability,
} from "@/engine/core/utils/object/object_general";
import { setObjectsRelation, setObjectSympathy } from "@/engine/core/utils/relation";
import { emitSchemeEvent } from "@/engine/core/utils/scheme/logic";
import { trySwitchToAnotherSection } from "@/engine/core/utils/scheme/switch";
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";
Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/schemes/camper/CampStoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isObjectMeeting } from "@/engine/core/utils/check/check";
import { parseStringsList } from "@/engine/core/utils/ini/parse";
import { readIniString } from "@/engine/core/utils/ini/read";
import { LuaLogger } from "@/engine/core/utils/logging";
import { emitSchemeEvent } from "@/engine/core/utils/scheme/logic";
import { emitSchemeEvent } from "@/engine/core/utils/scheme";
import {
ClientObject,
EScheme,
Expand Down
7 changes: 4 additions & 3 deletions src/engine/core/schemes/mob_jump/MobJumpManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { cond, look, patrol } from "xray16";
import { AbstractSchemeManager } from "@/engine/core/schemes";
import { ISchemeMobJumpState } from "@/engine/core/schemes/mob_jump/ISchemeMobJumpState";
import { abort } from "@/engine/core/utils/assertion";
import { action, scriptCaptureObject, scriptReleaseObject } from "@/engine/core/utils/object/object_general";
import { action } from "@/engine/core/utils/object/object_general";
import { scriptCaptureMonster, scriptReleaseMonster } from "@/engine/core/utils/scheme";
import { addVectors } from "@/engine/core/utils/vector";
import { Optional, Patrol, Vector } from "@/engine/lib/types";

Expand All @@ -23,7 +24,7 @@ export class MobJumpManager extends AbstractSchemeManager<ISchemeMobJumpState> {
* todo: Description.
*/
public override resetScheme(): void {
scriptCaptureObject(this.object, true, MobJumpManager.name);
scriptCaptureMonster(this.object, true, MobJumpManager.name);

// -- reset signals
this.state.signals = new LuaTable();
Expand Down Expand Up @@ -64,7 +65,7 @@ export class MobJumpManager extends AbstractSchemeManager<ISchemeMobJumpState> {
if (this.stateCurrent === STATE_JUMP) {
this.object.jump(this.point!, this.state.ph_jump_factor);
this.state.signals!.set("jumped", true);
scriptReleaseObject(this.object, MobJumpManager.name);
scriptReleaseMonster(this.object);
}
}
}
5 changes: 3 additions & 2 deletions src/engine/core/schemes/mob_remark/MobRemarkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { abort } from "@/engine/core/utils/assertion";
import { getExtern } from "@/engine/core/utils/binding";
import { pickSectionFromCondList } from "@/engine/core/utils/ini/config";
import { parseStringsList } from "@/engine/core/utils/ini/parse";
import { action, scriptCaptureObject } from "@/engine/core/utils/object/object_general";
import { action } from "@/engine/core/utils/object/object_general";
import { scriptCaptureMonster } from "@/engine/core/utils/scheme/monster";
import { AnyCallablesModule, LuaArray, MonsterBodyStateKey, Optional, TName } from "@/engine/lib/types";

/**
Expand All @@ -26,7 +27,7 @@ export class MobRemarkManager extends AbstractSchemeManager<ISchemeMobRemarkStat

this.object.disable_talk();

scriptCaptureObject(this.object, !this.state.no_reset);
scriptCaptureMonster(this.object, !this.state.no_reset);

const animationsList: LuaArray<TName> = parseStringsList(this.state.anim);

Expand Down
20 changes: 10 additions & 10 deletions src/engine/core/schemes/mob_walker/MobWalkerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { anim, cond, look, move, patrol, sound } from "xray16";

import { registry, setMonsterState } from "@/engine/core/database";
import { StalkerMoveManager } from "@/engine/core/objects/state/StalkerMoveManager";
import { AbstractSchemeManager } from "@/engine/core/schemes";
import { AbstractSchemeManager } from "@/engine/core/schemes/base";
import { ISchemeMobWalkerState } from "@/engine/core/schemes/mob_walker/ISchemeMobWalkerState";
import { abort } from "@/engine/core/utils/assertion";
import { pickSectionFromCondList } from "@/engine/core/utils/ini/config";
import { parseWaypointsData } from "@/engine/core/utils/ini/parse";
import { parseWaypointsData, pickSectionFromCondList } from "@/engine/core/utils/ini";
import { IWaypointData } from "@/engine/core/utils/ini/types";
import { action, isObjectScriptCaptured, scriptCaptureObject } from "@/engine/core/utils/object/object_general";
import { action } from "@/engine/core/utils/object/object_general";
import { isStalkerAtWaypoint } from "@/engine/core/utils/position";
import { isMonsterScriptCaptured, scriptCaptureMonster } from "@/engine/core/utils/scheme/monster";
import { copyVector } from "@/engine/core/utils/vector";
import { EMonsterState } from "@/engine/lib/constants/monsters";
import { NIL, TRUE } from "@/engine/lib/constants/words";
Expand Down Expand Up @@ -62,7 +62,7 @@ export class MobWalkerManager extends AbstractSchemeManager<ISchemeMobWalkerStat
setMonsterState(this.object, this.state.state);

this.state.signals = new LuaTable();
scriptCaptureObject(this.object, true);
scriptCaptureMonster(this.object, true);

this.patrolWalk = new patrol(this.state.path_walk);

Expand Down Expand Up @@ -109,7 +109,7 @@ export class MobWalkerManager extends AbstractSchemeManager<ISchemeMobWalkerStat
* todo: Description.
*/
public update(): void {
if (!isObjectScriptCaptured(this.object)) {
if (!isMonsterScriptCaptured(this.object)) {
this.resetScheme();

return;
Expand Down Expand Up @@ -235,7 +235,7 @@ export class MobWalkerManager extends AbstractSchemeManager<ISchemeMobWalkerStat
* todo: Description.
*/
public updateMovementState(): void {
scriptCaptureObject(this.object, true);
scriptCaptureMonster(this.object, true);

let m;

Expand Down Expand Up @@ -268,7 +268,7 @@ export class MobWalkerManager extends AbstractSchemeManager<ISchemeMobWalkerStat
* todo: Description.
*/
public updateStandingState(): void {
scriptCaptureObject(this.object, true);
scriptCaptureMonster(this.object, true);

if (this.scheduledSound) {
action(
Expand All @@ -287,7 +287,7 @@ export class MobWalkerManager extends AbstractSchemeManager<ISchemeMobWalkerStat
* todo: Description.
*/
public override deactivate(): void {
scriptCaptureObject(this.object, true);
scriptCaptureMonster(this.object, true);
action(this.object, new move(move.steal, this.patrolWalk!.point(0)), new cond(cond.move_end));
}

Expand All @@ -304,7 +304,7 @@ export class MobWalkerManager extends AbstractSchemeManager<ISchemeMobWalkerStat
lookPoint.normalize();
// --this.object:set_sight(look.direction, look_pt, 0)

scriptCaptureObject(this.object, true);
scriptCaptureMonster(this.object, true);
action(this.object, new look(look.direction, lookPoint), new cond(cond.look_end));

this.lastLookIndex = pt;
Expand Down
11 changes: 5 additions & 6 deletions src/engine/core/schemes/ph_minigun/MinigunManager.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { CCar, level, move, patrol, time_global } from "xray16";

import { getObjectByStoryId, registry } from "@/engine/core/database";
import { AbstractSchemeManager } from "@/engine/core/schemes";
import { AbstractSchemeManager } from "@/engine/core/schemes/base";
import { ISchemeMinigunState } from "@/engine/core/schemes/ph_minigun/ISchemeMinigunState";
import { abort } from "@/engine/core/utils/assertion";
import { isHeavilyWounded } from "@/engine/core/utils/check/check";
import { isActiveSection } from "@/engine/core/utils/check/is";
import { pickSectionFromCondList } from "@/engine/core/utils/ini/config";
import { TConditionList } from "@/engine/core/utils/ini/types";
import { isObjectScriptCaptured, scriptReleaseObject } from "@/engine/core/utils/object/object_general";
import { pickSectionFromCondList, TConditionList } from "@/engine/core/utils/ini";
import { isMonsterScriptCaptured, scriptReleaseMonster } from "@/engine/core/utils/scheme";
import { switchObjectSchemeToSection, trySwitchToAnotherSection } from "@/engine/core/utils/scheme/switch";
import { createEmptyVector, createVector, yaw } from "@/engine/core/utils/vector";
import { ACTOR, NIL } from "@/engine/lib/constants/words";
Expand Down Expand Up @@ -311,7 +310,7 @@ export class MinigunManager extends AbstractSchemeManager<ISchemeMinigunState> {
}

if (this.stateCannon === STATE_CANNON_STOP && this.stateFiretarget === STATE_NONE) {
if (isObjectScriptCaptured(this.object) && !this.object.action()) {
if (isMonsterScriptCaptured(this.object) && !this.object.action()) {
this.destroyCar();

return true;
Expand Down Expand Up @@ -439,7 +438,7 @@ export class MinigunManager extends AbstractSchemeManager<ISchemeMinigunState> {
this.mgun.Action(CCar.eWpnAutoFire, 0);
this.setShooting(this.stateShooting);

scriptReleaseObject(this.object, MinigunManager.name);
scriptReleaseMonster(this.object);

if (this.state.on_death_info !== null) {
registry.actor.give_info_portion(this.state.on_death_info);
Expand Down
5 changes: 2 additions & 3 deletions src/engine/core/schemes/sr_cutscene/SchemeCutscene.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { AbstractScheme, ESchemeEvent } from "@/engine/core/schemes";
import { CutsceneManager } from "@/engine/core/schemes/sr_cutscene/CutsceneManager";
import { ISchemeCutsceneState } from "@/engine/core/schemes/sr_cutscene/ISchemeCutsceneState";
import { getConfigSwitchConditions } from "@/engine/core/utils/ini/config";
import { parseStringsList } from "@/engine/core/utils/ini/parse";
import { getConfigSwitchConditions, parseStringsList } from "@/engine/core/utils/ini";
import { readIniBoolean, readIniNumber, readIniString } from "@/engine/core/utils/ini/read";
import { LuaLogger } from "@/engine/core/utils/logging";
import { emitSchemeEvent } from "@/engine/core/utils/scheme/logic";
import { emitSchemeEvent } from "@/engine/core/utils/scheme";
import { NIL } from "@/engine/lib/constants/words";
import { ClientObject, EScheme, ESchemeType, IniFile, TSection } from "@/engine/lib/types";

Expand Down
7 changes: 4 additions & 3 deletions src/engine/core/schemes/sr_monster/MonsterManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { registry } from "@/engine/core/database";
import { GlobalSoundManager } from "@/engine/core/managers/sounds/GlobalSoundManager";
import { AbstractSchemeManager } from "@/engine/core/schemes";
import { ISchemeMonsterState } from "@/engine/core/schemes/sr_monster/ISchemeMonsterState";
import { action, scriptCaptureObject, scriptReleaseObject } from "@/engine/core/utils/object/object_general";
import { action } from "@/engine/core/utils/object/object_general";
import { scriptCaptureMonster, scriptReleaseMonster } from "@/engine/core/utils/scheme";
import { trySwitchToAnotherSection } from "@/engine/core/utils/scheme/switch";
import { copyVector, subVectors } from "@/engine/core/utils/vector";
import { sounds } from "@/engine/lib/constants/sound/sounds";
Expand Down Expand Up @@ -88,7 +89,7 @@ export class MonsterManager extends AbstractSchemeManager<ISchemeMonsterState> {
this.monsterObject!.position().distance_to(this.state.path.point(this.state.path.count() - 1)) <= 1)
) {
if (registry.objects.has(this.monster!.id)) {
scriptReleaseObject(this.monsterObject!, MonsterManager.name);
scriptReleaseMonster(this.monsterObject as ClientObject);
}

alife().release(this.monster, true);
Expand Down Expand Up @@ -127,7 +128,7 @@ export class MonsterManager extends AbstractSchemeManager<ISchemeMonsterState> {
) {
this.monsterObject = registry.objects.get(this.monster.id).object!;

scriptCaptureObject(this.monsterObject, true, MonsterManager.name);
scriptCaptureMonster(this.monsterObject, true);

action(
this.monsterObject,
Expand Down
4 changes: 4 additions & 0 deletions src/engine/core/utils/ini/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "@/engine/core/utils/ini/config";
export * from "@/engine/core/utils/ini/parse";
export * from "@/engine/core/utils/ini/read";
export * from "@/engine/core/utils/ini/types";
49 changes: 3 additions & 46 deletions src/engine/core/utils/object/object_general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IRegistryObjectState, registry } from "@/engine/core/database";
import { AnomalyZoneBinder, SmartTerrain } from "@/engine/core/objects";
import { Squad } from "@/engine/core/objects/server/squad/Squad";
import { EStalkerState } from "@/engine/core/objects/state";
import { abort, assertDefined } from "@/engine/core/utils/assertion";
import { assert, assertDefined } from "@/engine/core/utils/assertion";
import { isCseAlifeObject, isStalker } from "@/engine/core/utils/check/is";
import { getInfosFromData, pickSectionFromCondList } from "@/engine/core/utils/ini/config";
import { parseConditionsList } from "@/engine/core/utils/ini/parse";
Expand Down Expand Up @@ -198,9 +198,9 @@ export function action(object: Optional<ClientObject>, ...actions: Array<TEntity
/**
* todo;
*/
export function resetObjectAction(object: ClientObject, scriptName: TName): void {
export function resetMonsterAction(object: ClientObject, scriptName: TName): void {
if (object.get_script()) {
object.script(false, scriptName);
object.script(false, object.get_script_name());
}

object.script(true, scriptName);
Expand Down Expand Up @@ -516,49 +516,6 @@ export function isObjectAsleep(object: ClientObject): boolean {
return registry.objects.get(object.id()).stateManager!.animstate.states.currentState === EStalkerState.SLEEP;
}

/**
* todo;
* todo;
* todo;
*/
export function scriptReleaseObject(object: ClientObject, scriptName: TName = $filename): void {
if (object.get_script()) {
object.script(false, scriptName);
}
}

/**
* todo;
* todo;
* todo;
*/
export function scriptCaptureObject(
object: ClientObject,
resetActions: Optional<boolean>,
scriptName: TName = $filename
): void {
if (resetActions === null) {
abort("mob_capture: reset_actions parameter's value is !specified");
}

if (resetActions !== null) {
resetObjectAction(object, scriptName);
} else {
if (!object.get_script()) {
object.script(true, scriptName);
}
}
}

/**
* todo;
* todo;
* todo;
*/
export function isObjectScriptCaptured(object: ClientObject): boolean {
return object.get_script() !== null;
}

/**
* Check whether object is in provided smart terrain (name).
*
Expand Down
Loading

0 comments on commit 1b4eb37

Please sign in to comment.