Skip to content

Commit

Permalink
Merge pull request #155 from vegastrike/task_armor
Browse files Browse the repository at this point in the history
Hull, armor and shield components
  • Loading branch information
royfalk authored Feb 18, 2025
2 parents aff5046 + 6445734 commit 5c45bb8
Show file tree
Hide file tree
Showing 9 changed files with 1,200 additions and 1,867 deletions.
34 changes: 34 additions & 0 deletions master_component_list.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
[
{
"file": "hull",
"categoryname": "upgrades/integral",
"price": "12000",
"mass": "0",
"volume": "0",
"description": "@cargo/hull_patches.image@The ship's hull."
},
{
"file": "afterburner",
"categoryname": "upgrades/integral",
"price": "2000",
"mass": "0",
"volume": "0",
"description": "@upgrades/afterburner_generic.image@Engine overdrive. Increases thrust at the expense of decreased fuel efficiency."
},
{
"file": "drive",
"categoryname": "upgrades/integral",
"price": "6000",
"mass": "0",
"volume": "0",
"description": "@upgrades/afterburner_generic.image@The ship's engine."
},
{
"file": "ftl_drive",
"categoryname": "upgrades/integral",
"price": "4500",
"mass": "0",
"volume": "0",
"description": "@upgrades/jump_drive.image@The ship's faster than light engine."
},


{
"file": "Areus_Milspec_Package",
"categoryname": "upgrades/Packages/Milspec",
Expand Down
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
96 changes: 84 additions & 12 deletions python/base_computer/upgrade_view.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import json

import json
import locale

locale.setlocale(locale.LC_ALL, '')

def format_number(number) -> str:
# large numbers - int with commas
if number > 1000:
int_number = '{:n}'.format(int(number))
return str(int_number)

# numbers that should be rounded


return str(number)

def add_exceptions(unit, key):
# Show Stats by default
Expand Down Expand Up @@ -113,7 +126,30 @@ def process_weapon(upgrade, unit, vsdm):
if 'Energy.rate' in upgrade:
unit['Energy.continuous_rate'] = round(upgrade['Energy.rate'] * shot_cycle_mul * vsdm,2)

def process_resource(key, resource_text):
exclude = ['description']
if key in exclude:
return resource_text

print(f"{key} {resource_text}")
parts = resource_text.split('/')

damaged_index = 0
original_index = 0

if len(parts) == 2:
damaged_index = 0
original_index = 1
elif len(parts) == 3:
damaged_index = 1
original_index = 2
else:
return resource_text

damaged = float(parts[damaged_index])
original = float(parts[original_index])

return f"{format_number(damaged)} (orig: {format_number(original)})"

# We process a line to find the tag <key> or <key=value>
# <key> we convert to unit[key] and replace the tag with it.
Expand Down Expand Up @@ -141,17 +177,18 @@ def process_line(line, unit):
eq_index = line.find('=')
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:]
value = process_resource(key, str(unit[key]))
line = line[:start_index] + str(value) + 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 All @@ -161,7 +198,14 @@ def process_line(line, unit):
return ''


def get_upgrade_info(key):
def get_upgrade_info(unit_stats):
key = unit_stats['upgrade_key']

# Remove ship name - use upgrade name
if 'Name' in unit_stats:
del unit_stats['Name']


vsdm = 5.0
with open('config.json', 'r') as file:
data = json.load(file)
Expand All @@ -185,13 +229,30 @@ def get_upgrade_info(key):
unit.update(upgrade)
break

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

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

# Process ammo and weapons
if 'Mounts' in unit:
mounts = unit['Mounts'][1:-1]
mount_parts = mounts.split(';')
key = mount_parts[0]
unit['ammo_quantity'] = mount_parts[1]

with open('weapons.json', 'r') as file:
data = json.load(file)

Expand All @@ -203,7 +264,17 @@ def get_upgrade_info(key):

add_exceptions(unit, key)
process_shady(unit,key)


# Overwrite values in original upgrade with actual in ship (if relevant)
for key in unit:
if key in unit_stats:
unit[key] = unit_stats[key]
print(f"{key} {unit_stats[key]}")

# Radar range in km not meters
if 'Radar_Range' in unit:
unit['Radar_Range'] = format_number(int(unit['Radar_Range'])/ 1000)

text = ''

with open('python/base_computer/upgrade_view.schema', 'r') as file:
Expand All @@ -214,6 +285,9 @@ def get_upgrade_info(key):


if __name__ == "__main__":
unit = {'Afterburner_Accel': '17000.00/17000.00/17000.00', 'Afterburner_Speed_Governor': '120.00/120.00/125.00', 'Bottom_Accel': '4000.00/4000.00/4000.00', 'Can_Cloak': '0', 'Can_Lock': '1', 'Cargo': '{armor02;upgrades/Armor;200.000000;1;20.000000;0.000000;1.000000;1.000000;;false;true}{capacitor02;upgrades/Capacitors/Standard;200.000000;1;4.000000;4.000000;1.000000;1.000000;;false;true}{reactor02;upgrades/Reactors/Standard;200.000000;1;2.000000;3.500000;1.000000;1.000000;;false;true}{add_spec_capacitor01;upgrades/SPEC_Capacitors;200.000000;1;5.000000;4.000000;1.000000;1.000000;;false;true}{skyscope1;upgrades/Sensors/Common;200.000000;1;0.010000;1.000000;1.000000;1.000000;;false;true}{quadshield02;upgrades/Shield_Systems/Standard_Quad_Shields;200.000000;1;2.000000;8.000000;1.000000;1.000000;;false;true}', 'Cargo_Import': '', 'Cloak_Energy': '0.000000', 'Cloak_Glass': '0', 'Cloak_Min': '0.000000', 'Cloak_Rate': '0.000000', 'Comm_Functionality': '1', 'Default_Speed_Governor': '120.00/120.00/125.00', 'ECM_Rating': '0', 'Equipment_Space': '0', 'FireControl_Functionality': '1', 'Forward_Accel': '17000.00/17000.00/17000.00', 'Fuel_Capacity': '25.00/25.00/25.00', 'Heat_Sink_Rating': '0', 'Hidden_Hold_Volume': '0', 'Hold_Volume': '2000', '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;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;1;', 'Hull': '500.00/500.00/500.00', 'ITTS': '1', 'Jump_Drive_Delay': '1.000000', 'Jump_Drive_Present': '0', 'Key': 'Llama.begin', 'Left_Accel': '4000.00/4000.00/4000.00', 'Lifesupport_Functionality': '1', 'Lock_Cone': '25', 'Maneuver_Pitch': '50000.00/50000.00/50000.00', 'Maneuver_Roll': '50000.00/50000.00/50000.00', 'Maneuver_Yaw': '50000.00/50000.00/50000.00', 'Mass': '250', 'Max_Comm_Functionality': '1', 'Max_Cone': '180', 'Max_FireControl_Functionality': '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;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;1;', 'Max_Lifesupport_Functionality': '1', 'Max_SPECDrive_Functionality': '1', 'Mounts': '{Laser;-1;15;LIGHT;7.084000;-0.476000;23.855999;0.000000;0.000000;0.000000;0.000000;1.000000;0.000000;1.000000;0.000000;1.000000;1.000000}{Laser;-1;15;LIGHT;-6.748000;-0.476000;23.855999;0.000000;0.000000;0.000000;0.000000;1.000000;0.000000;1.000000;0.000000;1.000000;1.000000}{Laser;-1;3;LIGHT;2.660000;1.232000;7.532000;0.000000;0.000000;0.000000;0.000000;1.000000;0.000000;1.000000;0.000000;1.000000;1.000000}{Laser;-1;3;LIGHT;-2.352000;1.232000;7.532000;0.000000;0.000000;0.000000;0.000000;1.000000;0.000000;1.000000;0.000000;1.000000;1.000000}{Dumbfire;48;48;LIGHT-MISSILE MEDIUM-MISSILE SPECIAL-MISSILE;0.000000;0.000000;0.000000;0.000000;0.000000;0.000000;0.000000;1.000000;0.000000;1.000000;0.000000;1.000000;1.000000}{;-1;48;LIGHT-MISSILE MEDIUM-MISSILE SPECIAL-MISSILE;0.000000;0.000000;0.000000;0.000000;0.000000;0.000000;0.000000;1.000000;0.000000;1.000000;0.000000;1.000000;1.000000}', 'Name': 'Llama', 'Outsystem_Jump_Cost': '200.000000', 'Pitch_Governor_Down': '50.00/50.00/50.00', 'Pitch_Governor_Up': '50.00/50.00/50.00', 'Primary_Capacitor': '0.33/0.33/0.33', 'Radar_Color': '0', 'Radar_Range': '3e+08', 'Reactor_Recharge': '44.000000', 'Repair_Droid': '0', 'Retro_Accel': '15000.00/15000.00/15000.00', 'Right_Accel': '4000.00/4000.00/4000.00', 'Roll_Governor_Left': '55.00/55.00/55.00', 'Roll_Governor_Right': '55.00/55.00/55.00', 'SPECDrive_Functionality': '1', 'Shield_Efficiency': '1', 'Shield_Leak': '0', 'Shield_Recharge': '8.00/8.00/8.00', 'Slide_End': '0', 'Slide_Start': '0', 'Spec_Interdiction': '0', 'Sub_Units': '', 'Textual_Description': "With Lauktk's death, ownership of this vessel has passed on to you.", 'Top_Accel': '4000.00/4000.00/4000.00', 'Tracking_Cone': '3.99998', 'Tractorability': 'p', 'Unit_Scale': '', 'Upgrade_Storage_Volume': '360', 'Upgrades': '', 'Warp_Capacitor': '0.67/0.67/0.67', 'Warp_Max_Multiplier': '1', 'Warp_Min_Multiplier': '1', 'Warp_Usage_Cost': '120.000000', 'Wormhole': '0', 'Yaw_Governor_Left': '45.00/45.00/45.00', 'Yaw_Governor_Right': '45.00/45.00/45.00', 'armor_back': '190.00/190.00/200.00', 'armor_front': '192.00/192.00/200.00', 'armor_left': '195.00/195.00/200.00', 'armor_right': '180.00/180.00/200.00', 'shield_back': '142.00/142.00/150.00', 'shield_facets': '4', 'shield_front': '138.00/138.00/150.00', 'shield_left': '145.00/145.00/150.00', 'shield_right': '150.00/150.00/150.00', 'upgrade_key': 'add_spec_capacitor01__upgrades'}
unit['upgrade_key'] == 'skyscope1'
t = get_upgrade_info(unit)
#t = get_upgrade_info('Photon_MK_III_ammo__upgrades')
#t = get_upgrade_info('Photon_MK_III__upgrades')
#t = get_upgrade_info('armor01__upgrades')
Expand All @@ -222,7 +296,7 @@ def get_upgrade_info(key):
#t = get_upgrade_info('cloaking_device__upgrades')
#t = get_upgrade_info('jump_drive__upgrades')
#t = get_upgrade_info('mult_overdrive01__upgrades')
t = get_upgrade_info('passenger_quarters_01__upgrades')
#t = get_upgrade_info(['upgrade_key': 'passenger_quarters_01__upgrades'])
#t = get_upgrade_info('reactor09__upgrades')
#t = get_upgrade_info('add_spec_capacitor01__upgrades')
#t = get_upgrade_info('hawkeye2__upgrades')
Expand All @@ -239,7 +313,5 @@ def get_upgrade_info(key):
#t = get_upgrade_info('mult_shady_moreupgrade__upgrades')
#t = get_upgrade_info('mult_shady_morethrust__upgrades')



print(t)

26 changes: 11 additions & 15 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 @@ -69,18 +65,18 @@ Activated energy usage: #-c<Cloak_Energy> MJ/s
// Sensor
// TODO: Check against code
#c.75:.9:1#Tracking range: #-c<Radar_Range> km
#c.75:.9:1#Tracking cone: #-c<Tracking_Cone>
#c.75:.9:1#Assisted targeting cone: #-c<Max_Cone> radians
#c.75:.9:1#Missile locking cone: #-c<Lock_Cone> radians
#c.75:.9:1#Tracking cone: #-c<Tracking_Cone> degrees
#c.75:.9:1#Assisted targeting cone: #-c<Max_Cone> degrees
#c.75:.9:1#Missile locking cone: #-c<Lock_Cone> degrees
#c.75:.9:1#ITTS (Intelligent Target Tracking System) support: #-c<ITTS>
#c.75:.9:1#AFHH (Advanced Flag & Hostility Heuristics) support: #-c<Radar_Color>

// 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
Loading

0 comments on commit 5c45bb8

Please sign in to comment.