From 47cf538a96494a3d2c242580f3641efb3062ebb1 Mon Sep 17 00:00:00 2001
From: Luna <judahiii@gmail.com>
Date: Mon, 28 May 2018 22:26:19 -0400
Subject: [PATCH] Rename switch_charge to charge (reflecting usage)

---
 scripts/ability_icon.gd    |  6 +++---
 scripts/ai.gd              |  6 +++---
 scripts/hero_select.gd     |  2 +-
 scripts/heroes/0.gd        |  4 ++--
 scripts/heroes/1.gd        |  6 +++---
 scripts/heroes/3.gd        | 11 +++++++----
 scripts/heroes/4.gd        |  2 +-
 scripts/heroes/5.gd        |  4 ++--
 scripts/heroes/5_portal.gd |  2 +-
 scripts/player.gd          | 40 ++++++++++++++++++++--------------------
 10 files changed, 43 insertions(+), 40 deletions(-)

diff --git a/scripts/ability_icon.gd b/scripts/ability_icon.gd
index 886f9db..7ff9ecb 100644
--- a/scripts/ability_icon.gd
+++ b/scripts/ability_icon.gd
@@ -42,10 +42,10 @@ func _process(delta):
 	else:
 		if display_progress:
 			if cost == 0:
-				bar.value = 100 if hero.switch_charge > 0 else 0
+				bar.value = 100 if hero.charge > 0 else 0
 			else:
-				bar.value = 100 * hero.switch_charge / cost
-		if hero.switch_charge > cost:
+				bar.value = 100 * hero.charge / cost
+		if hero.charge > cost:
 			available.show()
 		else:
 			available.hide()
diff --git a/scripts/ai.gd b/scripts/ai.gd
index 2b54a34..0aba6c8 100644
--- a/scripts/ai.gd
+++ b/scripts/ai.gd
@@ -24,8 +24,8 @@ func _physics_process(delta):
 
 func set_spawn():
 	get_node("..").set_translation(str2var(recording.spawn))
-	print(recording.switch_charge)
-	get_node("..").switch_charge = str2var(recording.switch_charge)
+	print(recording.charge)
+	get_node("..").charge = str2var(recording.charge)
 
 func read_recording():
 
@@ -80,7 +80,7 @@ func play_keys():
 	# events[0][0] is first event's TIME
 	if recording.events.size() == 0:
 		get_node("..").spawn() # This may cause spawn twice, I hope this isn't a problem
-		# get_node("..").switch_charge = 0 # This needs to reset so the recording is accurate
+		# get_node("..").charge = 0 # This needs to reset so the recording is accurate
 		read_recording()
 	while float(recording.events[0][0]) <= time:
 		# events[0][1] is first event's EVENT
diff --git a/scripts/hero_select.gd b/scripts/hero_select.gd
index ebb7b3c..a180f51 100644
--- a/scripts/hero_select.gd
+++ b/scripts/hero_select.gd
@@ -10,7 +10,7 @@ const hero_names = [
 ]
 
 const hero_text = [
-	"DILIGENCE.\n\nWallride by jumping on walls.\n\nHold left click to go faster (but spend switch charge).",
+	"DILIGENCE.\n\nWallride by jumping on walls.\n\nHold left click to go faster (but spend charge).",
 	"WRATH.\n\nPress E and click (or just click) to build a wall.\n\nRight click to destroy one.",
 	"LUST.\n\nYou attract nearby heroes.\n\nPress E to switch to repelling them.",
 	"GENEROSITY.\n\nMake contact with a friend to boost their speed.\n\nPress E to separate.",
diff --git a/scripts/heroes/0.gd b/scripts/heroes/0.gd
index 862e3b2..efaf9ca 100644
--- a/scripts/heroes/0.gd
+++ b/scripts/heroes/0.gd
@@ -24,7 +24,7 @@ func control_player(state):
 	var boost_strength = 2
 	var boost_drain = 25 # Recall increased charge must be factored in
 	var cost = boost_drain * state.step
-	if get_node("MasterOnly/Boost").is_pressed() and switch_charge > cost:
+	if get_node("MasterOnly/Boost").is_pressed() and charge > cost:
 		walk_speed *= 2
 		air_accel *= 3
 		build_charge(-cost)
@@ -60,7 +60,7 @@ func wallride(state):
 			apply_impulse(Vector3(), air_accel * aim[2] * get_mass())
 		# Allow jumping (for wall hopping!)
 		if Input.is_action_just_pressed("jump"):
-			var build_factor = 1 + switch_charge * wallride_leap_build
+			var build_factor = 1 + charge * wallride_leap_build
 			var jump_impulse = build_factor * wallride_leap_side * last_wall_normal
 			jump_impulse.y += build_factor * wallride_leap_height
 			set_gravity_scale(1) # Jumping requires gravity
diff --git a/scripts/heroes/1.gd b/scripts/heroes/1.gd
index 8733b31..71a00c5 100644
--- a/scripts/heroes/1.gd
+++ b/scripts/heroes/1.gd
@@ -15,7 +15,7 @@ func _ready():
 
 func _process(delta):
 	if is_network_master():
-		var can_build = switch_charge > place_wall_ability.cost
+		var can_build = charge > place_wall_ability.cost
 		if can_build:
 			if placement.place_input():
 				build_charge(-place_wall_ability.cost)
@@ -42,8 +42,8 @@ func on_looked_at(who, delta):
 	if who.player_info.is_right_team != player_info.is_right_team:
 		var subtracted = who.build_charge(-looked_at_charge_suck * delta)
 		build_charge(-subtracted)
-		# We rset our switch_charge because otherwise it won't be acknowledged
+		# We rset our charge because otherwise it won't be acknowledged
 		# because we're not master
 		# The *PICKER* is master, we're slave! Well, let's flip that for a mo'
-		rset("switch_charge", switch_charge)
+		rset("charge", charge)
 
diff --git a/scripts/heroes/3.gd b/scripts/heroes/3.gd
index 7f5229e..4372adb 100644
--- a/scripts/heroes/3.gd
+++ b/scripts/heroes/3.gd
@@ -37,9 +37,12 @@ func _process(delta):
 			rpc("unmerge")
 		if merged:
 			# Subtract and then add, so we can continously add this
-			switch_charge -= boost_charge
-			boost_charge = merged.switch_charge - original_charge
-			build_charge(boost_charge)
+			# We don't use build_charge because this is delicate math
+			charge -= boost_charge
+			boost_charge = merged.charge - original_charge
+			charge += boost_charge
+			# Network the changes
+			build_charge(0)
 
 func control_player(state):
 	if !merged:
@@ -85,7 +88,7 @@ func set_boosted(node, is_boosted):
 	node.walk_speed *= ratio
 	node.air_accel *= ratio
 	if is_boosted:
-		original_charge = node.switch_charge
+		original_charge = node.charge
 		boost_charge = 0
 
 sync func merge(node_name):
diff --git a/scripts/heroes/4.gd b/scripts/heroes/4.gd
index 15221bc..2e239e3 100644
--- a/scripts/heroes/4.gd
+++ b/scripts/heroes/4.gd
@@ -35,7 +35,7 @@ func _process(delta):
 			destroy_ability.cost = looking_at.destroy_cost
 			destroy_ability.disabled = false
 			if Input.is_action_just_pressed("primary_ability"):
-					if switch_charge > looking_at.destroy_cost:
+					if charge > looking_at.destroy_cost:
 						build_charge(-looking_at.destroy_cost)
 						looking_at.rpc("destroy")
 		else:
diff --git a/scripts/heroes/5.gd b/scripts/heroes/5.gd
index 875beb4..2e54d64 100644
--- a/scripts/heroes/5.gd
+++ b/scripts/heroes/5.gd
@@ -27,9 +27,9 @@ func _process(delta):
 	if is_network_master():
 		var is_second = placement.placed.size() % 2 != 0
 		var portal_crosshair = second_crosshair if is_second else first_crosshair
-		var crosshair = no_portal_crosshair if switch_charge < portal_ability.cost else portal_crosshair
+		var crosshair = no_portal_crosshair if charge < portal_ability.cost else portal_crosshair
 		get_node("MasterOnly/Crosshair").set_text(crosshair)
-		var can_build = switch_charge > portal_ability.cost
+		var can_build = charge > portal_ability.cost
 		if placement.place_input(radius, can_build, true) and is_second:
 			build_charge(-portal_ability.cost)
 
diff --git a/scripts/heroes/5_portal.gd b/scripts/heroes/5_portal.gd
index 757f7d9..a5010f2 100644
--- a/scripts/heroes/5_portal.gd
+++ b/scripts/heroes/5_portal.gd
@@ -57,7 +57,7 @@ func player_collided(with, player):
 func portal(player):
 	if player.player_info.is_right_team == maker_node.player_info.is_right_team:
 		if other:
-			if maker_node.switch_charge > -portal_charge:
+			if maker_node.charge > -portal_charge:
 				var spawn_distance = 1.75
 				# Find a sane place to spawn
 				# -Z is in the direction of the portal
diff --git a/scripts/player.gd b/scripts/player.gd
index 479ca9e..24e2c79 100644
--- a/scripts/player.gd
+++ b/scripts/player.gd
@@ -18,11 +18,11 @@ var air_accel = .1 # m/s/s
 var floor_friction = 1-0.08
 var air_friction = 1-0.03
 
-var walk_speed_build = 0.006 # `walk_speed` per `switch_charge`
-var air_speed_build = 0.006 # `air_accel` per `switch_charge`
+var walk_speed_build = 0.006 # `walk_speed` per `charge`
+var air_speed_build = 0.006 # `air_accel` per `charge`
 
-sync var switch_charge = 0
-var switch_charge_cap = 200 # While switching is always at 100, things like speed boost might go higher!
+sync var charge = 0
+var charge_cap = 200 # While switching is always at 100, things like speed boost might go higher!
 var movement_charge = 0.15 # In percent per meter (except when heroes change that)
 
 # Nodes
@@ -71,7 +71,7 @@ func _input(event):
 		if "record" in player_info:
 			recording.events.append([recording.time, event_to_obj(event)])
 		if Input.is_action_just_pressed("enable_cheats"):
-			switch_charge = 199
+			charge = 199
 
 func _process(delta):
 	# All player code not caused by input, and not causing movement
@@ -79,7 +79,7 @@ func _process(delta):
 
 		# Check falling (cancel charge and respawn)
 		var fall_height = -400 # This is essentially the respawn timer
-		var switch_height = -150 # At this point, stop adding to switch_charge. This makes falls not charge you too much
+		var switch_height = -150 # At this point, stop adding to charge. This makes falls not charge you too much
 		var vel = get_linear_velocity()
 		if translation.y < switch_height:
 			vel.y = 0 # Don't gain charge from falling when below switch_height
@@ -87,17 +87,17 @@ func _process(delta):
 		if get_translation().y < fall_height:
 			rpc("spawn")
 
-		# Update switch charge GUI
-		switch_text.set_text("%d%%" % int(switch_charge)) # We truncate, rather than round, so that switch is displayed AT 100%
-		if switch_charge >= 100:
+		# Update charge GUI
+		switch_text.set_text("%d%%" % int(charge)) # We truncate, rather than round, so that switch is displayed AT 100%
+		if charge >= 100:
 			switch_hero_action.show()
 		else:
 			switch_hero_action.hide()
-		if switch_charge > switch_charge_cap:
+		if charge > charge_cap:
 			# There is however a cap
-			switch_charge = switch_charge_cap
-		switch_bar.value = switch_charge
-		switch_bar_extra.value = switch_charge - 100
+			charge = charge_cap
+		switch_bar.value = charge
+		switch_bar_extra.value = charge - 100
 
 		# AI recording
 		if "record" in player_info:
@@ -140,10 +140,10 @@ func build_charge(amount):
 			amount *= uncapped_advantage
 	else:
 		# Only build down to 0
-		amount = max(amount, -switch_charge)
-	switch_charge += amount
+		amount = max(amount, -charge)
+	charge += amount
 	if is_network_master():
-		rset_unreliable("switch_charge", switch_charge)
+		rset_unreliable("charge", charge)
 	return amount
 
 sync func spawn():
@@ -163,7 +163,7 @@ sync func spawn():
 	placement.z += rand_range(0, z_varies)
 	recording = { "time": 0, "states": [], "events": [], "spawn": Vector3() }
 	recording.spawn = var2str(placement)
-	recording.switch_charge = var2str(switch_charge)
+	recording.charge = var2str(charge)
 	set_transform(Basis())
 	set_translation(placement)
 	set_linear_velocity(Vector3())
@@ -274,7 +274,7 @@ func control_player(state):
 		var floor_velocity = Vector3()
 		var object = ray.get_collider()
 
-		var accel = (1 + switch_charge * walk_speed_build) * walk_speed
+		var accel = (1 + charge * walk_speed_build) * walk_speed
 		state.apply_impulse(Vector3(), direction * accel * get_mass())
 		var lin_v = state.get_linear_velocity()
 		lin_v.x *= floor_friction
@@ -285,7 +285,7 @@ func control_player(state):
 			state.apply_impulse(Vector3(), normal * jump_speed * get_mass())
 
 	else:
-		var accel = (1 + switch_charge * air_speed_build) * air_accel
+		var accel = (1 + charge * air_speed_build) * air_accel
 		state.apply_impulse(Vector3(), direction * accel * get_mass())
 		var lin_v = state.get_linear_velocity()
 		lin_v.x *= air_friction
@@ -295,7 +295,7 @@ func control_player(state):
 	state.integrate_forces()
 
 func switch_hero_interface():
-	if switch_charge >= 100:
+	if charge >= 100:
 		# Interface needs the mouse!
 		toggle_mouse_capture()
 		# Pause so if we have walls and such nothing funny happens