Skip to content

Commit

Permalink
Bounty missions
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers authored Aug 19, 2024
2 parents bafce27 + b3edf1d commit 36fbae5
Show file tree
Hide file tree
Showing 16 changed files with 315 additions and 45 deletions.
8 changes: 8 additions & 0 deletions actors/heroes/bounties/Vex 'Quantum' Cygnus.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="Hero" load_steps=2 format=3 uid="uid://dehs0xqbalevx"]

[ext_resource type="Script" path="res://actors/heroes/hero.gd" id="1_6aguh"]

[resource]
script = ExtResource("1_6aguh")
name = "Vex 'Quantum' Cygnus"
bounty_target = true
8 changes: 8 additions & 0 deletions actors/heroes/bounties/Zora 'Starshiv' Blackburn.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="Hero" load_steps=2 format=3 uid="uid://qlbnowlag2dr"]

[ext_resource type="Script" path="res://actors/heroes/hero.gd" id="1_5sbmg"]

[resource]
script = ExtResource("1_5sbmg")
name = "Zora 'Starshiv' Blackburn"
bounty_target = true
15 changes: 15 additions & 0 deletions actors/heroes/hero.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extends Resource
class_name Hero

## A "hero" is any named NPC.
##
## These are often used as a target or escort in missions.

## The name of the hero.
@export var name: String

## Whether this hero is eligible to be targeted in bounty missions.
@export var bounty_target: bool = false

## Fires when this hero is killed in combat.
signal killed(hero: Hero)
46 changes: 46 additions & 0 deletions actors/heroes/hero_roster.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
extends Node3D
class_name HeroRoster

## Maintains a list of [Hero]s that are alive in the game.

## Current heroes.
##
## NOTE: This array must not be mutated at runtime from outside this class!
@export var heroes: Array[Hero] = []:
set(value):
if value == heroes:
return

self._unsubscribe_from_heroes()
heroes = value.duplicate()
self._subscribe_to_heroes()

func _subscribe_to_heroes() -> void:
for hero in self.heroes:
hero.killed.connect(_on_hero_killed)

func _unsubscribe_from_heroes() -> void:
for hero in self.heroes:
hero.killed.disconnect(_on_hero_killed)

func _on_hero_killed(hero: Hero) -> void:
self.heroes.erase(hero)

## Randomly picks a hero that is eligible to have a bounty, or returns null if none are available.
func pick_random_bounty() -> Hero:
var eligible := self.heroes.filter(func(hero: Hero) -> bool: return hero.bounty_target)
if not eligible:
return null

return eligible.pick_random()

## See [SaveGame].
func save_to_dict() -> Dictionary:
var result := {}
result["heroes"] = SaveGame.serialize_array_of_resources(self.heroes)
return result

## See [SaveGame].
func load_from_dict(dict: Dictionary) -> void:
var heroes_array: Array = dict["heroes"]
self.heroes = SaveGame.deserialize_array_of_resources(heroes_array)
21 changes: 11 additions & 10 deletions actors/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class_name Player
@export var bank_account: BankAccount
@export var calendar: Calendar
@export var mission_controller: MissionController
@export var hero_roster: HeroRoster

@onready var ship := get_parent() as Ship

Expand Down Expand Up @@ -44,10 +45,10 @@ var landing_target: PlanetInstance = null:
set(value):
if landing_target == value:
return

if landing_target:
landing_target.targeted_by_player = false

landing_target = value
self.landing_target_changed.emit(self, landing_target)

Expand Down Expand Up @@ -101,7 +102,7 @@ func _ready() -> void:
if self.ship.hyperdrive:
self._on_hyperdrive_changed()
self.ship.hyperdrive.changed.connect(_on_hyperdrive_changed)

self.mission_controller.calendar = self.calendar
self.mission_controller.cargo_hold = self.ship.cargo_hold
self.mission_controller.bank_account = self.bank_account
Expand Down Expand Up @@ -166,7 +167,7 @@ func _closest_landing_target() -> PlanetInstance:
if distance <= nearest_distance:
nearest_planet_instance = planet_instance
nearest_distance = distance

return nearest_planet_instance

func _unhandled_key_input(event: InputEvent) -> void:
Expand Down Expand Up @@ -196,15 +197,15 @@ func _on_broadcasted_input_event(receiver: Node, event: InputEvent) -> void:
var mouse_button_event := event as InputEventMouseButton
if not mouse_button_event:
return

if mouse_button_event.button_index != MOUSE_BUTTON_LEFT or not mouse_button_event.pressed:
return

var combat_object := receiver as CombatObject
if combat_object:
self.ship.targeting_system.target = combat_object
return

var planet_instance := receiver as PlanetInstance
if planet_instance:
self.landing_target = planet_instance
Expand All @@ -213,7 +214,7 @@ func _on_broadcasted_input_event(receiver: Node, event: InputEvent) -> void:
func _jump_to_hyperspace() -> void:
if not self.ship.hyperdrive_system.jump_destination:
return

if not self.hyperspace_scene_switcher.start_jump():
return

Expand All @@ -227,7 +228,7 @@ func _land() -> void:
self.landing_target = self._closest_landing_target()
if not self.landing_target:
return

# Run the following checks only after a target is selected, to avoid spamming the message log.
if self.landing_target.global_transform.origin.distance_to(self.ship.global_transform.origin) > MAX_LANDING_DISTANCE:
self.message_log.add_message("Too far away to land.")
Expand All @@ -254,7 +255,7 @@ func _land() -> void:
landing.add_sibling(self.ship)
landing.queue_free()
self._depart_from_planet())

self.landed.emit(self, planet)

func _depart_from_planet() -> void:
Expand Down
2 changes: 1 addition & 1 deletion galaxy/map/galaxy_map_window.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ own_world_3d = true
handle_input_locally = false
scaling_3d_scale = 2.0
physics_object_picking = true
size = Vector2i(793, 799)
size = Vector2i(2, 2)
render_target_update_mode = 4

[node name="GalaxyMap3D" parent="PanelContainer/HSplitContainer/LeftContainer/SubViewportContainer/SubViewport" instance=ExtResource("1_rlhp4")]
Expand Down
33 changes: 31 additions & 2 deletions galaxy/star_system/scenes/barnard's_star.tscn
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
[gd_scene load_steps=6 format=3 uid="uid://cghdtnx2qen2u"]
[gd_scene load_steps=13 format=3 uid="uid://cghdtnx2qen2u"]

[ext_resource type="Resource" uid="uid://shiglva7yxl0" path="res://galaxy/star_system/star_systems/barnard's_star.tres" id="2_y4tl8"]
[ext_resource type="PackedScene" uid="uid://d27pdcik2lwf1" path="res://stars/main_sequence/star_class_m.tscn" id="3_cqasn"]
[ext_resource type="Resource" uid="uid://qlbnowlag2dr" path="res://actors/heroes/bounties/Zora 'Starshiv' Blackburn.tres" id="5_lj2ck"]
[ext_resource type="PackedScene" uid="uid://ccdkamqw03rk7" path="res://fx/asteroids/multi_asteroid_field.tscn" id="5_x1i1i"]
[ext_resource type="Script" path="res://mechanics/combat/hull.gd" id="6_084xj"]
[ext_resource type="Script" path="res://mechanics/combat/shield.gd" id="7_tt2dl"]
[ext_resource type="Script" path="res://mechanics/power/battery.gd" id="8_qba8t"]
[ext_resource type="PackedScene" uid="uid://culoat6jnbwc8" path="res://actors/ai/pirate_frigate.tscn" id="9_xdjbl"]
[ext_resource type="PackedScene" uid="uid://fxemun7o6rix" path="res://galaxy/star_system/star_system_instance.tscn" id="star_system_instance"]

[sub_resource type="Resource" id="Resource_nv5hr"]
resource_local_to_scene = true
script = ExtResource("6_084xj")
max_integrity = 100.0
integrity = 100.0

[sub_resource type="Resource" id="Resource_q3lvv"]
resource_local_to_scene = true
script = ExtResource("7_tt2dl")
max_integrity = 100.0
integrity = 100.0
recharge_rate = 10.0
power_efficiency = 1.0
only_recharge_above = 0.2

[sub_resource type="Resource" id="Resource_vl342"]
resource_local_to_scene = true
script = ExtResource("8_qba8t")
max_power = 300.0
power = 300.0

[node name="Barnard\'s Star" instance=ExtResource("star_system_instance")]
star_system = ExtResource("2_y4tl8")

[node name="Star Class M" parent="." index="0" instance=ExtResource("3_cqasn")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.65429, 2.08165e-12, 11.1402)

[node name="PirateFrigate" parent="." index="1" instance=ExtResource("9_xdjbl")]
[node name="Zora" parent="." index="1" instance=ExtResource("9_xdjbl")]
transform = Transform3D(0.866897, -1.28496e-16, 0.498488, 3.48787e-16, 1, -3.48787e-16, -0.498488, 4.76228e-16, 0.866897, -8.39, 2.08165e-12, 1.15)
hero = ExtResource("5_lj2ck")
hull = SubResource("Resource_nv5hr")
shield = SubResource("Resource_q3lvv")
battery = SubResource("Resource_vl342")

[node name="AsteroidField" parent="." index="2" instance=ExtResource("5_x1i1i")]
57 changes: 55 additions & 2 deletions galaxy/star_system/scenes/wolf_359.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
[gd_scene load_steps=5 format=3 uid="uid://d3qpe4ne3bgww"]
[gd_scene load_steps=15 format=3 uid="uid://d3qpe4ne3bgww"]

[ext_resource type="Resource" uid="uid://di0bekcy5g0ya" path="res://galaxy/star_system/star_systems/wolf_359.tres" id="2_byjpf"]
[ext_resource type="PackedScene" uid="uid://d27pdcik2lwf1" path="res://stars/main_sequence/star_class_m.tscn" id="3_wjxxu"]
[ext_resource type="PackedScene" uid="uid://culoat6jnbwc8" path="res://actors/ai/pirate_frigate.tscn" id="4_tean3"]
[ext_resource type="Script" path="res://mechanics/combat/hull.gd" id="5_1fi2w"]
[ext_resource type="Script" path="res://mechanics/combat/shield.gd" id="6_fwcxa"]
[ext_resource type="Script" path="res://mechanics/power/battery.gd" id="7_el5w1"]
[ext_resource type="Resource" uid="uid://dehs0xqbalevx" path="res://actors/heroes/bounties/Vex 'Quantum' Cygnus.tres" id="8_25dnf"]
[ext_resource type="PackedScene" uid="uid://fxemun7o6rix" path="res://galaxy/star_system/star_system_instance.tscn" id="star_system_instance"]

[sub_resource type="Resource" id="Resource_p4pv3"]
resource_local_to_scene = true
script = ExtResource("5_1fi2w")
max_integrity = 100.0
integrity = 100.0

[sub_resource type="Resource" id="Resource_yxo7w"]
resource_local_to_scene = true
script = ExtResource("6_fwcxa")
max_integrity = 100.0
integrity = 100.0
recharge_rate = 10.0
power_efficiency = 1.0
only_recharge_above = 0.2

[sub_resource type="Resource" id="Resource_0pc4o"]
resource_local_to_scene = true
script = ExtResource("7_el5w1")
max_power = 300.0
power = 300.0

[sub_resource type="Resource" id="Resource_sq0sg"]
resource_local_to_scene = true
script = ExtResource("5_1fi2w")
max_integrity = 100.0
integrity = 100.0

[sub_resource type="Resource" id="Resource_accbt"]
resource_local_to_scene = true
script = ExtResource("6_fwcxa")
max_integrity = 100.0
integrity = 100.0
recharge_rate = 10.0
power_efficiency = 1.0
only_recharge_above = 0.2

[sub_resource type="Resource" id="Resource_cq7l1"]
resource_local_to_scene = true
script = ExtResource("7_el5w1")
max_power = 300.0
power = 300.0

[node name="Wolf 359" instance=ExtResource("star_system_instance")]
star_system = ExtResource("2_byjpf")

Expand All @@ -13,6 +59,13 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -7.65186, 2.08165e-12, 2.2427

[node name="PirateFrigate" parent="." index="1" instance=ExtResource("4_tean3")]
transform = Transform3D(-0.287762, -2.33666e-16, -0.957702, 3.48787e-16, 1, -3.48787e-16, 0.957702, -4.34402e-16, -0.287762, -7.88217, 0, -3.99797)
hull = SubResource("Resource_p4pv3")
shield = SubResource("Resource_yxo7w")
battery = SubResource("Resource_0pc4o")

[node name="PirateFrigate2" parent="." index="2" instance=ExtResource("4_tean3")]
[node name="Vex" parent="." index="2" instance=ExtResource("4_tean3")]
transform = Transform3D(-0.69814, 4.9322e-16, 0.715961, 3.48787e-16, 1, -3.48787e-16, -0.715961, 6.21573e-18, -0.69814, 5.40376, 0, 0.771966)
hero = ExtResource("8_25dnf")
hull = SubResource("Resource_sq0sg")
shield = SubResource("Resource_accbt")
battery = SubResource("Resource_cq7l1")
Loading

0 comments on commit 36fbae5

Please sign in to comment.