Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hull, armor and shield components #155

Merged
merged 13 commits into from
Feb 18, 2025
1 change: 0 additions & 1 deletion modules/quests/quest_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def launchNewDrone (self):
#VS.launch(name,type,faction,unittype,ai,nr,nrwaves,pos,squadlogo):
self.drone = VS.launch("Oswald","Robin.tutorial","klkk_citizen","unit","default",1,1,vec,'')
# upgrade drone
self.drone.upgrade("quadshield15",0,0,1,0)
self.drone.upgrade("armor06",0,0,1,0)
# when launching give the player some text and ask him to decide if he wants to participate
VS.IOmessage (0,"Oswald","Privateer",self.msgColor+"Hello traveler.")
Expand Down
54 changes: 23 additions & 31 deletions python/base_computer/ship_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ def get_iff(iff):
if iff=='2': return 'object recognition'
return iff

def get_ypr(ship_stats, prefix, divider_maneuver, left = '_Left', right = '_Right'):
data = get_dbl(ship_stats,prefix, divider_maneuver)
if data > 0:
return data
data = get_dbl(ship_stats,prefix+left, divider_maneuver)
data += get_dbl(ship_stats,prefix+right, divider_maneuver)
return data/2

# General
def get_general(ship_stats):
text = f"{green}[GENERAL INFORMATION]{newline}"
Expand Down Expand Up @@ -181,18 +189,10 @@ def get_governor(ship_stats):
speed = get_int(ship_stats, 'Default_Speed_Governor')
afterburner = get_int(ship_stats, 'Afterburner_Speed_Governor')

yaw = get_dbl(ship_stats, 'Yaw_Governor',divider)
#yaw_right = get_dbl(ship_stats, 'Yaw_Governor_Right')
#yaw_left = get_dbl(ship_stats, 'Yaw_Governor_Left')

pitch = get_dbl(ship_stats, 'Pitch_Governor',divider)
#pitch_down = get_dbl(ship_stats, 'Pitch_Governor_Up')
#pitch_up = get_dbl(ship_stats, 'Pitch_Governor_Down')

roll = get_dbl(ship_stats, 'Roll_Governor',divider)
#roll_right = get_dbl(ship_stats, 'Roll_Governor_Right')
#roll_left = get_dbl(ship_stats, 'Roll_Governor_Left')

yaw = get_ypr(ship_stats, 'Yaw_Governor',divider)
pitch = get_ypr(ship_stats, 'Pitch_Governor',divider, '_Up', '_Down')
roll = get_ypr(ship_stats, 'Roll_Governor',divider)

text = f"{green}[GOVERNOR SETTINGS]{newline}#-c{newline}"
text += f"{light_grey}Max combat speed: #-c{speed} m/s{newline}"
text += f"{light_grey}Max overdrive combat speed: #-c{afterburner} m/s{newline}"
Expand Down Expand Up @@ -255,33 +255,25 @@ def get_energy_spec_and_jump(ship_stats):

def get_durability(ship_stats):
armor = [
('Fore-starboard-high','Armor_Front_Top_Right'),
('Aft-starboard-high','Armor_Back_Top_Right'),
('Fore-port-high','Armor_Front_Top_Left'),
('Aft-port-high','Armor_Back_Top_Left'),
('Fore-starboard-low','Armor_Front_Bottom_Right'),
('Aft-starboard-low','Armor_Back_Bottom_Right'),
('Fore-port-low','Armor_Front_Bottom_Left'),
('Aft-port-low','Armor_Back_Bottom_Left'),
('Front armor','armor_front'),
('Rear armor','armor_back'),
('Port armor','armor_left'),
('Starboard armor','armor_right')
]

shield4 = [
('Port','Shield_Front_Bottom_Left'),('Starboard','Shield_Front_Bottom_Right'),('Fore','Shield_Front_Top_Right'),('Aft','Shield_Back_Top_Left'),
('Front shield','shield_front'),
('Rear shield','shield_back'),
('Port shield','shield_left'),
('Starboard shield','shield_right')
]

shield2 = [
('Fore','Shield_Front_Top_Right'),('Aft','Shield_Back_Top_Left'),
('Front shield','shield_front'),
('Rear shield','shield_back')
]

# This is a kludge. Should go away when we refactor units.json and unit_csv.cpp
shield_stat = {}
num_emitters = 0
for pair in shield4:
if not pair[1] in ship_stats:
continue
value = get_dbl(ship_stats,pair[1])
if value > 0:
num_emitters += 1
num_emitters = lnum(ship_stats, 'shield_facets')


hull = lnum(ship_stats,'Hull')
Expand Down
23 changes: 20 additions & 3 deletions python/base_computer/upgrade_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,15 @@ def process_line(line, unit):
if eq_index == -1:
key = line[start_index+1:end_index]
if key in unit:
# Is there another tag?
line = line[:start_index] + str(unit[key]) + line[end_index+1:]

# Is there another tag?
if line.find('<') != -1:
return process_line(line, unit)

return line + "#n#" + '\n'
else:
return ''
return
return ''
else:
pair = line[start_index+1:end_index]
key, value = pair.split('=')
Expand Down Expand Up @@ -185,6 +184,24 @@ def get_upgrade_info(key):
unit.update(upgrade)
break

# Process shield and armor
if 'shield_strength' in unit:
shield_strength = unit['shield_strength']
unit['shield_front'] = shield_strength
unit['shield_back'] = shield_strength
unit['shield_left'] = shield_strength
unit['shield_right'] = shield_strength
del unit['shield_strength']

if 'armor_strength' in unit:
armor_strength = unit['armor_strength']
unit['armor_front'] = armor_strength
unit['armor_back'] = armor_strength
unit['armor_left'] = armor_strength
unit['armor_right'] = armor_strength
del unit['armor_strength']


# Process ammo and weapons
if 'Mounts' in unit:
mounts = unit['Mounts'][1:-1]
Expand Down
20 changes: 8 additions & 12 deletions python/base_computer/upgrade_view.schema
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@
<Upgrade_Type=Armor>#c.75:.9:1#Replaces existing armor, if any.
<Upgrade_Type=Armor>Armor damage resistance:#-c

#c.675:.925:.825# - Fore-starboard-high: #-c<Armor_Front_Top_Right> MJ
#c.675:.925:.825# - Aft-starboard-high: #-c<Armor_Back_Top_Right> MJ
#c.675:.925:.825# - Fore-port-high: #-c<Armor_Front_Top_Left> MJ
#c.675:.925:.825# - Aft-port-high: #-c<Armor_Back_Top_Left> MJ
#c.675:.925:.825# - Fore-starboard-low: #-c<Armor_Front_Bottom_Right> MJ
#c.675:.925:.825# - Aft-starboard-low: #-c<Armor_Back_Bottom_Right> MJ
#c.675:.925:.825# - Fore-port-low: #-c<Armor_Front_Bottom_Left> MJ
#c.675:.925:.825# - Aft-port-low: #-c<Armor_Back_Bottom_Left> MJ
#c.675:.925:.825# - Front: #-c<armor_front> MJ
#c.675:.925:.825# - Back: #-c<armor_back> MJ
#c.675:.925:.825# - Left: #-c<armor_left> MJ
#c.675:.925:.825# - Right: #-c<armor_right> MJ

// Autotracking
<Upgrade_Type=Autotrack>#c.75:.9:1#Installs auto-tracking capability on the selected mount.
Expand Down Expand Up @@ -77,10 +73,10 @@ Activated energy usage: #-c<Cloak_Energy> MJ/s

// Shield
<Upgrade_Type=Shield>#c.75:.9:1#Installs shield with following protection ratings:#-c
#c.675:.925:.825# - port: #-c<Shield_Front_Bottom_Left> MJ
#c.675:.925:.825# - starboard: #-c<Shield_Front_Bottom_Right> MJ
#c.675:.925:.825# - fore: #-c<Shield_Front_Top_Right> MJ
#c.675:.925:.825# - aft: #-c<Shield_Back_Top_Left> MJ
#c.675:.925:.825# - Front: #-c<shield_front> MJ
#c.675:.925:.825# - Back: #-c<shield_back> MJ
#c.675:.925:.825# - Left: #-c<shield_left> MJ
#c.675:.925:.825# - Right: #-c<shield_right> MJ
#c.75:.9:1#Shield recharge rate of: #-c<Shield_Recharge> MJ/s

// Tractor Capability
Expand Down
110 changes: 87 additions & 23 deletions units/minimize_parts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import sys
import os

KEY = 'Key'
NAME = 'Name'
Expand All @@ -8,24 +9,24 @@
delete_array = ['box', 'box.blank', 'box.template']
delete_keys = ['Moment_Of_Inertia']

minimize_array = [('armor', ['Armor_Front_Top_Right',
'Armor_Front_Top_Left',
'Armor_Front_Bottom_Right',
'Armor_Front_Bottom_Left',
'Armor_Back_Top_Right',
'Armor_Back_Top_Left',
'Armor_Back_Bottom_Right',
'Armor_Back_Bottom_Left']),
('shield_strength',['Shield_Front_Top_Right',
'Shield_Back_Top_Left',
'Shield_Front_Bottom_Right',
'Shield_Front_Bottom_Left']),
minimize_array = [('armor', ['armor_front', 'armor_rear','armor_left', 'armor_right']),
('shield_strength',['shield_front', 'shield_back','shield_left', 'shield_right']),
('accel', ['Left_Accel',
'Right_Accel',
'Top_Accel',
'Bottom_Accel'])
]

force_array = [(['armor_front', 'armor_back','armor_left', 'armor_right'],
['Armor_Front_Top_Right', 'Armor_Front_Top_Left',
'Armor_Front_Bottom_Right', 'Armor_Front_Bottom_Left',
'Armor_Back_Top_Right', 'Armor_Back_Top_Left',
'Armor_Back_Bottom_Right',
'Armor_Back_Bottom_Left'], 'armor'),
(['shield_front', 'shield_back','shield_left', 'shield_right'],
['Shield_Front_Top_Right', 'Shield_Back_Top_Left',
'Shield_Front_Bottom_Right', 'Shield_Front_Bottom_Left'], 'shield')]

ship_defaults = {"Object_Type": "Vessel",
"Hud_Functionality": "1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1",
"Max_Hud_Functionality": "1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1",
Expand Down Expand Up @@ -62,18 +63,65 @@ def delete_ship_by_key(key, units):
if unit[KEY] == key:
units.remove(unit)
return


def add_facets(unit):
# Convert old armor/shield to new format
def force_minimize_shield_and_armor(unit, new_keys, old_keys, min_key):
sum_value = 0
facets = 0
for old_key in old_keys:
if old_key not in unit:
continue

temp_value = int(round(float(unit[old_key])))
facets += 1 if temp_value > 0 else 0
sum_value += temp_value

for key in minimize_array[1][1]:
if key in unit and float(unit[key]) > 0:
facets += 1

if facets > 0:
unit['shield_facets'] = str(facets)


if facets == 2:
unit[new_keys[0]] = unit[new_keys[1]] = str(sum_value / 2)
elif facets == 4:
unit[new_keys[0]] = unit[new_keys[1]] = str(sum_value / 4)
unit[new_keys[2]] = unit[new_keys[3]] = str(sum_value / 4)
elif facets == 8:
unit[new_keys[0]] = unit[new_keys[1]] = str(sum_value / 4)
unit[new_keys[2]] = unit[new_keys[3]] = str(sum_value / 4)
elif facets == 0:
# Nothing to do
pass
else:
print(unit)
print('\n')
print(f"Illegal number of facets {facets} in force_minimize_shield_and_armor for {unit['Key']}")
sys.exit(1)

if facets == 8:
facets = 4

# Try and minimize to one value
if facets == 2:
if unit[new_keys[0]] == unit[new_keys[1]]:
# Minimize new keys. We have a single value
unit[min_key] = unit[new_keys[0]]
del(unit[new_keys[0]])
del(unit[new_keys[1]])

elif facets == 4:
if unit[new_keys[0]] == unit[new_keys[1]] and unit[new_keys[0]] == unit[new_keys[2]] and unit[new_keys[0]] == unit[new_keys[3]]:
unit[min_key] = unit[new_keys[0]]
# Minimize new keys. We have a single value
for new_key in new_keys:
del(unit[new_key])

# We got to the end, we can minimize
for old_key in old_keys:
if old_key in unit:
del(unit[old_key])

# Add shield facets
if 'shield' in unit or 'shield_front' in unit:
unit['shield_facets'] = str(facets)


def minimize_some_values(unit, new_key, old_keys):
old_value = None
Expand All @@ -86,6 +134,7 @@ def minimize_some_values(unit, new_key, old_keys):

if temp != old_value and old_value != None:
# values don't match, exit
print(f"{unit['Key']} has inconsistent {old_key}")
return

old_value = temp
Expand All @@ -103,6 +152,9 @@ def minimize_some_values(unit, new_key, old_keys):
def minimize(units, upgrades, base_template):
for unit in units:
key = unit['Key']

if key == 'generic_cargo':
print('cargo')

# Delete keys
for key_to_delete in delete_keys:
Expand All @@ -121,9 +173,13 @@ def minimize(units, upgrades, base_template):
if k in unit and v == unit[k]:
del unit[k]

# Add shield_facets
add_facets(unit)

# Force minimize shields and armor
for force_minimize in force_array:
new_keys = force_minimize[0]
old_keys = force_minimize[1]
min_key = force_minimize[2]
force_minimize_shield_and_armor(unit, new_keys, old_keys, min_key)

for minimize_values in minimize_array:
new_key = minimize_values[0]
old_keys = minimize_values[1]
Expand Down Expand Up @@ -176,6 +232,8 @@ def is_ship(unit):

return True

# Go over units and extract all units with __upgrades into a separate list
# Remove some keys in the first line as well
def generate_upgrades(units):
exclude_list = ['Key', 'Name', 'Object_Type', 'Textual_Description', 'Moment_Of_Inertia', 'Mounts']
upgrades = {}
Expand Down Expand Up @@ -324,6 +382,12 @@ def generate_cargo(unit, upgrades):


if __name__ == '__main__':
# If run from Asset-Production, change to units folder
if os.path.isdir('units'):
path = os.getcwd()
os.chdir(path + '/units')


units = []
base_template = {}

Expand Down
Loading
Loading