Skip to content

Commit

Permalink
Docs correction. Move StateManagerWeapon utils to separate folder. Do…
Browse files Browse the repository at this point in the history
… not use spawn_ini(), use global ini ref.
  • Loading branch information
Neloreck committed Aug 25, 2023
1 parent 3ea540c commit d41b059
Show file tree
Hide file tree
Showing 24 changed files with 143 additions and 139 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { system_ini } from "xray16";

import { SYSTEM_INI } from "@/engine/core/database";
import { AbstractCoreManager } from "@/engine/core/managers/base/AbstractCoreManager";
import { executeConsoleCommand } from "@/engine/core/utils/game/game_console";
import { readIniString } from "@/engine/core/utils/ini";
Expand All @@ -18,7 +17,7 @@ export class ActorInventoryMenuManager extends AbstractCoreManager {
* todo: Description.
*/
public override initialize(): void {
const ini: IniFile = system_ini();
const ini: IniFile = SYSTEM_INI;

executeConsoleCommand(consoleCommands.slot_0, readIniString(ini, ACTOR, "quick_item_1", false, "", ""));
executeConsoleCommand(consoleCommands.slot_1, readIniString(ini, ACTOR, "quick_item_2", false, "", ""));
Expand Down
4 changes: 2 additions & 2 deletions src/engine/core/objects/ai/state/StalkerStateManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { action_planner, level, look, object, time_global } from "xray16";

import { StalkerAnimationManager } from "@/engine/core/objects/ai/state/StalkerAnimationManager";
import { getObjectAnimationWeapon } from "@/engine/core/objects/ai/state/weapon/StateManagerWeapon";
import { EStateActionId, EStateEvaluatorId } from "@/engine/core/objects/ai/types";
import { EAnimationType, EWeaponAnimation } from "@/engine/core/objects/animation/animation_types";
import {
Expand All @@ -14,6 +13,7 @@ import {
import { states } from "@/engine/core/objects/animation/states";
import { assert } from "@/engine/core/utils/assertion";
import { LuaLogger } from "@/engine/core/utils/logging";
import { getObjectWeaponForAnimationState } from "@/engine/core/utils/object/object_weapon";
import { areSameVectors, createVector, subVectors } from "@/engine/core/utils/vector";
import { ZERO_VECTOR } from "@/engine/lib/constants/vectors";
import {
Expand Down Expand Up @@ -120,7 +120,7 @@ export class StalkerStateManager {
nextStateDescriptorWeapon !== EWeaponAnimation.SNIPER_FIRE
) {
if (this.object.active_item() && this.object.best_weapon() && this.object.weapon_unstrapped()) {
this.object.set_item(object.idle, getObjectAnimationWeapon(this.object, state));
this.object.set_item(object.idle, getObjectWeaponForAnimationState(this.object, state));
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/engine/core/objects/ai/state/state/ActionStateEnd.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { action_base, level, LuabindClass, object, time_global } from "xray16";

import { StalkerStateManager } from "@/engine/core/objects/ai/state/StalkerStateManager";
import { getObjectIdleState, getStateQueueParams } from "@/engine/core/objects/ai/state/weapon/StateManagerWeapon";
import { EWeaponAnimation } from "@/engine/core/objects/animation";
import { states } from "@/engine/core/objects/animation/states";
import { LuaLogger } from "@/engine/core/utils/logging";
import { getObjectSmartCoverStateQueueParams } from "@/engine/core/utils/object";
import { isStalker, isWeapon } from "@/engine/core/utils/object/object_class";
import { getWeaponStateForAnimationState } from "@/engine/core/utils/object/object_weapon";
import { ClientObject, EClientObjectRelation, Optional, TDuration, TRate, TTimestamp } from "@/engine/lib/types";

const logger: LuaLogger = new LuaLogger($filename);

// todo: Move out.
const AIM_RATIO: TRate = 1000 / 50;
const MIN_RATIO: TRate = 1500;
const SNIPER_AIM_TIME: TDuration = 3000;
Expand Down Expand Up @@ -87,7 +89,10 @@ export class ActionStateEnd extends action_base {

this.object.set_item(object.fire1, this.object.best_weapon(), 1, sniperAimDuration);
} else {
const [value] = getStateQueueParams(this.object, states.get(this.stateManager.targetState!));
const [value] = getObjectSmartCoverStateQueueParams(
this.object,
states.get(this.stateManager.targetState!)
);

this.object.set_item(object.fire1, this.object.best_weapon(), value);
}
Expand All @@ -104,22 +109,22 @@ export class ActionStateEnd extends action_base {
if (targetWeaponState === EWeaponAnimation.SNIPER_FIRE) {
this.object.set_item(object.fire1, this.object.best_weapon(), 1, sniperAimDuration);
} else {
const [value] = getStateQueueParams(this.object, states.get(this.stateManager.targetState!));
const [value] = getObjectSmartCoverStateQueueParams(this.object, states.get(this.stateManager.targetState!));

this.object.set_item(object.fire1, this.object.best_weapon(), value);
}

return;
}

const [value] = getStateQueueParams(this.object, states.get(this.stateManager.targetState!));
const [value] = getObjectSmartCoverStateQueueParams(this.object, states.get(this.stateManager.targetState!));

this.object.set_item(object.fire1, this.object.best_weapon(), value);

return;
} else if (targetWeaponState === EWeaponAnimation.UNSTRAPPED) {
// Unstrap weapon.
this.object.set_item(getObjectIdleState(this.stateManager.targetState), this.object.best_weapon());
this.object.set_item(getWeaponStateForAnimationState(this.stateManager.targetState), this.object.best_weapon());
}
}
}
3 changes: 1 addition & 2 deletions src/engine/core/objects/ai/state/state/ActionStateToIdle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export class ActionStateToIdle extends action_base {
* Starting resetting state to idle for object.
*/
public override initialize(): void {
logger.info("State to idle for:", this.object.name(), this.name);

super.initialize();

this.object.inactualize_patrol_path();
Expand All @@ -42,6 +40,7 @@ export class ActionStateToIdle extends action_base {
public override execute(): void {
super.execute();

// If any animation is active in state manager, reset everything for client object.
if (this.stateManager.targetState !== EStalkerState.IDLE) {
this.object.clear_animations();
this.stateManager.setState(EStalkerState.IDLE, null, null, null, { isForced: true });
Expand Down
10 changes: 5 additions & 5 deletions src/engine/core/objects/ai/state/weapon/ActionWeaponDrop.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { action_base, LuabindClass, object } from "xray16";

import { StalkerStateManager } from "@/engine/core/objects/ai/state/StalkerStateManager";
import { getObjectAnimationWeapon } from "@/engine/core/objects/ai/state/weapon/StateManagerWeapon";
import { LuaLogger } from "@/engine/core/utils/logging";
import { isStrappableWeapon, setItemCondition } from "@/engine/core/utils/object";
import { getObjectWeaponForAnimationState } from "@/engine/core/utils/object/object_weapon";
import { logicsConfig } from "@/engine/lib/configs/LogicsConfig";
import { ClientObject, Optional } from "@/engine/lib/types";

const logger: LuaLogger = new LuaLogger($filename);

/**
* todo;
* Action to drop active item.
* In case if item is not stappable, just hide all active items.
*/
@LuabindClass()
export class ActionWeaponDrop extends action_base {
Expand All @@ -26,15 +27,14 @@ export class ActionWeaponDrop extends action_base {
* If object has no weapon, just select no weapon active.
*/
public override initialize(): void {
logger.info("Drop weapon for:", this.object.name());

super.initialize();

const weapon: Optional<ClientObject> = getObjectAnimationWeapon(this.object, this.stateManager.targetState);
const weapon: Optional<ClientObject> = getObjectWeaponForAnimationState(this.object, this.stateManager.targetState);

if (isStrappableWeapon(weapon)) {
this.object.set_item(object.drop, weapon);

// todo: Is it needed?
setItemCondition(
weapon,
math.random(
Expand Down
2 changes: 0 additions & 2 deletions src/engine/core/objects/ai/state/weapon/ActionWeaponNone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export class ActionWeaponNone extends action_base {
* Select no weapon active.
*/
public override initialize(): void {
logger.info("Set weapon none for:", this.object.name());

super.initialize();
this.object.set_item(object.idle, null);
}
Expand Down
8 changes: 3 additions & 5 deletions src/engine/core/objects/ai/state/weapon/ActionWeaponStrap.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { action_base, LuabindClass, object } from "xray16";

import { StalkerStateManager } from "@/engine/core/objects/ai/state/StalkerStateManager";
import { getObjectAnimationWeapon } from "@/engine/core/objects/ai/state/weapon/StateManagerWeapon";
import { LuaLogger } from "@/engine/core/utils/logging";
import { isStrappableWeapon } from "@/engine/core/utils/object";
import { getObjectWeaponForAnimationState } from "@/engine/core/utils/object/object_weapon";
import { ClientObject, Optional } from "@/engine/lib/types";

const logger: LuaLogger = new LuaLogger($filename);

/**
* todo;
* Strap active weapon item if it is stapable.
*/
@LuabindClass()
export class ActionWeaponStrap extends action_base {
Expand All @@ -24,11 +24,9 @@ export class ActionWeaponStrap extends action_base {
* Strap active weapon.
*/
public override initialize(): void {
logger.info("Strap weapon for:", this.object.name());

super.initialize();

const weapon: Optional<ClientObject> = getObjectAnimationWeapon(this.object, this.stateManager.targetState);
const weapon: Optional<ClientObject> = getObjectWeaponForAnimationState(this.object, this.stateManager.targetState);

if (isStrappableWeapon(weapon)) {
this.object.set_item(object.strap, weapon);
Expand Down
14 changes: 8 additions & 6 deletions src/engine/core/objects/ai/state/weapon/ActionWeaponUnstrap.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { action_base, LuabindClass } from "xray16";

import { StalkerStateManager } from "@/engine/core/objects/ai/state/StalkerStateManager";
import { getObjectAnimationWeapon, getObjectIdleState } from "@/engine/core/objects/ai/state/weapon/StateManagerWeapon";
import { LuaLogger } from "@/engine/core/utils/logging";
import {
getObjectWeaponForAnimationState,
getWeaponStateForAnimationState,
} from "@/engine/core/utils/object/object_weapon";

const logger: LuaLogger = new LuaLogger($filename);

/**
* todo;
* Unstrap active weapon item.
*/
@LuabindClass()
export class ActionWeaponUnstrap extends action_base {
Expand All @@ -22,12 +25,11 @@ export class ActionWeaponUnstrap extends action_base {
* Unstrap active animation weapon.
*/
public override initialize(): void {
logger.info("Unstrap weapon for:", this.object.name());

super.initialize();

this.object.set_item(
getObjectIdleState(this.stateManager.targetState),
getObjectAnimationWeapon(this.object, this.stateManager.targetState)
getWeaponStateForAnimationState(this.stateManager.targetState),
getObjectWeaponForAnimationState(this.object, this.stateManager.targetState)
);
}
}
2 changes: 1 addition & 1 deletion src/engine/core/objects/ai/state/weapon/EvaluatorWeapon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StalkerStateManager } from "@/engine/core/objects/ai/state/StalkerState
import { EWeaponAnimation } from "@/engine/core/objects/animation";
import { states } from "@/engine/core/objects/animation/states";
import { LuaLogger } from "@/engine/core/utils/logging";
import { isStrappableWeapon, isWeapon } from "@/engine/core/utils/object";
import { isStrappableWeapon } from "@/engine/core/utils/object";
import { ClientObject, Optional } from "@/engine/lib/types";

const logger: LuaLogger = new LuaLogger($filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { LuaLogger } from "@/engine/core/utils/logging";
const logger: LuaLogger = new LuaLogger($filename);

/**
* Whether object in fire weapon state.
* Whether object is in fire weapon state.
*/
@LuabindClass()
export class EvaluatorWeaponFire extends property_evaluator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isObjectWeaponLocked } from "@/engine/core/utils/object/object_weapon";
const logger: LuaLogger = new LuaLogger($filename);

/**
* Whether weapon state is locked.
* Whether weapon state is locked and cannot be used.
*/
@LuabindClass()
export class EvaluatorWeaponLocked extends property_evaluator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { LuaLogger } from "@/engine/core/utils/logging";
const logger: LuaLogger = new LuaLogger($filename);

/**
* Whether object should hide weapon at all.
* Whether object should hide weapon.
*/
@LuabindClass()
export class EvaluatorWeaponNone extends property_evaluator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LuaLogger } from "@/engine/core/utils/logging";
const logger: LuaLogger = new LuaLogger($filename);

/**
* Whether have no weapon in hands at all.
* Whether object has no weapon in hands right now.
*/
@LuabindClass()
export class EvaluatorWeaponNoneNow extends property_evaluator {
Expand Down
87 changes: 0 additions & 87 deletions src/engine/core/objects/ai/state/weapon/StateManagerWeapon.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/engine/core/objects/animation/state_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export interface IStateDescriptor {
bodystate: Optional<TMoveType>;
animstate: Optional<TName>;
animation: Optional<TName>;
weapon_slot?: Optional<TIndex>;
weaponSlot?: Optional<TIndex>;
direction?: TLookType | TSightType;
special_danger_move?: Optional<boolean>;
isForced?: Optional<boolean>;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/objects/animation/states/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ export const baseStates: LuaTable<TName, IStateDescriptor> = $fromObject<TName,
},
[EStalkerState.PSY_SHOOT]: {
weapon: EWeaponAnimation.FIRE,
weapon_slot: 1,
weaponSlot: 1,
movement: move.stand,
mental: anim.free,
bodystate: move.standing,
Expand Down
Loading

0 comments on commit d41b059

Please sign in to comment.