Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
4.9 kB
3
Indexable
Never
extends Button

signal CityClicked(population: float,loyalty: float,prosperity: float,safety: float,military: float,wealth: float,populationchange: float,loyaltychange: float,prosperitychange: float,safetychange: float,militarychange: float,wealthchange: float)
var hovered: bool = false

var CityName: String = "Cowtopia"

var population: float = 10000
var loyalty: float = 50
var prosperity: float = 1000
var safety: float = 50.1
var military: float = 250
var wealth: float = 100000
var income: float = 1000
var expenses: float = 500

var PopulationDisplay: float
var LoyaltyDisplay: float
var ProsperityDisplay: float
var SafetyDisplay: float
var MilitaryDisplay: float
var WealthDisplay: float
var IncomeDisplay: float
var ExpensesDisplay: float

var PopulationChange: float
var LoyaltyChange: float
var ProsperityChange: float
var SafetyChange: float
var MilitaryChange: float
var WealthChange: float

var PopulationChangeDisplay: float
var LoyaltyChangeDisplay: float
var ProsperityChangeDisplay: float
var SafetyChangeDisplay: float
var MilitaryChangeDisplay: float
var WealthChangeDisplay: float

func _on_income_timer_timeout():
	if population < 10000:
		PopulationChange = (population * .00001) * (prosperity * .001) * (safety * .02) #grows no matter what
	elif population < 50000:
		PopulationChange = (population * .00001) * (prosperity * .001 - 1) * (safety * .02) #population can start shrinking if below 1000 prosperity
	elif population < 100000:
		PopulationChange = (population * .00001) * (prosperity * .001 - 2) * (safety * .02) #population can start shrinking if below 2000 prosperity
	elif population >= 100000:
		PopulationChange = (population * .00001) * (prosperity * .001 - 3) * (safety * .02) #population can start shrinking if below 3000 prosperity
	population += PopulationChange
	PopulationDisplay = snappedf(population,1)
	PopulationChangeDisplay = snappedf(PopulationChange,.01)
	population = snappedf(population,.0000001)
	
	if wealth < 0:
		LoyaltyChange = (safety * .02 - 1) * (military - (population * .01)) - 1
	else:
		LoyaltyChange = (safety * .02 - 1) * (military - (population * .01))
	if loyalty + LoyaltyChange >= 100:
		loyalty = 100
	elif loyalty + LoyaltyChange <= 0:
		loyalty = 0
	else:
		loyalty += LoyaltyChange
	LoyaltyDisplay = snappedf(loyalty,.1)
	LoyaltyChangeDisplay = snappedf(LoyaltyChange,.01)
	loyalty = snappedf(loyalty,.0000001)
	
	if wealth < 0:
		ProsperityChange = ((population * .0001) * -1) + (safety * .02 - 1)
	else:
		ProsperityChange = ((population * .0001) * -1) + (safety * .02 - 1) + 4
	prosperity += ProsperityChange
	ProsperityDisplay = snappedf(prosperity,1)
	ProsperityChangeDisplay = snappedf(ProsperityChange,.01)
	prosperity = snappedf(prosperity,.0000001)
	
	SafetyChange = (((population / military) - 50) * -.01) + ((loyalty - 50) + .001) - (prosperity / 10000)
	if safety + SafetyChange >= 100:
		safety = 100
	elif safety + SafetyChange <= 0:
		safety = 0
	else:
		safety += SafetyChange
	SafetyDisplay = snappedf(safety,.1)
	SafetyChangeDisplay = snappedf(SafetyChange,.01)
	safety = snappedf(safety,.0000001)
	
	MilitaryChange = population / 100000
	military += MilitaryChange
	MilitaryDisplay = snappedf(military,1)
	MilitaryChangeDisplay = snappedf(MilitaryChange,.01)
	military = snappedf(military,.0000001)
	
	income = ((population * prosperity) / 1000) * .2
	IncomeDisplay = snappedf(income,1)
	income = snappedf(income,.0000001)
	
	expenses = (population * .1) + (prosperity * .25) + (military * 2)
	ExpensesDisplay = snappedf(expenses,1)
	expenses = snappedf(expenses,.0000001)
	
	WealthChange = income - expenses
	wealth += WealthChange
	WealthDisplay = snappedf(wealth,1)
	WealthChangeDisplay = snappedf(WealthChange,.01)
	wealth = snappedf(wealth,.0000001)
	
	CityClicked.emit(PopulationDisplay, LoyaltyDisplay, ProsperityDisplay, SafetyDisplay, MilitaryDisplay, WealthDisplay, PopulationChangeDisplay, LoyaltyChangeDisplay, ProsperityChangeDisplay, SafetyChangeDisplay, MilitaryChangeDisplay, WealthChangeDisplay)
	
	tooltip_text = "population = " + str(population) + "prosperity = " + str(prosperity) + "safety = " + str(safety) 

func _input(event: InputEventMouse):
	if (event.button_mask == MOUSE_BUTTON_MASK_LEFT) and (hovered == false):
		$CityUI.visible = false

func _on_pressed():
	$ClickCheck.start()

func _on_click_check_timeout():
	population += 1
	CityClicked.emit(PopulationDisplay, LoyaltyDisplay, ProsperityDisplay, SafetyDisplay, MilitaryDisplay, WealthDisplay, PopulationChangeDisplay, LoyaltyChangeDisplay, ProsperityChangeDisplay, SafetyChangeDisplay, MilitaryChangeDisplay, WealthChangeDisplay)
	$CityUI.visible = true

func _on_area_2d_mouse_entered():
	hovered = true
	print("true")

func _on_area_2d_mouse_exited():
	hovered = false
	print("false")
Leave a Comment