Skip to content

Commit

Permalink
Minor encounter tweaks and map header exporter script
Browse files Browse the repository at this point in the history
- Don't remove loot from fallen party members
- Add toggles for random encounter tweaks
- Python script for mass-dumping map headers to YAML
  • Loading branch information
phobos2077 committed Jun 8, 2024
1 parent fff5267 commit 52e079c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
53 changes: 53 additions & 0 deletions proto_src/maps_dump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# pip install pyyaml
#
# written by phobos2077 with help of Bing Chat

import glob
import os
import struct
import yaml
from typing import List, Dict
from collections import namedtuple
from fallout_enums import *

CALIBERS = []

def flagsAsHex(flags):
return hex(flags % (1<<32))

def readFile(file_path: str) -> Dict:
with open(file_path, 'rb') as f:
data = f.read()
keys = ['version', 'name', 'startTile', 'startElevation', 'startRotation', 'lvarCount', 'scrIdx', 'flags', 'darkness', 'gvarCount', 'index', 'lastVisitTime']
# Header = namedtuple('Header', 'version name startTile startElevation startRotation lvarCount scrIdx flags darkness gvarCount index lastVisitTime')
head = dict(zip(keys, struct.unpack('>i16siiiiiiiiii', data[:60])))
head['name'] = head['name'].decode('ascii').rstrip('\0')
return head

def writeFile(file_path: str, data: Dict):
with open(file_path, 'w') as f:
yaml.dump(data, f, sort_keys = False, default_style = '')

def main(file_pattern: str, output_dir: str):
files = glob.glob(file_pattern)
for file in files:
try:
data = readFile(file)
os.makedirs(output_dir, exist_ok = True)
writeFile(os.path.join(output_dir, f'{os.path.splitext(os.path.basename(file))[0]}.yml'), data)
except Exception as e:
print("Error map proto " + file + ": ", e)

print("Written " + str(len(files)) + " text files.")

if __name__ == '__main__':
import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('file_pattern', help='A blob pattern for MAP files')
parser.add_argument('output_dir', help='Output directory')
args = parser.parse_args()

main(args.file_pattern, args.output_dir)
3 changes: 3 additions & 0 deletions proto_src/maps_dump_vanilla.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ECHO OFF
py .\maps_dump.py d:\GAMES\!Arhives\Fallout\VANILLA\master.dat\maps\*.map d:\GAMES\!Arhives\Fallout\VANILLA\maps\
py .\maps_dump.py c:\Projects\fo2_rp\data\maps\*.map ..\maps_txt\yml\
7 changes: 7 additions & 0 deletions root/mods/ecco/misc.ini
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ reduce_drugs_pids=40,48,49,53,87,109,110,144,273
reduce_weapons_pids=25,26,27


[ENCOUNTERS]
; Restore Sneak state after map change
remember_sneak=1
; Make sure all ranged NPC's have spare ammo
ensure_npcs_ammo=1


[TOWN_REP]
0=47 ; ARROYO
2=48 ; KLAMATH
Expand Down
3 changes: 2 additions & 1 deletion scripts_src/_pbs_main/gl_pbs_critter_loot.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ procedure ondeath_handler begin
return;

if (critter and obj_type(critter) == OBJ_TYPE_CRITTER) then begin
if (ini_reduce_ammo_percent[1] > 0 or ini_reduce_drugs_percent > 0 or ini_destroy_weapon_percent > 0) then begin
if (not obj_in_party(critter)
and (ini_reduce_ammo_percent[1] > 0 or ini_reduce_drugs_percent > 0 or ini_destroy_weapon_percent > 0)) then begin
call reduce_loot(critter);
end
if (ini_weapon_drop_chance > 0 and random(1, 100) <= ini_weapon_drop_chance) then begin
Expand Down
16 changes: 13 additions & 3 deletions scripts_src/_pbs_main/gl_pbs_random_encounters.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
#include "../sfall/define_extra.h"

#include "../_pbs_headers/ecco_ids.h"
#include "../_pbs_headers/ecco_ini.h"
#include "../_pbs_headers/ecco_log.h"
#include "../_pbs_headers/maps_utils.h"

variable begin
ini_remember_sneak;
ini_ensure_npcs_ammo;
encounter_map_id;
was_using_sneak;
end
Expand Down Expand Up @@ -98,24 +101,31 @@ end

procedure map_enter_p_proc begin
//display_msg("gl map_enter_proc");
if (was_using_sneak) then begin
if (ini_remember_sneak and was_using_sneak) then begin
show_iface_tag(0);
was_using_sneak := false;
end
if (encounter_map_id >= 0 and cur_map_index == encounter_map_id) then begin
call ensure_npcs_ammo;
if (ini_ensure_npcs_ammo) then
call ensure_npcs_ammo;

//call relocate_party_to_random_start_point;
end
encounter_map_id := -1;
end

procedure map_exit_p_proc begin
was_using_sneak := is_iface_tag_active(0);
was_using_sneak := ini_remember_sneak and is_iface_tag_active(0);
//display_msg("gl map_exit_proc " + is_iface_tag_active(0));
end

#define INI_FILE INI_MISC
#define INI_SECTION "ENCOUNTERS"

procedure start begin
if (game_loaded) then begin
load_bool_from_ini(remember_sneak, false);
load_bool_from_ini(ensure_npcs_ammo, false);
encounter_map_id := -1;
register_hook_proc(HOOK_ENCOUNTER, encounter_hook);
end
Expand Down

0 comments on commit 52e079c

Please sign in to comment.