From 0b8addb1dc205e54ee586c77c27a9ec05cdc8b6b Mon Sep 17 00:00:00 2001 From: Ategon Date: Sun, 15 Sep 2024 03:29:19 -0400 Subject: [PATCH] Add close bonus --- BuildingLevel.gd | 69 +++++++++++++++++++++++- InfoWindow.tscn | 2 +- Main.tscn | 14 +++++ ResourceGain.tscn | 18 +++++++ info_window.gd | 77 +++++++++++++++++++++++---- parts/buildings/essencecompressor.txt | 4 +- parts/buildings/foodgathering.txt | 5 ++ parts/buildings/foodprocessing.txt | 6 +++ parts/buildings/stoneminer.txt | 1 + parts/buildings/waterprocessor.txt | 6 +++ parts/buildings/waterpump.txt | 5 ++ parts/buildings/woodcutter.txt | 1 + resource_gain.gd | 21 ++++++++ ui.gd | 27 ++++++++++ 14 files changed, 241 insertions(+), 15 deletions(-) create mode 100644 ResourceGain.tscn create mode 100644 resource_gain.gd diff --git a/BuildingLevel.gd b/BuildingLevel.gd index 469d155..d5ba751 100644 --- a/BuildingLevel.gd +++ b/BuildingLevel.gd @@ -13,6 +13,7 @@ var last_text var rand = 0 const NAME_ICON = preload("res://NameIcon.tscn") +const RESOURCE_GAIN = preload("res://ResourceGain.tscn") var building_to_tile_map = { "tents": { @@ -98,6 +99,66 @@ func _process(delta: float) -> void: last_text.position = map_to_local(tile) + Vector2(-25, -10) add_sibling(last_text) + for coords in building_data: + var building = building_data[coords] + if building.has("workers") and building.workers > 0 and (not Data.data.buildings[building.key].has("needs") or (Persister.get_value(Data.data.buildings[building.key].needs, PersisterEnums.Scope.UNKNOWN, 0) > 0)): + building.progress += delta * building.efficiency / 100.0 + + if building.progress >= Data.data.buildings[building.key].time: + if Data.data.buildings[building.key].has("needs"): + Persister.change_value(Data.data.buildings[building.key].needs, -1) + Persister.change_value(Data.data.buildings[building.key].resource, Data.data.buildings[building.key].amount) + var gain = RESOURCE_GAIN.instantiate() + gain.text = "[center]+1 %s" % [Data.data.buildings[building.key].resourcename] + gain.position = map_to_local(coords) + Vector2(-25, -5) + add_sibling(gain) + building.progress -= Data.data.buildings[building.key].time + + if building.has("workers"): + var close_bonus = 1.0 + + if building.key == "woodcutter": + if tree_spots.size() == 0: + close_bonus = 0 + else: + var min_distance = INF + for tree in tree_spots: + var distance = tree.distance_to(coords) + + if distance < min_distance: + min_distance = distance + + if min_distance > 5: + close_bonus = 0 + else: + close_bonus = 1 - (min_distance / 5) + elif building.key == "stoneminer": + if rock_spots.size() == 0: + close_bonus = 0 + else: + var min_distance = INF + for tree in rock_spots: + var distance = tree.distance_to(coords) + + if distance < min_distance: + min_distance = distance + + if min_distance > 5: + close_bonus = 0 + else: + close_bonus = 1 - (min_distance / 5) + elif building.key == "waterpump": + var water_level = Persister.get_value("flood_level", PersisterEnums.Scope.UNKNOWN, 0) + + var amount = level - water_level + + if amount > 3: + close_bonus = 0 + else: + close_bonus = (3 - amount) + + building.efficiency = (100 + Persister.get_value("conduit_bonus", PersisterEnums.Scope.UNKNOWN, 0)) * building.workers * 0.5 * close_bonus + last_tile = tile if not building_mode: @@ -113,6 +174,7 @@ func _ready() -> void: Triggerer.listen("flood_level", _on_flood_level) + func _on_flood_level(data): var value = int(data.value) @@ -158,10 +220,13 @@ func place_building(): if build_data.type == "housing": Persister.change_value("max_population", int(build_data.amount)) building_data[tile].max_population = int(build_data.amount) - else: + elif build_data.name != "Conduit": building_data[tile].workers = 0 building_data[tile].max_workers = 6 - building_data[tile].efficiency = 100 + building_data[tile].efficiency = 100 + Persister.get_value("conduit_bonus", PersisterEnums.Scope.UNKNOWN, 0) + building_data[tile].progress = 0 + else: + Persister.change_value("conduit_bonus", 20) Persister.persist_data("drag_mode", false) diff --git a/InfoWindow.tscn b/InfoWindow.tscn index 6e95352..db433b8 100644 --- a/InfoWindow.tscn +++ b/InfoWindow.tscn @@ -242,7 +242,7 @@ text = "[center]+" position = Vector2(-50, 0) [node name="CollisionShape2D" type="CollisionShape2D" parent="ResourceAllocation/ColorRect3/MouseHandler2"] -position = Vector2(8, 8) +position = Vector2(58, 8) shape = SubResource("RectangleShape2D_fnpfc") [node name="RichTextLabel" type="RichTextLabel" parent="ResourceAllocation"] diff --git a/Main.tscn b/Main.tscn index e32240c..c8a78e2 100644 --- a/Main.tscn +++ b/Main.tscn @@ -550,6 +550,20 @@ text = "0/0 vertical_alignment = 1 script = ExtResource("16_knn3d") +[node name="WoodCountLabel2" type="Label" parent="CanvasLayer/UI/Background/Control3"] +layout_mode = 2 +offset_left = 35.0 +offset_top = 12.71 +offset_right = 94.0 +offset_bottom = 36.71 +scale = Vector2(1e-05, 1e-05) +pivot_offset = Vector2(30, 12.29) +theme_override_colors/font_color = Color(0.403492, 0.47752, 0.570235, 1) +theme_override_constants/outline_size = 3 +text = "0 Available" +horizontal_alignment = 1 +vertical_alignment = 1 + [node name="Control2" type="Control" parent="CanvasLayer/UI/Background"] anchors_preset = 0 offset_right = 40.0 diff --git a/ResourceGain.tscn b/ResourceGain.tscn new file mode 100644 index 0000000..624a99d --- /dev/null +++ b/ResourceGain.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=3 format=3 uid="uid://d0sou8ksu22pm"] + +[ext_resource type="Theme" uid="uid://d035h7upxrw3h" path="res://theme.tres" id="1_aw2u1"] +[ext_resource type="Script" path="res://resource_gain.gd" id="2_enpvk"] + +[node name="NameIcon" type="RichTextLabel"] +z_index = 10 +clip_contents = false +offset_left = 243.0 +offset_top = 104.0 +offset_right = 369.0 +offset_bottom = 121.0 +pivot_offset = Vector2(62, 4) +theme = ExtResource("1_aw2u1") +theme_override_constants/outline_size = 3 +bbcode_enabled = true +text = "[center]Rock" +script = ExtResource("2_enpvk") diff --git a/info_window.gd b/info_window.gd index 1fcf8a7..44f29a8 100644 --- a/info_window.gd +++ b/info_window.gd @@ -12,6 +12,8 @@ var window_tween @onready var color_rect_5: ColorRect = $ColorRect5 @onready var color_rect_2: ColorRect = $ResourceAllocation/ColorRect2 @onready var color_rect_3: ColorRect = $ResourceAllocation/ColorRect3 +@onready var color_rect_4: ColorRect = $ResourceAllocation/ColorRect4 +@onready var description_2: RichTextLabel = $ResourceAllocation/Description2 var recent_data @@ -29,7 +31,7 @@ func _ready() -> void: func _on_flood_level(data): var value = int(data.value) - if value >= recent_data.level: + if recent_data and value >= recent_data.level: Triggerer.trigger("hide_info") @@ -52,7 +54,7 @@ func _show_info_window(data): subtitle.text = "[center]%s" % [building_data.short] if data.has("workers"): rich_text_label_2.text = "[center]%d/%d" % [data.workers, data.max_workers] - description_3.text = "[center]EFFICIENCY: %d%" % [data.efficiency] + description_3.text = "[center]EFFICIENCY: %d%%" % [data.efficiency] resource_allocation.visible = true else: resource_allocation.visible = false @@ -66,7 +68,18 @@ func _show_info_window(data): func _process(delta: float) -> void: if Input.is_action_just_pressed("rclick"): _hide_info_window({}) - + + if recent_data and recent_data.has("progress"): + color_rect_4.scale.x = (float(recent_data.progress) / Data.data.buildings[recent_data.key].time) + + if recent_data and recent_data.has("workers") and recent_data.workers > 0: + description_2.text = "[center]STATUS: WORKING" + else: + description_2.text = "[center]STATUS: STOPPED" + + if recent_data: + description_3.text = "[center]EFFICIENCY: %d%%" % [recent_data.efficiency] + func _hide_info_window(_data): if window_tween: @@ -79,27 +92,73 @@ func _hide_info_window(_data): func _on_mouse_handler_clicked() -> void: - pass # Replace with function body. + if recent_data.workers > 0: + recent_data.workers -= 1 + Persister.change_value("avail_population", 1) + rich_text_label_2.text = "[center]%d/%d" % [recent_data.workers, recent_data.max_workers] + + if minus_tween: + minus_tween.kill() + + minus_tween = create_tween() + minus_tween.set_trans(Tween.TRANS_QUAD) + minus_tween.tween_property(color_rect_2, "scale", Vector2.ONE * 0.95, 0.125) + minus_tween.tween_property(color_rect_2, "scale", Vector2.ONE, 0.125) func _on_mouse_handler_hovered() -> void: - pass # Replace with function body. + if minus_tween: + minus_tween.kill() + + minus_tween = create_tween() + minus_tween.set_ease(Tween.EASE_OUT) + minus_tween.set_trans(Tween.TRANS_BACK) + minus_tween.tween_property(color_rect_2, "scale", Vector2.ONE * 1.05, 0.25) func _on_mouse_handler_unhovered() -> void: - pass # Replace with function body. + if minus_tween: + minus_tween.kill() + + minus_tween = create_tween() + minus_tween.set_ease(Tween.EASE_OUT) + minus_tween.set_trans(Tween.TRANS_QUAD) + minus_tween.tween_property(color_rect_2, "scale", Vector2.ONE, 0.25) func _on_mouse_handler_2_clicked() -> void: - pass # Replace with function body. + if recent_data.workers < recent_data.max_workers and Persister.get_value("avail_population") > 0: + recent_data.workers += 1 + Persister.change_value("avail_population", -1) + rich_text_label_2.text = "[center]%d/%d" % [recent_data.workers, recent_data.max_workers] + + if plus_tween: + plus_tween.kill() + + plus_tween = create_tween() + plus_tween.set_trans(Tween.TRANS_QUAD) + plus_tween.tween_property(color_rect_3, "scale", Vector2.ONE * 0.95, 0.125) + plus_tween.tween_property(color_rect_3, "scale", Vector2.ONE, 0.125) func _on_mouse_handler_2_hovered() -> void: - pass # Replace with function body. + if plus_tween: + plus_tween.kill() + + plus_tween = create_tween() + plus_tween.set_ease(Tween.EASE_OUT) + plus_tween.set_trans(Tween.TRANS_BACK) + plus_tween.tween_property(color_rect_3, "scale", Vector2.ONE * 1.05, 0.25) func _on_mouse_handler_2_unhovered() -> void: - pass # Replace with function body. + if plus_tween: + plus_tween.kill() + + plus_tween = create_tween() + plus_tween.set_ease(Tween.EASE_OUT) + plus_tween.set_trans(Tween.TRANS_QUAD) + plus_tween.tween_property(color_rect_3, "scale", Vector2.ONE, 0.25) func _on_mouse_handler_3_clicked() -> void: diff --git a/parts/buildings/essencecompressor.txt b/parts/buildings/essencecompressor.txt index 25851ed..397dace 100644 --- a/parts/buildings/essencecompressor.txt +++ b/parts/buildings/essencecompressor.txt @@ -1,10 +1,8 @@ name: Conduit short: Boosts Production type: production -resource: essence -amount: 1 +boost: 5 time: 10 -max_workers: 6 cost[] stone: 3 wood: 2 diff --git a/parts/buildings/foodgathering.txt b/parts/buildings/foodgathering.txt index c1df883..2216690 100644 --- a/parts/buildings/foodgathering.txt +++ b/parts/buildings/foodgathering.txt @@ -1,5 +1,10 @@ name: Field short: Produces Wheat type: utility +resource: wheat +resourcename: Wheat +time: 5 +amount: 1 +max_workers: 6 cost[] wood: 2 diff --git a/parts/buildings/foodprocessing.txt b/parts/buildings/foodprocessing.txt index 8798370..8923663 100644 --- a/parts/buildings/foodprocessing.txt +++ b/parts/buildings/foodprocessing.txt @@ -1,6 +1,12 @@ name: Farmhouse short: Turns Wheat to Food type: utility +resource: food +time: 15 +amount: 1 +needs: wheat +max_workers: 6 +resourcename: Food cost[] wood: 4 stone: 8 diff --git a/parts/buildings/stoneminer.txt b/parts/buildings/stoneminer.txt index e722618..c4c90e0 100644 --- a/parts/buildings/stoneminer.txt +++ b/parts/buildings/stoneminer.txt @@ -5,5 +5,6 @@ amount: 1 time: 10 max_workers: 6 short: Gathers Stone +resourcename: Stone cost[] stone: 2 diff --git a/parts/buildings/waterprocessor.txt b/parts/buildings/waterprocessor.txt index 60bc351..11b073e 100644 --- a/parts/buildings/waterprocessor.txt +++ b/parts/buildings/waterprocessor.txt @@ -1,6 +1,12 @@ name: Water Processor type: utility short: Cleans Water +time: 15 +amount: 1 +needs: drops +max_workers: 6 +resource: water +resourcename: Clean Water cost[] wood: 6 stone: 10 diff --git a/parts/buildings/waterpump.txt b/parts/buildings/waterpump.txt index 35aff18..1758868 100644 --- a/parts/buildings/waterpump.txt +++ b/parts/buildings/waterpump.txt @@ -1,5 +1,10 @@ name: Water Pump type: utility short: Produces Water +resource: drops +time: 5 +amount: 1 +max_workers: 6 +resourcename: Water cost[] stone: 3 diff --git a/parts/buildings/woodcutter.txt b/parts/buildings/woodcutter.txt index 99cfec6..66982ea 100644 --- a/parts/buildings/woodcutter.txt +++ b/parts/buildings/woodcutter.txt @@ -5,5 +5,6 @@ amount: 1 time: 10 max_workers: 6 short: Gathers Wood +resourcename: Wood cost[] stone: 3 diff --git a/resource_gain.gd b/resource_gain.gd new file mode 100644 index 0000000..dda822e --- /dev/null +++ b/resource_gain.gd @@ -0,0 +1,21 @@ +extends RichTextLabel + +var tween +var selected = true + +func _ready() -> void: + var starting_pos = position + scale = Vector2.ZERO + tween = create_tween() + tween.set_ease(Tween.EASE_OUT) + tween.set_trans(Tween.TRANS_BACK) + tween.tween_property(self, "scale", Vector2.ONE, 0.25) + tween.tween_interval(0.5) + tween.set_trans(Tween.TRANS_QUAD) + tween.tween_property(self, "scale", Vector2.ZERO, 0.25) + tween.tween_callback(func(): + queue_free() + ) + + var tween2 = create_tween() + tween2.tween_property(self, "position:y", starting_pos.y - 20, 1) diff --git a/ui.gd b/ui.gd index 8bd59e1..0b09b70 100644 --- a/ui.gd +++ b/ui.gd @@ -1,14 +1,41 @@ extends CanvasLayer @onready var animation_player: AnimationPlayer = $AnimationPlayer +@onready var wood_count_label_2: Label = $UI/Background/Control3/WoodCountLabel2 + +var available_tween func _ready() -> void: Persister.persist_data("wood", 50) Persister.persist_data("stone", 50) Persister.persist_data("population", 3) + Persister.persist_data("avail_population", 3) Persister.persist_data("max_population", 3) + Triggerer.listen("show_info", _on_show_info) + Triggerer.listen("hide_info", _on_hide_info) func _process(delta: float) -> void: if Input.is_action_just_pressed("lclick") and not Persister.get_value("game_started"): Persister.persist_data("game_started", true) animation_player.play("start") + + wood_count_label_2.text = "%d available" % [Persister.get_value("avail_population")] + +func _on_show_info(_data): + if available_tween: + available_tween.kill() + + available_tween = create_tween() + available_tween.set_ease(Tween.EASE_OUT) + available_tween.set_trans(Tween.TRANS_BACK) + available_tween.tween_property(wood_count_label_2, "scale", Vector2.ONE, 0.5) + + +func _on_hide_info(_data): + if available_tween: + available_tween.kill() + + available_tween = create_tween() + available_tween.set_ease(Tween.EASE_OUT) + available_tween.set_trans(Tween.TRANS_QUAD) + available_tween.tween_property(wood_count_label_2, "scale", Vector2.ZERO, 0.5)