NATION

PASSWORD

1

DispatchFactbookMilitary

by IreallylikeRPGs. . 6 reads.

Warfare

These are the basic warfare rules!
The stats from the armies, be it size, attack, defence, and etcetera, affect!
Most battles are determined by rolls of dice with my python code.
If morale is lowered to 0, the side that has it at 0 is routed immediately.
If the army size is lowered to 0, or if the ruler of the nation that has it does not wish for the army to fight till death, the battle is over.

Here is the code if you want to see it:
import random

def calculate_combat_damage(
atk_army_name: str,
atk_atk_stat: int,
atk_def_stat: int,
atk_morale_percent: int,
def_army_name: str,
def_atk_stat: int, # Not used for damage, but good to track
def_def_stat: int,
def_morale_percent: int,
environment_mod: int = 0 # e.g., +2 for attack, -2 for defense
) -> dict:
"""
Calculates the damage dealt by the attacker to the defender in a single round.

Args:
atk_.../def_...: Attacker/Defender stats.
environment_mod: External modifier applied to the Attacker's roll.
(Positive for beneficial terrain, negative for bad)

Returns:
A dictionary containing the damage dealt and the roll results.
"""

# --- 1. Determine Morale Modifiers ---
# Simplified example: +2 for high morale, -2 for low morale

def get_morale_mod(morale: int) -> int:
if morale >= 75:
return 2 # High Morale Bonus
elif morale <= 25:
return -2 # Low Morale Penalty
return 0

atk_morale_mod = get_morale_mod(atk_morale_percent)
def_morale_mod = get_morale_mod(def_morale_percent)

# --- 2. Calculate Combat Rolls ---

# Base roll is a d10 (1 to 10)
atk_d10 = random.randint(1, 10)
def_d10 = random.randint(1, 10)

# Calculate final modified rolls
atk_roll = atk_d10 + atk_morale_mod + environment_mod
def_roll = def_d10 + def_morale_mod

# --- 3. Calculate Base Damage ---

# Base Damage is ATK - DEF, with a minimum of 1
base_damage = max(1, atk_atk_stat - def_def_stat)

# --- 4. Determine Final Damage Multiplier (M) and Damage ---

roll_difference = atk_roll - def_roll
final_damage = 0
multiplier = 0.0

if roll_difference > 0:
# Attacker wins the roll: Damage is multiplied by the margin of victory
# Multiplier formula: 1.0 + (difference * 0.2)
# e.g., Diff of 5 means 1.0 + 1.0 = 2.0x Damage
multiplier = 1.0 + (roll_difference * 0.2)
final_damage = int(base_damage * multiplier)
outcome = f"{atk_army_name} won the engagement roll! ({roll_difference} higher)"

else:
# Defender wins or ties the roll: Damage is significantly reduced
multiplier = 0.25 # Only 25% of Base Damage gets through
final_damage = int(base_damage * multiplier)
outcome = f"{def_army_name} held the line or won the engagement roll!"

# --- 5. Return Results ---
return {
"attacker": atk_army_name,
"defender": def_army_name,
"base_damage": base_damage,
"atk_final_roll": atk_roll,
"def_final_roll": def_roll,
"roll_difference": roll_difference,
"damage_multiplier": multiplier,
"final_damage": final_damage,
"outcome": outcome
}

# --- EXAMPLE USAGE ---

# Define Army Stats
attacker_stats = {
"name": "Sea Raiders",
"atk": 2,
"def": 2,
"morale": 15 # Low Morale (-2 mod)
}

defender_stats = {
"name": "Italvian Marines",
"atk": 3,
"def": 3,
"morale": 100 # High Morale (+2 mod)
}

# Run the Combat Calculation
combat_result = calculate_combat_damage(
atk_army_name=attacker_stats["name"],
atk_atk_stat=attacker_stats["atk"],
atk_def_stat=attacker_stats["def"],
atk_morale_percent=attacker_stats["morale"],
def_army_name=defender_stats["name"],
def_atk_stat=defender_stats["atk"], # Included for completeness
def_def_stat=defender_stats["def"],
def_morale_percent=defender_stats["morale"],
environment_mod=1 # Attacker gets a +1 bonus from terrain
)

# Print Results
print("--- Combat Round Result ---")
print(f"Attacker: {combat_result['attacker']} | Defender: {combat_result['defender']}")
print(f"Base Damage (ATK {attacker_stats['atk']} - DEF {defender_stats['def']}): {combat_result['base_damage']}")
print("-" * 30)
print(f"Attacker Roll (d10 + Mods): {combat_result['atk_final_roll']}")
print(f"Defender Roll (d10 + Mods): {combat_result['def_final_roll']}")
print(f"Roll Difference (A - D): {combat_result['roll_difference']}")
print("-" * 30)
print(f"Outcome: {combat_result['outcome']}")
print(f"Damage Multiplier: {combat_result['damage_multiplier']:.2f}x")
print(f"**FINAL DAMAGE DEALT:** {combat_result['final_damage']} to {combat_result['defender']}")

IreallylikeRPGs

RawReport