From d6a158a1ae8e0cd3921ee486ddbb3a06ee443574 Mon Sep 17 00:00:00 2001
From: Luna <judahiii@gmail.com>
Date: Sat, 28 Apr 2018 17:53:51 -0400
Subject: [PATCH] Give losing or non-possessing team more charge!

Nice! I love this balance tweak! And it can be changed depending on how
strong we want it to be.
---
 plans.md                   |  2 --
 scenes/level.tscn          |  1 -
 scripts/heroes/1_wall.gd   |  2 +-
 scripts/heroes/2.gd        |  2 +-
 scripts/heroes/3.gd        |  2 +-
 scripts/heroes/4.gd        |  4 ++--
 scripts/heroes/5.gd        |  2 +-
 scripts/heroes/5_portal.gd |  2 +-
 scripts/player.gd          | 17 ++++++++++++++++-
 9 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/plans.md b/plans.md
index 0fde1f4..e127ec1 100644
--- a/plans.md
+++ b/plans.md
@@ -25,8 +25,6 @@ Smaller TODOs:
 - Ira is OP?
   - Nerfed - 5 walls
 - Make motion more reactive?
-- Grab someone and draw an impulse on them
-  - Combine with SUPERBIA, use charge to build portals
 
 Bugs:
 
diff --git a/scenes/level.tscn b/scenes/level.tscn
index fc34b1a..16e1a7d 100644
--- a/scenes/level.tscn
+++ b/scenes/level.tscn
@@ -155,7 +155,6 @@ directional_shadow_max_distance = 200.0
 
 [node name="Players" type="Spatial" parent="." index="1"]
 
-
 [node name="Ball" type="RigidBody" parent="." index="2"]
 
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -14.4344, 6.09969, 4.40885 )
diff --git a/scripts/heroes/1_wall.gd b/scripts/heroes/1_wall.gd
index f359e33..ef78b48 100644
--- a/scripts/heroes/1_wall.gd
+++ b/scripts/heroes/1_wall.gd
@@ -5,7 +5,7 @@ var being_touched = 0
 
 func _process(delta):
 	if being_touched > 0:
-		maker_node.switch_charge += touch_charge * delta
+		maker_node.build_charge(touch_charge * delta)
 
 func init(maker):
 
diff --git a/scripts/heroes/2.gd b/scripts/heroes/2.gd
index 7f84167..3af3272 100644
--- a/scripts/heroes/2.gd
+++ b/scripts/heroes/2.gd
@@ -15,7 +15,7 @@ func _process(delta):
 				get_node("MasterOnly/Crosshair").set_text("\\/")
 
 		var overlapping = get_node("Area").get_overlapping_bodies().size()
-		switch_charge += delta * overlap_charge * overlapping
+		build_charge(delta * overlap_charge * overlapping)
 
 sync func switch_gravity():
 	var area = get_node("Area")
diff --git a/scripts/heroes/3.gd b/scripts/heroes/3.gd
index c904333..b5603af 100644
--- a/scripts/heroes/3.gd
+++ b/scripts/heroes/3.gd
@@ -39,7 +39,7 @@ func _process(delta):
 			# Subtract and then add, so we can continously add this
 			switch_charge -= boost_charge
 			boost_charge = merged.switch_charge - original_charge
-			switch_charge += boost_charge
+			build_charge(boost_charge)
 
 func control_player(state):
 	if !merged:
diff --git a/scripts/heroes/4.gd b/scripts/heroes/4.gd
index c25b00c..179792a 100644
--- a/scripts/heroes/4.gd
+++ b/scripts/heroes/4.gd
@@ -46,8 +46,8 @@ func _process(delta):
 			var player = pick_from(players)
 			if player != -1:
 				# We get charge for just stunning, plus charge for how much linear velocity we cut out
-				switch_charge += stun_charge * delta
-				switch_charge += velocity_charge * players[player].get_linear_velocity().length() * delta
+				build_charge(stun_charge * delta)
+				build_charge(velocity_charge * players[player].linear_velocity.length() * delta)
 				rpc("stun", players[player].get_name(), get_node("TPCamera/Camera/Ray").get_collision_point())
 				is_stunning = true
 
diff --git a/scripts/heroes/5.gd b/scripts/heroes/5.gd
index 3f7fb15..72fd2e8 100644
--- a/scripts/heroes/5.gd
+++ b/scripts/heroes/5.gd
@@ -63,7 +63,7 @@ func flick_input():
 		towards -= gravity
 		rpc("flick", flicking.get_name(), towards)
 		flicking = null
-		switch_charge += flick_charge
+		build_charge(flick_charge)
 
 sync func flick(player_id, towards):
 	var who = $"/root/Level/Players".get_node(player_id)
diff --git a/scripts/heroes/5_portal.gd b/scripts/heroes/5_portal.gd
index 9b4f547..da361b2 100644
--- a/scripts/heroes/5_portal.gd
+++ b/scripts/heroes/5_portal.gd
@@ -65,5 +65,5 @@ func portal(player):
 				# With both axes, gravity could never bring us to hit the portal
 				var to = other.to_global(Vector3(spawn_distance,0,-spawn_distance)) 
 				player.set_translation(to)
-				maker_node.switch_charge += portal_charge
+				maker_node.build_charge(portal_charge)
 
diff --git a/scripts/player.gd b/scripts/player.gd
index a85d604..2adddfa 100644
--- a/scripts/player.gd
+++ b/scripts/player.gd
@@ -83,7 +83,7 @@ func _process(delta):
 		var vel = get_linear_velocity()
 		if translation.y < switch_height:
 			vel.y = 0 # Don't gain charge from falling when below switch_height
-		switch_charge += movement_charge * vel.length() * delta
+		build_charge(movement_charge * vel.length() * delta)
 		switch_text.set_text("%d%%" % int(switch_charge)) # We truncate, rather than round, so that switch is displayed AT 100%
 		if switch_charge >= 100:
 			switch_hero_action.show()
@@ -118,6 +118,21 @@ func _exit_tree():
 # Functions
 # =========
 
+# Build all charge with a multiplier for ~~balance~~
+func build_charge(amount):
+	# If we used build_charge to cost charge, don't mess with it!
+	if amount > 0:
+		var losing_advantage = 1.2
+		var uncapped_advantage = 1.3
+		var obj = get_node("/root/Level/FullObjective/Objective")
+		if (obj.left > obj.right) == player_info.is_right_team:
+			# Is losing (left winning, we're on right or vice versa)
+			amount *= losing_advantage
+		if obj.right_active != player_info.is_right_team and obj.active:
+			# Point against us (right active and left, or vice versa)
+			amount *= uncapped_advantage
+	switch_charge += amount
+
 sync func spawn():
 	emit_signal("spawn")
 	if "record" in player_info: