Skip to content

Commit

Permalink
More H1 scenario export work
Browse files Browse the repository at this point in the history
  • Loading branch information
General-101 committed Dec 5, 2024
1 parent e491c32 commit e0a98d9
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 41 deletions.
34 changes: 24 additions & 10 deletions io_scene_halo/file_tag/build_scene/generate_h1_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def set_item_data(ob, element_flags):
def set_device_data(ob, element_flags):
device_flags = DeviceFlags(element_flags)

ob.tag_view.initially_open = DeviceFlags.initially_open_1_0 in device_flags
ob.tag_view.initially_off = DeviceFlags.initially_off_0_0 in device_flags
ob.tag_view.initially_open = DeviceFlags.initially_open in device_flags
ob.tag_view.initially_off = DeviceFlags.initially_off in device_flags
ob.tag_view.can_change_only_once = DeviceFlags.can_change_only_once in device_flags
ob.tag_view.position_reversed = DeviceFlags.position_reversed in device_flags
ob.tag_view.not_usable_from_any_side = DeviceFlags.not_usable_from_any_side in device_flags
Expand All @@ -159,7 +159,7 @@ def set_machine_data(ob, element_flags):
def set_control_data(ob, element_flags):
control_flags = ControlFlags(element_flags)

ob.tag_view.usuable_from_both_sides = ControlFlags.usable_from_both_sides in control_flags
ob.tag_view.usable_from_both_sides = ControlFlags.usable_from_both_sides in control_flags

def get_data_type(collection_name, root, tag_path, element, object_name_tag_block):
if collection_name == "BSPs":
Expand Down Expand Up @@ -219,7 +219,7 @@ def get_data_type(collection_name, root, tag_path, element, object_name_tag_bloc
root.tag_view.power_group = element.power_group_index
root.tag_view.position_group = element.position_group_index
set_device_data(root, element.flags)
root.tag_view.color = element.intensity
root.tag_view.color = element.color_RGBA[0:3]
root.tag_view.intensity = element.intensity
root.tag_view.falloff_angle = element.falloff_angle
root.tag_view.cutoff_angle = element.cutoff_angle
Expand All @@ -230,6 +230,12 @@ def get_data_type(collection_name, root, tag_path, element, object_name_tag_bloc

elif collection_name == "Player Starting Locations":
root.tag_view.data_type_enum = str(DataTypesEnum.player_starting_locations.value)
root.tag_view.team_index = element.team_index
root.tag_view.bsp_index = element.bsp_index
root.tag_view.type_0 = str(element.type_0)
root.tag_view.type_1 = str(element.type_1)
root.tag_view.type_2 = str(element.type_2)
root.tag_view.type_3 = str(element.type_3)

elif collection_name == "Netgame Flags":
root.tag_view.data_type_enum = str(DataTypesEnum.netgame_flags.value)
Expand Down Expand Up @@ -308,12 +314,18 @@ def generate_object_elements(level_root, collection_name, object_name_tag_block,
objects_list.append(ob)

for element_idx, element in enumerate(tag_block):
pallete_item = palette[element.type_index]
tag_name = os.path.basename(pallete_item.name)
tag_path = ""
ob = None
if element.type_index >= 0:
pallete_item = palette[element.type_index]
ob = objects_list[element.type_index]
tag_path = pallete_item.name

name = "%s_%s" % (tag_name, element_idx)
tag_name = "NONE"
if not global_functions.string_empty_check(tag_path):
tag_name = os.path.basename(tag_path)

ob = objects_list[element.type_index]
name = "%s_%s" % (tag_name, element_idx)
if not ob == None:
root = bpy.data.objects.new(name, ob.data)
asset_collection.objects.link(root)
Expand All @@ -326,7 +338,7 @@ def generate_object_elements(level_root, collection_name, object_name_tag_block,
root.parent = level_root
root.location = element.position * 100

get_data_type(collection_name, root, pallete_item.name, element, object_name_tag_block)
get_data_type(collection_name, root, tag_path, element, object_name_tag_block)

rotation = Euler((radians(0.0), radians(0.0), radians(0.0)), 'XYZ')
roll = Euler((radians(element.rotation[2]), radians(0.0), radians(0.0)), 'XYZ')
Expand Down Expand Up @@ -375,7 +387,7 @@ def generate_netgame_equipment_elements(level_root, tag_block, context, game_ver
ob.empty_display_type = 'ARROWS'
asset_collection.objects.link(ob)

get_data_type("Netgame Equipment", ob, element.item_collection.name, element)
get_data_type("Netgame Equipment", ob, element.item_collection.name, element, None)

ob.parent = level_root
ob.location = element.position * 100
Expand All @@ -396,6 +408,8 @@ def generate_empties(context, level_root, collection_name, tag_block):
ob.location = element.position * 100
ob.rotation_euler = (radians(0.0), radians(0.0), radians(element.facing))

get_data_type(collection_name, ob, "", element, None)

asset_collection.objects.link(ob)

def generate_camera_flags(context, level_root, collection_name, tag_block):
Expand Down
4 changes: 2 additions & 2 deletions io_scene_halo/file_tag/h1/file_scenario/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class DeviceGroupFlags(Flag):
can_change_only_once = auto()

class DeviceFlags(Flag):
initially_open_1_0 = auto()
initially_off_0_0 = auto()
initially_open = auto()
initially_off = auto()
can_change_only_once = auto()
position_reversed = auto()
not_usable_from_any_side = auto()
Expand Down
81 changes: 57 additions & 24 deletions io_scene_halo/file_tag/h1/file_scenario/process_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import bpy

from math import degrees
from .format import ScenarioAsset, ObjectFlags, UnitFlags, VehicleFlags, ItemFlags
from .format import ScenarioAsset, ObjectFlags, UnitFlags, VehicleFlags, ItemFlags, DeviceFlags, MachineFlags, ControlFlags
from ....global_functions import global_functions, tag_format

def get_palette_index(TAG, SCENARIO, tag_group, tag_path, palette_tag_block):
Expand All @@ -37,7 +37,7 @@ def get_palette_index(TAG, SCENARIO, tag_group, tag_path, palette_tag_block):
palette_index = palette_element_idx
break

if palette_index == -1 and not global_functions.string_empty_check(tag_group):
if palette_index == -1 and not global_functions.string_empty_check(tag_group) and not global_functions.string_empty_check(tag_path):
palette_tag_block.append(TAG.TagRef(tag_group, tag_path, len(tag_path)))
palette_index = len(palette_tag_block) - 1

Expand Down Expand Up @@ -129,6 +129,38 @@ def get_item_flags(ob):

return item_flags

def get_device_flags(ob):
device_flags = 0
if ob.tag_view.initially_open:
device_flags += DeviceFlags.initially_open.value
if ob.tag_view.initially_off:
device_flags += DeviceFlags.initially_off.value
if ob.tag_view.can_change_only_once:
device_flags += DeviceFlags.can_change_only_once.value
if ob.tag_view.position_reversed:
device_flags += DeviceFlags.position_reversed.value
if ob.tag_view.not_usable_from_any_side:
device_flags += DeviceFlags.not_usable_from_any_side.value
return device_flags

def get_machine_flags(ob):
machine_flags = 0
if ob.tag_view.does_not_operate_automatically:
machine_flags += MachineFlags.does_not_operate_automatically.value
if ob.tag_view.one_sided:
machine_flags += MachineFlags.one_sided.value
if ob.tag_view.never_appears_locked:
machine_flags += MachineFlags.never_appears_locked.value
if ob.tag_view.opened_by_melee_attack:
machine_flags += MachineFlags.opened_by_melee_attack.value
return machine_flags

def get_control_flags(ob):
control_flags = 0
if ob.tag_view.usable_from_both_sides:
control_flags += ControlFlags.usable_from_both_sides.value
return control_flags

def generate_comments(TAG, SCENARIO):
comment_collection = bpy.data.collections.get("Comments")
blender_comments = []
Expand Down Expand Up @@ -262,10 +294,10 @@ def generate_machines(TAG, SCENARIO):
rot = ob.rotation_euler
machine.rotation = (get_half_angle(degrees(rot[2])), get_half_angle(degrees(-rot[0])), get_half_angle(degrees(-rot[1])))
machine.appearance_player_index = ob.tag_view.appearance_player_index
machine.power_group_index = 0
machine.position_group_index = 0
machine.flags_0 = 0
machine.flags_1 = 0
machine.power_group_index = ob.tag_view.power_group
machine.position_group_index = ob.tag_view.position_group
machine.flags_0 = get_device_flags(ob)
machine.flags_1 = get_machine_flags(ob)

blender_machines.append(machine)

Expand All @@ -285,11 +317,11 @@ def generate_controls(TAG, SCENARIO):
rot = ob.rotation_euler
control.rotation = (get_half_angle(degrees(rot[2])), get_half_angle(degrees(-rot[0])), get_half_angle(degrees(-rot[1])))
control.appearance_player_index = ob.tag_view.appearance_player_index
control.power_group_index = 0
control.position_group_index = 0
control.flags_0 = 0
control.flags_1 = 0
control.unknown = 0
control.power_group_index = ob.tag_view.power_group
control.position_group_index = ob.tag_view.position_group
control.flags_0 = get_device_flags(ob)
control.flags_1 = get_control_flags(ob)
control.unknown = ob.tag_view.control_value

blender_controls.append(control)

Expand All @@ -309,13 +341,13 @@ def generate_light_fixtures(TAG, SCENARIO):
rot = ob.rotation_euler
light_fixture.rotation = (get_half_angle(degrees(rot[2])), get_half_angle(degrees(-rot[0])), get_half_angle(degrees(-rot[1])))
light_fixture.appearance_player_index = ob.tag_view.appearance_player_index
light_fixture.power_group_index = 0
light_fixture.position_group_index = 0
light_fixture.flags = 0
light_fixture.color_RGBA = (0.0, 0.0, 0.0, 1.0)
light_fixture.intensity = 0
light_fixture.falloff_angle = 0
light_fixture.cutoff_angle = 0
light_fixture.power_group_index = ob.tag_view.power_group
light_fixture.position_group_index = ob.tag_view.position_group
light_fixture.flags = get_device_flags(ob)
light_fixture.color_RGBA = (ob.tag_view.color[0], ob.tag_view.color[1], ob.tag_view.color[2], 1)
light_fixture.intensity = ob.tag_view.intensity
light_fixture.falloff_angle = ob.tag_view.falloff_angle
light_fixture.cutoff_angle = ob.tag_view.cutoff_angle

blender_light_fixtures.append(light_fixture)

Expand Down Expand Up @@ -350,12 +382,12 @@ def generate_player_starting_locations(TAG, SCENARIO):

player_starting_location.position = ob.location / 100
player_starting_location.facing = get_half_angle(degrees(rot[2]))
player_starting_location.team_index = 0
player_starting_location.bsp_index = 0
player_starting_location.type_0 = 0
player_starting_location.type_1 = 0
player_starting_location.type_2 = 0
player_starting_location.type_3 = 0
player_starting_location.team_index = ob.tag_view.team_index
player_starting_location.bsp_index = ob.tag_view.bsp_index
player_starting_location.type_0 = int(ob.tag_view.type_0)
player_starting_location.type_1 = int(ob.tag_view.type_1)
player_starting_location.type_2 = int(ob.tag_view.type_2)
player_starting_location.type_3 = int(ob.tag_view.type_3)

blender_player_starting_locations.append(player_starting_location)

Expand Down Expand Up @@ -538,6 +570,7 @@ def generate_scenario_scene(DONOR_ASSET):
generate_trigger_volumes(TAG, DONOR_ASSET)

DONOR_ASSET.comments_tag_block = TAG.TagBlock(len(DONOR_ASSET.comments))
DONOR_ASSET.object_names_tag_block = TAG.TagBlock(len(DONOR_ASSET.object_names))
DONOR_ASSET.scenery_tag_block = TAG.TagBlock(len(DONOR_ASSET.scenery))
DONOR_ASSET.scenery_palette_tag_block = TAG.TagBlock(len(DONOR_ASSET.scenery_palette))
DONOR_ASSET.bipeds_tag_block = TAG.TagBlock(len(DONOR_ASSET.bipeds))
Expand Down
90 changes: 85 additions & 5 deletions io_scene_halo/global_ui/tag_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ class HALO_PropertiesGroup(PropertyGroup):
default = False,
)

usuable_from_both_sides: BoolProperty(
name ="Usuable From Both Sides",
usable_from_both_sides: BoolProperty(
name ="Usable From Both Sides",
description = "Control ignores forward vector",
default = False,
)
Expand All @@ -366,12 +366,67 @@ class HALO_PropertiesGroup(PropertyGroup):

falloff_angle: FloatProperty(
name="Falloff Angle",
description="I have no idea what this is"
description="I have no idea what this is",
subtype="ANGLE"
)

cutoff_angle: FloatProperty(
name="Cutoff Angle",
description="I have no idea what this is"
description="I have no idea what this is",
subtype="ANGLE"
)

team_index: IntProperty(
name = "Team Index",
description = "Team index",
min = 0
)

bsp_index: IntProperty(
name = "BSP Index",
description = "BSP index",
min = -1
)

type_options = ( ('0', "None", "None"),
('1', "CTF", "CTF"),
('2', "Slayer", "Slayer"),
('3', "Oddball", "Oddball"),
('4', "King Of The Hill", "King Of The Hill"),
('5', "Race", "Race"),
('6', "Terminator", "Terminator"),
('7', "Stub", "Stub"),
('8', "Ignored1", "Ignored1"),
('9', "Ignored2", "Ignored2"),
('10', "Ignored3", "Ignored3"),
('11', "Ignored4", "Ignored4"),
('12', "All Games", "All Games"),
('13', "All Except CTF", "All Except CTF"),
('14', "All Except Race And CTF", "All Except Race And CTF")
)

type_0: EnumProperty(
name="Type 0",
description="Type 0",
items=type_options
)

type_1: EnumProperty(
name="Type 1",
description="Type 1",
items=type_options
)

type_2: EnumProperty(
name="Type 2",
description="Type 2",
items=type_options
)

type_3: EnumProperty(
name="Type 3",
description="Type 3",
items=type_options
)

def render_cluster(layout, tag_view):
Expand Down Expand Up @@ -578,7 +633,7 @@ def render_control(layout, tag_view):
box_flags.label(text="Flags")
col_flags = box_flags.column(align=True)
row_flags = col_flags.row()
row_flags.prop(tag_view, "usuable_from_both_sides")
row_flags.prop(tag_view, "usable_from_both_sides")

box = layout.split()
col = box.column(align=True)
Expand All @@ -602,6 +657,29 @@ def render_light_fixture(layout, tag_view):
row.label(text='Cutoff Angle')
row.prop(tag_view, "cutoff_angle", text='')

def render_player_starting_location(layout, tag_view):
box = layout.split()
col = box.column(align=True)

row = col.row()
row.label(text='Team Index')
row.prop(tag_view, "team_index", text='')
row = col.row()
row.label(text='BSP Index')
row.prop(tag_view, "bsp_index", text='')
row = col.row()
row.label(text='Type 0')
row.prop(tag_view, "type_0", text='')
row = col.row()
row.label(text='Type 1')
row.prop(tag_view, "type_1", text='')
row = col.row()
row.label(text='Type 2')
row.prop(tag_view, "type_2", text='')
row = col.row()
row.label(text='Type 3')
row.prop(tag_view, "type_3", text='')

class Halo_TagView(Panel):
bl_label = "Halo Tag View"
bl_idname = "HALO_PT_TagView"
Expand Down Expand Up @@ -653,5 +731,7 @@ def draw(self, context):
render_object(layout, tag_view)
render_device(layout, tag_view)
render_light_fixture(layout, tag_view)
elif data_type_value == DataTypesEnum.player_starting_locations.value:
render_player_starting_location(layout, tag_view)
elif data_type_value == DataTypesEnum.instances.value:
render_instance(layout, tag_view)

0 comments on commit e0a98d9

Please sign in to comment.