Loader
logo

Follow-up: A pet dog blocks to retreat from battle field

Started by tos1, April 03, 2024, 02:55:20 PM

Previous topic - Next topic
Related topic:
A pet dog blocks to retreat from battle field

It is about an issue where we cannot use the Tab key to leave the battle field when the pet dog is nearby. I disassembled the code and have just found out the cause and the solution.

Current code (v9.3)
---- cf_check_enemies_nearby in script.txt
get_player_agent_no ":L0"   # 1700 1 1224979098644774912
agent_is_alive ":L0"   # 1702 1 1224979098644774912
agent_get_position 1 ":L0"   # 1710 2 1 1224979098644774912
assign ":L1" 0   # 2133 2 1224979098644774913 0
set_fixed_point_multiplier 100   # 2124 1 100
try_for_agents ":L2"   # 12 1 1224979098644774914
  neq ":L2" ":L0"   # 2147483679 2 1224979098644774914 1224979098644774912
  agent_is_alive ":L2"   # 1702 1 1224979098644774914
  agent_is_human ":L2"   # 1704 1 1224979098644774914
  agent_is_ally|neg ":L2"   # 2147485354 1 1224979098644774914
  this_or_next|neq "$wolf_companion" 1   # 3221225503 2 144115188075855957 1
  this_or_next|neq "$dog_companion" 1   # 3221225503 2 144115188075855959 1
  this_or_next|neq ":L2" "$player_wolf_agent_no"   # 3221225503 2 1224979098644774914 144115188075856612
  neq ":L2" "$player_dog_agent_no"   # 2147483679 2 1224979098644774914 144115188075856614
  agent_get_position 2 ":L2"   # 1710 2 2 1224979098644774914
  get_distance_between_positions ":L3" 1 2   # 710 3 1224979098644774915 1 2
  lt ":L3" 1000   # 2147483678 2 1224979098644774915 1000
  assign ":L1" 1   # 2133 2 1224979098644774913 1
try_end   # 3 0
eq ":L1" 0   # 31 2 1224979098644774913 0
----

Currently, the code block for dog/wolf is OR of 4 conditions, so when loop variable L2 is the pet dog agent and there is no wolf in the party, it badly proceed to the distance check.

A correct logic should be:
"if (A and B) or (C and D) then skip to next agent"
As you know, if we write this as code as is, we will need to add variables and registers for flags, so let's convert it to "not( AND of not(OR)s )" using De Morgan's law:
"if not ( (not A or not B) and (not C or not D) ) then skip to next agent"
In other words,
"if (not A or not B) and (not C or not D) then check distance"

I don't know if we can have the dog and wolf in the party at the same time, but that case also should cause no problem at the last logic above. That's because the loop variable ":L2" cannot represent two agents at the same time and "if (not TRUE or not TRUE) and (not TRUE or not TRUE)" never happen even if both animal is in the party.

In conclusion, it is necessary to add a try-block as shown below, and the judgement of "$player_wolf_agent_no" must be "neq" immediately after "$wolf_companion", and the 4 judgements and the distance checking must be in the newly added try-block.

A correct code.
---- cf_check_enemies_nearby in script.txt
get_player_agent_no ":L0"   # 1700 1 1224979098644774912
agent_is_alive ":L0"   # 1702 1 1224979098644774912
agent_get_position 1 ":L0"   # 1710 2 1 1224979098644774912
assign ":L1" 0   # 2133 2 1224979098644774913 0
set_fixed_point_multiplier 100   # 2124 1 100
try_for_agents ":L2"   # 12 1 1224979098644774914
  neq ":L2" ":L0"   # 2147483679 2 1224979098644774914 1224979098644774912
  agent_is_alive ":L2"   # 1702 1 1224979098644774914
  agent_is_human ":L2"   # 1704 1 1224979098644774914
  agent_is_ally|neg ":L2"   # 2147485354 1 1224979098644774914
  try_begin   # 4 0
    this_or_next|neq "$wolf_companion" 1   # 3221225503 2 144115188075855957 1
    neq ":L2" "$player_wolf_agent_no"   # 2147483679 2 1224979098644774914 144115188075856612
    this_or_next|neq "$dog_companion" 1   # 3221225503 2 144115188075855959 1
    neq ":L2" "$player_dog_agent_no"   # 2147483679 2 1224979098644774914 144115188075856614
    agent_get_position 2 ":L2"   # 1710 2 2 1224979098644774914
    get_distance_between_positions ":L3" 1 2   # 710 3 1224979098644774915 1 2
    lt ":L3" 1000   # 2147483678 2 1224979098644774915 1000
    assign ":L1" 1   # 2133 2 1224979098644774913 1
  try_end   # 3 0
try_end   # 3 0
eq ":L1" 0   # 31 2 1224979098644774913 0
----

After experimentally editing the relevant part of the txt file as shown above, I tried Tab key in cases below and found no problem:
"Only the dog is nearby", "Dog and ally soldier are nearby", "Only enemy soldiers are nearby", "Dog and enemy soldiers are nearby", "Only ally soldiers are nearby", "No one is nearby".

I haven't tried the case where both the dog and wolf are in the party at the same time.

- How to reproduce it/when/why it happens:
Play until you get the pet dog or pet wolf, start a battle, hit Tab key when the dog is near the player. Try that also for all conceivable cases.

- Game version (and steam or downloaded):
AWoIaF v9.3, Warband v1.174 downloaded
(Note: v8.* and v7.11 has the same logic in the script.)

Quick Reply

Note: this post will not display until it has been approved by a moderator.

Name:
Email:
Shortcuts: ALT+S post or ALT+P preview