Moved hard-coded "ControlCombat" mod from sfall into a global script #87

- Exactly the same functionality and settings
- Mod settings are now in sfall-mods.ini
This commit is contained in:
phobos2077
2017-04-01 21:11:19 +07:00
parent 9531fcbebd
commit 116c522bdc
7 changed files with 83 additions and 93 deletions
+10
View File
@@ -22,3 +22,13 @@ OutlineColor=32
; 1 - requires Motion Scanner present in player inventory to activate highlighting
; 2 - requires Motion Scanner and also requires 1 charge on every use (depleted scanner will not work anymore)
MotionScanner=2
[CombatControl]
;Allows you to directly control other critters in combat
;Set to 0 to disable
;Set to 1 to control all critters in combat
;Set to 2 to control all party members
;If you want to control only specific critters, uncomment the PIDList line and set a comma delimited list of PIDs
Mode=0
;PIDList=62,89,97,107,160,161
-8
View File
@@ -515,14 +515,6 @@ DialogPanelAnimDelay=33
;Controls the speed of pipboy alarm clock animations (lower - faster; valid range: 0..127)
PipboyTimeAnimDelay=50
;Allows you to directly control other critters in combat
;Set to 0 to disable
;Set to 1 to control all critters in combat
;Set to 2 to control all party members
;If you want to control only specific critters, uncomment the ControlCombatPIDList line and set a comma delimited list of PIDs
ControlCombat=0
;ControlCombatPIDList=62,89,97,107,160,161
;Set to 1 to stack empty identical weapons, no matter what type of ammo was loaded before
StackEmptyWeapons=0
Binary file not shown.
+51
View File
@@ -0,0 +1,51 @@
/*
NPC Combat Control
Allows to take control of your party member or other NPCs during combat
NOTE: this script requires compiler from sfall modderspack with -s option
(short circuit evaluation)
version 1.0
*/
#include "main.h"
variable
configSection := "CombatControl",
controlMode,
pidList;
procedure combatturn_handler begin
variable
status := get_sfall_arg,
critter := get_sfall_arg,
arg3 := get_sfall_arg,
pid;
// display_msg("Combat Turn: " + status + ", by " + obj_name(critter) + ", arg3: " + arg3);
pid := obj_pid(critter);
if (status == 1
and (len_array(pidList) == 0 or scan_array(pidList, pid bwand 0xFFFFFF) != -1)
and (controlMode == 1 or party_member_obj(pid))) then begin
set_dude_obj(critter);
end else begin
set_dude_obj(real_dude_obj);
end
end
procedure start begin
if game_loaded then begin
controlMode := GetConfig("CombatControl", "Mode", 0);
if (controlMode > 2) then controlMode := 0;
if (controlMode > 0) then begin
pidList := GetConfigListInt("CombatControl", "PIDList");
fix_array(pidList);
register_hook_proc(HOOK_COMBATTURN, combatturn_handler);
end
end
end
+19
View File
@@ -24,6 +24,25 @@ procedure GetConfigStr(variable section, variable key, variable def) begin
return val;
end
// Gets the value from ddraw.ini as a temp array of strings
procedure GetConfigList(variable section, variable key) begin
variable val := get_ini_string(ini + "|" + section + "|" + key);
if val == -1 or val == "" then return [];
return string_split(val, ",");
end
// Gets the value from ddraw.ini as a temp array of ints
procedure GetConfigListInt(variable section, variable key) begin
variable arr, i, item;
arr := GetConfigList(section, key);
for (i := 0; i < len_array(arr); i++) begin
arr[i] := atoi(arr[i]);
end
return arr;
end
// Translates given string using Translations.ini
procedure Translate(variable id, variable def) begin
variable str := get_ini_string(translationIni + "|Sfall|" + id);
-41
View File
@@ -604,46 +604,5 @@ procedure _PURGE_all_saved_arrays begin
free_array(load_array(key));
end
// temp_list* functions are deprecated since we have array expressions
#define _LIST_ELEMENT_SIZE 128
procedure temp_list2(variable x1, variable x2) begin
variable a;
a := temp_array(2, _LIST_ELEMENT_SIZE);
a[0] := x1; a[1] := x2;
return a;
end
procedure temp_list3(variable x1, variable x2, variable x3) begin
variable a;
a := temp_array(3, _LIST_ELEMENT_SIZE);
a[0] := x1; a[1] := x2; a[2] := x3;
return a;
end
procedure temp_list4(variable x1, variable x2, variable x3, variable x4) begin
variable a;
a := temp_array(4, _LIST_ELEMENT_SIZE);
a[0] := x1; a[1] := x2; a[2] := x3; a[3] := x4;
return a;
end
procedure temp_list6(variable x1, variable x2, variable x3, variable x4, variable x5, variable x6) begin
variable a;
a := temp_array(6, _LIST_ELEMENT_SIZE);
a[0] := x1; a[1] := x2; a[2] := x3; a[3] := x4; a[4] := x5; a[5] := x6;
return a;
end
procedure temp_list8(variable x1, variable x2, variable x3, variable x4, variable x5, variable x6, variable x7, variable x8) begin
variable a;
a := temp_array(8, _LIST_ELEMENT_SIZE);
a[0] := x1; a[1] := x2; a[2] := x3; a[3] := x4; a[4] := x5; a[5] := x6; a[6] := x7; a[7] := x8;
return a;
end
#undef _LIST_ELEMENT_SIZE
#endif
+3 -44
View File
@@ -56,11 +56,6 @@ static struct DudeState {
//DWORD bbox_sneak;
} realDude;
static bool _stdcall IsInPidList(fo::GameObject* obj) {
int pid = obj->protoId & 0xFFFFFF;
return std::find(allowedCritterPids.begin(), allowedCritterPids.end(), pid) != allowedCritterPids.end();
}
// saves the state of PC before moving control to NPC
static void SaveRealDudeState() {
realDude.obj_dude = fo::var::obj_dude;
@@ -164,26 +159,6 @@ static void RestoreRealDudeState() {
isControllingNPC = false;
}
// return values: 0 - use vanilla handler, 1 - skip vanilla handler, return 0 (normal status), -1 - skip vanilla, return -1 (game ended)
/*static int _stdcall CombatWrapperInner(fo::GameObject* obj) {
if ((obj != fo::var::obj_dude) && (allowedCritterPids.size() == 0 || IsInPidList(obj)) && (controlMode == 1 || fo::func::isPartyMember(obj))) {
// save "real" dude state
SaveRealDudeState();
SetCurrentDude(obj);
// Do combat turn
int turnResult = fo::func::combat_turn(obj, 1);
// restore state
if (isControllingNPC) { // if game was loaded during turn, PartyControlReset() was called and already restored state
RestoreRealDudeState();
}
// -1 means that combat ended during turn
return (turnResult == -1) ? -1 : 1;
}
return 0;
}*/
static void __stdcall DisplayCantDoThat() {
fo::func::display_print(fo::GetMessageStr(&fo::var::proto_main_msg_file, 675)); // I Can't do that
}
@@ -256,26 +231,10 @@ fo::GameObject* PartyControl::RealDudeObject() {
}
void PartyControl::init() {
controlMode = GetConfigInt("Misc", "ControlCombat", 0);
if (controlMode > 2) {
controlMode = 0;
}
if (controlMode > 0) {
auto pidList = GetConfigList("Misc", "ControlCombatPIDList", "", 512);
if (pidList.size() > 0) {
for (auto &pid : pidList) {
allowedCritterPids.push_back(static_cast<WORD>(strtoul(pid.c_str(), 0, 0)));
}
}
dlog_f(" Mode %d, Chars read: %d.\n", DL_INIT, controlMode, allowedCritterPids.size());
LoadGameHook::OnGameReset() += PartyControlReset;
HookCall(0x454218, stat_pc_add_experience_hook); // call inside op_give_exp_points_hook
HookCalls(pc_flag_toggle_hook, { 0x4124F1, 0x41279A });
LoadGameHook::OnGameReset() += PartyControlReset;
} else {
dlogr(" Disabled.", DL_INIT);
}
HookCall(0x454218, stat_pc_add_experience_hook); // call inside op_give_exp_points_hook
HookCalls(pc_flag_toggle_hook, { 0x4124F1, 0x41279A });
}
}