Skip to content

Commit 3e7eb4a

Browse files
committed
Try enums
1 parent edab3f1 commit 3e7eb4a

17 files changed

Lines changed: 217 additions & 345 deletions

‎src/base.d.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Fallout 2 engine builtins (external - not bundled into output)
22

3-
import type { ObjectPtr, CritterPtr, ItemPtr, DoorPtr, ContainerPtr, SkillID, ObjType, StatID, InvenSlot, TraitType, FloatMsgColor, PerkID, TraitID, PcStatID, CritterState, Elevation, Direction, Difficulty, RollResult } from "./index";
3+
import type { ObjectPtr, CritterPtr, ItemPtr, DoorPtr, ContainerPtr, SKILL, ObjType, STAT, InvenSlot, TraitType, FloatMsgColor, PerkID, TraitID, PcStatID, CritterState, Elevation, Direction, Difficulty, RollResult } from "./index";
44

55
// =============================================================================
66
// Runtime Globals
@@ -194,13 +194,13 @@ export declare function critter_state(who: CritterPtr): CritterState;
194194
export declare function critter_inven_obj(who: CritterPtr, slot: InvenSlot): ItemPtr;
195195

196196
/** Returns a critter stat value */
197-
export declare function get_critter_stat(who: CritterPtr, stat: StatID): number;
197+
export declare function get_critter_stat(who: CritterPtr, stat: STAT): number;
198198

199199
/**
200200
* DOES NOT SET THE STAT.
201201
* Modifies attribute `stat` in critter `who` by value `mod`.
202202
*/
203-
export declare function set_critter_stat(who: CritterPtr, stat: StatID, mod: number): number;
203+
export declare function set_critter_stat(who: CritterPtr, stat: STAT, mod: number): number;
204204

205205
/** Returns true if the critter has its FLEE flag set */
206206
export declare function critter_is_fleeing(who: CritterPtr): boolean;
@@ -234,7 +234,7 @@ export declare function has_trait(traitType: TraitType, who: ObjectPtr, trait: n
234234
* Note: Only works on dude_obj! Will not work on other critters.
235235
* For tagged skills, the amount will be rounded down to the closest even number.
236236
*/
237-
export declare function critter_mod_skill(who: CritterPtr, skill: SkillID, amount: number): number;
237+
export declare function critter_mod_skill(who: CritterPtr, skill: SKILL, amount: number): number;
238238

239239
/** Returns the critter's poison level */
240240
export declare function get_poison(who: CritterPtr): number;
@@ -430,7 +430,7 @@ export declare function terminate_combat(): void;
430430
* Returns the level of the skill (0-17) of the target critter.
431431
* Returns 0-200 for Fallout 1, 0-300 for Fallout 2.
432432
*/
433-
export declare function has_skill(who: CritterPtr, skill: SkillID): number;
433+
export declare function has_skill(who: CritterPtr, skill: SKILL): number;
434434

435435
/** Returns a pc-only stat value (PCSTAT_*) */
436436
export declare function get_pc_stat(stat: PcStatID): number;
@@ -447,10 +447,10 @@ export declare function do_check(who: CritterPtr, check: number, modifier: numbe
447447
* is_success and is_critical to determine states, and how_much can be used to
448448
* determine the difference succeeded or failed by.
449449
*/
450-
export declare function roll_vs_skill(who: CritterPtr, skill: SkillID, modifier: number): RollResult;
450+
export declare function roll_vs_skill(who: CritterPtr, skill: SKILL, modifier: number): RollResult;
451451

452452
/** Returns the value of a completed skill vs skill contest */
453-
export declare function skill_contest(skill: SkillID): RollResult;
453+
export declare function skill_contest(skill: SKILL): RollResult;
454454

455455
/** Returns true if the roll result is a success (including critical) */
456456
export declare function is_success(rollResult: RollResult): boolean;
@@ -908,7 +908,7 @@ export declare function use_obj(obj: ObjectPtr): void;
908908
export declare function use_obj_on_obj(item: ObjectPtr, target: ObjectPtr): ObjectPtr;
909909

910910
/** Returns true if an active skill is being used */
911-
export declare function using_skill(who: CritterPtr, skill: SkillID): boolean;
911+
export declare function using_skill(who: CritterPtr, skill: SKILL): boolean;
912912

913913
// =============================================================================
914914
// Named Events (sfall)

‎src/define.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Bundleable implementations for functions that need to be defined in each script
1+
// Custom defines
22

33
import { debug_msg } from "./base.d";
44

‎src/index.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export type {
33
ArrayID,
44
AttackMode,
55
AttackType,
6-
BodyPart,
76
ContainerPtr,
87
CritterPtr,
98
CritterState,
@@ -29,8 +28,6 @@ export type {
2928
SceneryPtr,
3029
SfallList,
3130
SfallMap,
32-
SkillID,
33-
StatID,
3431
TraitID,
3532
TraitType,
3633
WeaponType,
@@ -63,7 +60,6 @@ export {
6360
RIGHT_HAND,
6461
} from './types';
6562

66-
6763
// Re-export engine builtins from base.d
6864
export {
6965
action_being_used,
@@ -247,6 +243,10 @@ export {
247243
world_map,
248244
} from './base.d';
249245

246+
// Re-export enums from sfall (needed by core function signatures in base.d)
247+
export { BODY } from './sfall/define_extra';
248+
export { SKILL, STAT } from './sfall/define_lite';
249+
250250
// Re-export helpers from define
251251
export {
252252
FLOAT1,

‎src/rp/command.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { dude_obj, get_critter_stat, global_var } from "../base.d";
22
import { len_array } from "../sfall/sfall.d";
33
import { party_member_list_critters } from "../sfall/sfall";
44
import { dude_elevation } from "../sfall/command_lite";
5-
import { STAT_ch } from "../sfall/define_lite";
5+
import { STAT } from "../sfall/define_lite";
66
import { GVAR_PLAYER_GOT_CAR } from "./global";
77

88
export { dude_elevation };
99

1010
/** @inline */
1111
export function dude_charisma(): number {
12-
return get_critter_stat(dude_obj, STAT_ch);
12+
return get_critter_stat(dude_obj, STAT.ch);
1313
}
1414

1515
/** @inline */

‎src/sfall/ai_area.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// AI attack area mode values for AI_CAP_AREA_ATTACK_MODE.
2-
3-
export const ai_area_always = 0;
4-
export const ai_area_sometimes = 1;
5-
export const ai_area_be_sure = 2;
6-
export const ai_area_be_careful = 3;
7-
export const ai_area_be_absolutely_sure = 4;
1+
/** AI attack area mode values for AI_CAP.AREA_ATTACK_MODE. */
2+
export enum ai_area {
3+
always = 0,
4+
sometimes = 1,
5+
be_sure = 2,
6+
be_careful = 3,
7+
be_absolutely_sure = 4,
8+
}

‎src/sfall/ai_attack.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// AI attack-who mode values for AI_CAP_ATTACK_WHO.
2-
3-
export const ai_attack_whomever_attacking_me = 0;
4-
export const ai_attack_strongest = 1;
5-
export const ai_attack_weakest = 2;
6-
export const ai_attack_whomever = 3;
7-
export const ai_attack_closest = 4;
1+
/** AI attack-who mode values for AI_CAP.ATTACK_WHO. */
2+
export enum ai_attack {
3+
whomever_attacking_me = 0,
4+
strongest = 1,
5+
weakest = 2,
6+
whomever = 3,
7+
closest = 4,
8+
}

‎src/sfall/ai_cap.ts‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
// AI data parameter indices for get_object_ai_data / set_object_ai_data.
2-
3-
export const AI_CAP_AGGRESSION = 0;
4-
export const AI_CAP_AREA_ATTACK_MODE = 1;
5-
export const AI_CAP_ATTACK_WHO = 2;
6-
export const AI_CAP_BEST_WEAPON = 3;
7-
export const AI_CAP_CHEM_USE = 4;
8-
export const AI_CAP_DISPOSITION = 5;
9-
export const AI_CAP_DISTANCE = 6;
10-
export const AI_CAP_MAX_DISTANCE = 7;
11-
export const AI_CAP_MIN_HP = 8;
12-
export const AI_CAP_MIN_TO_HIT = 9;
13-
export const AI_CAP_HURT_TOO_MUCH = 10;
14-
export const AI_CAP_RUN_AWAY_MODE = 11;
15-
export const AI_CAP_SECONDARY_FREQ = 12;
16-
export const AI_CAP_CALLED_FREQ = 13;
17-
export const AI_CAP_CHEM_PRIMARY_DESIRE = 14;
1+
/** AI data parameter indices for get_object_ai_data / set_object_ai_data. */
2+
export enum AI_CAP {
3+
AGGRESSION = 0,
4+
AREA_ATTACK_MODE = 1,
5+
ATTACK_WHO = 2,
6+
BEST_WEAPON = 3,
7+
CHEM_USE = 4,
8+
DISPOSITION = 5,
9+
DISTANCE = 6,
10+
MAX_DISTANCE = 7,
11+
MIN_HP = 8,
12+
MIN_TO_HIT = 9,
13+
HURT_TOO_MUCH = 10,
14+
RUN_AWAY_MODE = 11,
15+
SECONDARY_FREQ = 12,
16+
CALLED_FREQ = 13,
17+
CHEM_PRIMARY_DESIRE = 14,
18+
}

‎src/sfall/ai_chem.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// AI chem-use mode values for AI_CAP_CHEM_USE.
2-
3-
export const ai_chem_clean = 0;
4-
export const ai_chem_stims_when_hurt_little = 1;
5-
export const ai_chem_stims_when_hurt_lots = 2;
6-
export const ai_chem_sometimes = 3;
7-
export const ai_chem_anytime = 4;
8-
export const ai_chem_always = 5;
1+
/** AI chem-use mode values for AI_CAP.CHEM_USE. */
2+
export enum ai_chem {
3+
clean = 0,
4+
stims_when_hurt_little = 1,
5+
stims_when_hurt_lots = 2,
6+
sometimes = 3,
7+
anytime = 4,
8+
always = 5,
9+
}

‎src/sfall/ai_disposition.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// AI disposition values for AI_CAP_DISPOSITION.
2-
3-
export const ai_disposition_none = -1;
4-
export const ai_disposition_custom = 0;
5-
export const ai_disposition_coward = 1;
6-
export const ai_disposition_defensive = 2;
7-
export const ai_disposition_aggressive = 3;
8-
export const ai_disposition_berserk = 4;
1+
/** AI disposition values for AI_CAP.DISPOSITION. */
2+
export enum ai_disposition {
3+
none = -1,
4+
custom = 0,
5+
coward = 1,
6+
defensive = 2,
7+
aggressive = 3,
8+
berserk = 4,
9+
}

‎src/sfall/ai_distance.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// AI distance values for AI_CAP_DISTANCE.
2-
3-
export const ai_distance_stay_close = 0;
4-
export const ai_distance_charge = 1;
5-
export const ai_distance_snipe = 2;
6-
export const ai_distance_on_your_own = 3;
7-
export const ai_distance_stay = 4;
1+
/** AI distance values for AI_CAP.DISTANCE. */
2+
export enum ai_distance {
3+
stay_close = 0,
4+
charge = 1,
5+
snipe = 2,
6+
on_your_own = 3,
7+
stay = 4,
8+
}

0 commit comments

Comments
 (0)