diff options
Diffstat (limited to 'data/credit.lua')
| -rw-r--r-- | data/credit.lua | 1166 |
1 files changed, 1166 insertions, 0 deletions
diff --git a/data/credit.lua b/data/credit.lua new file mode 100644 index 0000000..010ffd5 --- /dev/null +++ b/data/credit.lua @@ -0,0 +1,1166 @@ +print("Hello, world!") +-- TODO: Hide default windows when level ends / re-display when level begins + +-- Override tostring to display more info about the table +local old_tostring = tostring +local numtabs = 0 +function tostring(el) + if type(el) == "table" then + numtabs = numtabs + 1 + local strbuilder = {"{"} + for k,v in pairs(el) do + strbuilder[#strbuilder + 1] = string.format("%s%s : %s", string.rep("\t",numtabs), tostring(k), tostring(v)) + end + strbuilder[#strbuilder + 1] = "}" + numtabs = numtabs - 1 + return table.concat(strbuilder,"\n") + end + return old_tostring(el) +end + +--globals +local level = 1 +local applicants_left = -1 +local solutions = {} +local money_left = 1000000 +local unrealized_credit, unrealized_credit_label, unrealized_credit_visible = 0, false +local unrealized_credit_types, unrealized_credit_types_label, unrealized_credit_types_visible = {}, nil, false +local active_credit = {} +local cash_label, cash_label_visible = nil, false +local loan_sell_window, loan_sell_window_visible = nil, false +local active_app +local default_windows = {} + +local last_names = require("last_names") +local first_names = require("first_names") + +--functions +local intro, intro2 +local bankrupt + +local portraits = require("portraits") +local traits = require("traits") + +local function hide_default_windows(bool) + --print("About to hide default windows") + --for _,v in pairs(default_windows) do + --print("default window",v) + --v:setvisible(not bool) + --end + --print("Done hiding default windows") +end + +local function generate_loan_app() + local things_to_buy = { + { + name = "car", + cost_low = 10000, + cost_high = 100000, + repayment = -1, + }, + { + name = "house", + cost_low = 50000, + cost_high = 300000, + repayment = -1, + }, + { + name = "motorcycle", + cost_low = 5000, + cost_high = 50000, + repayment = -1, + } + } + local businesses = { + { + name = "paper company", + cost_low = 1, + cost_high = 1, + repayment = 1, + }, + { + name = "auto garage", + cost_low = 40000, + cost_high = 100000, + repayment = 1, + } + } + local collateral = { + { + name = "piece of golden jewelry", + short = "Gold", + cost_low = 1000, + cost_high = 10000 + }, + { + name = "plot of land", + short = "Land", + cost_low = 10000, + cost_high = 100000 + }, + { + name = "dog", + short = "Pet", + cost_low = 10, + cost_high = 500, + } + } + local rng = math.random() + local this_col = collateral[math.random(#collateral)] + if rng < 0.5 then + local thing = things_to_buy[math.random(#things_to_buy)] + local cost = math.random(thing.cost_low, thing.cost_high) + local ret = { + ammount = cost, + text = string.format("I want to buy a %s. I need $%d.",thing.name, cost), + repayment_time = math.random(60* math.random(5)), + collateral = { + name = this_col.name, + value = math.random(this_col.cost_low, this_col.cost_high), + short = this_col.short + }, + intrest = 0.03, + repayment = thing.repayment + } + return ret + elseif rng < 1 then + local bus = businesses[math.random(#businesses)] + local cost = math.random(bus.cost_low, bus.cost_high) + local ret = { + ammount = cost, + text = string.format("I want to start a %s. I need $%d.",bus.name, cost), + repayment_time = math.random(60* math.random(5)), + collateral = { + name = this_col.name, + value = math.random(this_col.cost_low, this_col.cost_high), + short = this_col.short + }, + intrest = 0.05, + repayment = bus.repayment + } + return ret + end +end + +local function generate_person() + local portrait_str = portraits[math.random(#portraits)] + + local random_first = first_names[math.random(#first_names)] + local random_last = last_names[math.random(#last_names)] + local random_name = string.format("%s %s",random_first,random_last) + + local trai = {} + local num_traits = 2 + math.random(2) + while #trai < num_traits do + local selected = traits[math.random(#traits)] + local has_trait_category = false + for _,v in pairs(trai) do + if selected.category == v.category then + has_trait_category = true + break + end + end + if not has_trait_category then + trai[#trai + 1] = selected + end + end + for i = 1,2 + math.random(2) do + trai[i] = traits[math.random(#traits)] + end + return { + name = random_name, + portrait_f = portrait_str, + traits = trai + } +end + +local function generate_applicant_lvl1() + local person = generate_person() + local tex = video.newtexturefromfile("../data/smol/" .. person.portrait_f) + + local win = gui.newwindow({{0,0},{480,480}}, "") + win.onClose = function() return true end + active_app = win + local portrait = gui.newiguiimage({20,40},true,tex, win) + win:settext(person.name) + local function cleanup() + applicants_left = applicants_left - 1 + win:remove() + if applicants_left > 0 then + generate_applicant_lvl1() + else + intro2() + end + end + local application = generate_loan_app() + local approve_but = gui.newbutton({{20,440},{220,460}},"Approve",win) + approve_but.onClick = function(self) + if money_left - application.ammount < 0 then + return false + end + solutions[applicants_left] = true + active_credit[#active_credit + 1] = { + loan = application, + person = person, + loan_start = get_time(), + deadline = get_time() + (application.repayment_time * 1000), + payment = (application.ammount * (1 + application.intrest)) / application.repayment_time, + will_default = false + } + money_left = money_left - application.ammount + cleanup() + end + local deny_but = gui.newbutton({{280,440},{460,460}},"Deny",win) + deny_but.onClick = function(self) + solutions[applicants_left] = false + cleanup() + end + local name_label = gui.newlabel({{180,40},{480,400}},application.text,win) + cash_label_visible = true +end + +local function generate_applicant_lvl2() + local person = generate_person() + local tex = video.newtexturefromfile("../data/smol/" .. person.portrait_f) + + local win = gui.newwindow({{0,0},{480,480}}, "") + active_app = win + win.onClose = function() return true end + local portrait = gui.newiguiimage({20,40},true,tex, win) + win:settext(person.name) + local function cleanup() + applicants_left = applicants_left - 1 + win:remove() + if applicants_left > 0 then + generate_applicant_lvl2() + else + intro3() + end + end + local application = generate_loan_app() + local approve_but = gui.newbutton({{20,440},{220,460}},"Approve",win) + print("application",application) + approve_but.onClick = function(self) + if money_left - application.ammount < 0 then + return false + end + solutions[applicants_left] = true + active_credit[#active_credit + 1] = { + loan = application, + person = person, + loan_start = get_time(), + deadline = get_time() + (application.repayment_time * 1000), + payment = (application.ammount * (1 + application.intrest)) / application.repayment_time, + } + money_left = money_left - application.ammount + cleanup() + end + local deny_but = gui.newbutton({{280,440},{460,460}},"Deny",win) + deny_but.onClick = function(self) + solutions[applicants_left] = false + cleanup() + end + print("application",application) + local application_text = string.format([[ +%s I have a %s worth $%d to put up as collateral. I can pay the loan back at %%%d intrest over %d weeks]], + application.text, + application.collateral.name, + application.collateral.value, + application.intrest * 100, + math.ceil(application.repayment_time / 60) + ) + local name_label = gui.newlabel({{180,40},{480,400}},application_text,win) + cash_label_visible = true +end + +local function generate_applicant_lvl3() + print("Generated portrait",portrait_str) + local person = generate_person() + local tex = video.newtexturefromfile("../data/smol/" .. person.portrait_f) + + local win = gui.newwindow({{0,0},{480,480}}, "") + win.onClose = function() return true end + active_app = win + local portrait = gui.newiguiimage({20,40},true,tex, win) + win:settext(person.name) + local function cleanup() + applicants_left = applicants_left - 1 + win:remove() + if applicants_left > 0 then + generate_applicant_lvl3() + else + intro4() + end + end + local application = generate_loan_app() + local approve_but = gui.newbutton({{20,440},{220,460}},"Approve",win) + print("application",application) + approve_but.onClick = function(self) + if money_left - application.ammount < 0 then + return false + end + solutions[applicants_left] = true + active_credit[#active_credit + 1] = { + loan = application, + person = person, + loan_start = get_time(), + deadline = get_time() + (application.repayment_time * 1000), + payment = (application.ammount * (1 + application.intrest)) / application.repayment_time, + } + money_left = money_left - application.ammount + cleanup() + end + local deny_but = gui.newbutton({{280,440},{460,460}},"Deny",win) + deny_but.onClick = function(self) + solutions[applicants_left] = false + cleanup() + end + local application_text = string.format([[ +%s I have a %s worth $%d to put up as collateral. I can pay the loan back at %%%d intrest over %d weeks]], + application.text, + application.collateral.name, + application.collateral.value, + application.intrest * 100, + math.ceil(application.repayment_time / 60) + ) + local name_label = gui.newlabel({{180,40},{480,400}},application_text,win) + cash_label_visible = true +end + +local function generate_applicant_lvl4() + print("Generated portrait",portrait_str) + local person = generate_person() + local tex = video.newtexturefromfile("../data/smol/" .. person.portrait_f) + + local win = gui.newwindow({{0,0},{480,480}}, "") + win.onClose = function() return true end + active_app = win + local portrait = gui.newiguiimage({20,40},true,tex, win) + win:settext(person.name) + local function cleanup() + applicants_left = applicants_left - 1 + win:remove() + if applicants_left > 0 then + generate_applicant_lvl4() + else + intro5() + end + end + local application = generate_loan_app() + local approve_but = gui.newbutton({{20,440},{220,460}},"Approve",win) + print("application",application) + approve_but.onClick = function(self) + if money_left - application.ammount < 0 then + return false + end + solutions[applicants_left] = true + active_credit[#active_credit + 1] = { + loan = application, + person = person, + loan_start = get_time(), + deadline = get_time() + (application.repayment_time * 1000), + payment = (application.ammount * (1 + application.intrest)) / application.repayment_time, + } + money_left = money_left - application.ammount + cleanup() + end + local deny_but = gui.newbutton({{280,440},{460,460}},"Deny",win) + deny_but.onClick = function(self) + solutions[applicants_left] = false + cleanup() + end + local application_text = string.format([[ +%s I have a %s worth $%d to put up as collateral. I can pay the loan back at %%%d intrest over %d weeks]], + application.text, + application.collateral.name, + application.collateral.value, + application.intrest * 100, + math.ceil(application.repayment_time / 60) + ) + local name_label = gui.newlabel({{180,20},{480,400}},application_text,win) + local traits_tbl = {} + for k,v in pairs(person.traits) do + traits_tbl[k] = string.format("* %s.",v.text) + end + local traits_label = gui.newlabel({{20,200},{480,400}},table.concat(traits_tbl,"\n"),win) + cash_label_visible = true +end + +local function generate_applicant_lvl5() + print("Generated portrait",portrait_str) + local person = generate_person() + local tex = video.newtexturefromfile("../data/smol/" .. person.portrait_f) + + local win = gui.newwindow({{0,0},{480,480}}, "") + win.onClose = function() return true end + active_app = win + local portrait = gui.newiguiimage({20,40},true,tex, win) + win:settext(person.name) + local function cleanup() + applicants_left = applicants_left - 1 + win:remove() + if applicants_left > 0 then + generate_applicant_lvl5() + else + intro6() + end + end + local application = generate_loan_app() + local approve_but = gui.newbutton({{20,440},{220,460}},"Approve",win) + print("application",application) + approve_but.onClick = function(self) + if money_left - application.ammount < 0 then + return false + end + solutions[applicants_left] = true + active_credit[#active_credit + 1] = { + loan = application, + person = person, + loan_start = get_time(), + deadline = get_time() + (application.repayment_time * 1000), + payment = (application.ammount * (1 + application.intrest)) / application.repayment_time, + repayment = application.repayment + } + money_left = money_left - application.ammount + cleanup() + end + local deny_but = gui.newbutton({{280,440},{460,460}},"Deny",win) + deny_but.onClick = function(self) + solutions[applicants_left] = false + cleanup() + end + local application_text = string.format([[ +%s I have a %s worth $%d to put up as collateral. I can pay the loan back at %%%d intrest over %d weeks]], + application.text, + application.collateral.name, + application.collateral.value, + application.intrest * 100, + math.ceil(application.repayment_time / 60) + ) + local name_label = gui.newlabel({{180,20},{480,400}},application_text,win) + local traits_tbl = {} + for k,v in pairs(person.traits) do + traits_tbl[k] = string.format("* %s.",v.text) + end + local traits_label = gui.newlabel({{20,200},{480,400}},table.concat(traits_tbl,"\n"),win) + cash_label_visible = true +end + +local function generate_applicant_lvl6() + print("Generated portrait",portrait_str) + local person = generate_person() + local tex = video.newtexturefromfile("../data/smol/" .. person.portrait_f) + + local win = gui.newwindow({{0,0},{480,480}}, "") + win.onClose = function() return true end + active_app = win + local portrait = gui.newiguiimage({20,40},true,tex, win) + win:settext(person.name) + local function cleanup() + applicants_left = applicants_left - 1 + win:remove() + if applicants_left > 0 then + generate_applicant_lvl6() + else + intro7() + end + end + local application = generate_loan_app() + local approve_but = gui.newbutton({{20,440},{220,460}},"Approve",win) + print("application",application) + approve_but.onClick = function(self) + if money_left - application.ammount < 0 then + return false + end + solutions[applicants_left] = true + active_credit[#active_credit + 1] = { + loan = application, + person = person, + loan_start = get_time(), + deadline = get_time() + (application.repayment_time * 1000), + payment = (application.ammount * (1 + application.intrest)) / application.repayment_time, + repayment = application.repayment + } + money_left = money_left - application.ammount + cleanup() + end + local deny_but = gui.newbutton({{280,440},{460,460}},"Deny",win) + deny_but.onClick = function(self) + solutions[applicants_left] = false + cleanup() + end + local application_text = string.format([[ +%s I have a %s worth $%d to put up as collateral. I can pay the loan back at %%%d intrest over %d weeks]], + application.text, + application.collateral.name, + application.collateral.value, + application.intrest * 100, + math.ceil(application.repayment_time / 60) + ) + local name_label = gui.newlabel({{180,20},{480,400}},application_text,win) + local traits_tbl = {} + for k,v in pairs(person.traits) do + traits_tbl[k] = string.format("* %s.",v.text) + end + local traits_label = gui.newlabel({{20,200},{480,400}},table.concat(traits_tbl,"\n"),win) + cash_label_visible = true +end + +local function generate_applicant_lvl7() + print("Generated portrait",portrait_str) + local person = generate_person() + local tex = video.newtexturefromfile("../data/smol/" .. person.portrait_f) + + local win = gui.newwindow({{0,0},{480,480}}, "") + win.onClose = function() return true end + active_app = win + local portrait = gui.newiguiimage({20,40},true,tex, win) + win:settext(person.name) + local function cleanup() + applicants_left = applicants_left - 1 + win:remove() + if applicants_left > 0 then + generate_applicant_lvl7() + else + intro8() + end + end + local application = generate_loan_app() + local approve_but = gui.newbutton({{20,440},{220,460}},"Approve",win) + print("application",application) + approve_but.onClick = function(self) + if money_left - application.ammount < 0 then + return false + end + solutions[applicants_left] = true + active_credit[#active_credit + 1] = { + loan = application, + person = person, + loan_start = get_time(), + deadline = get_time() + (application.repayment_time * 1000), + payment = (application.ammount * (1 + application.intrest)) / application.repayment_time, + repayment = application.repayment + } + money_left = money_left - application.ammount + cleanup() + end + local deny_but = gui.newbutton({{280,440},{460,460}},"Deny",win) + deny_but.onClick = function(self) + solutions[applicants_left] = false + cleanup() + end + local application_text = string.format([[ +%s I have a %s worth $%d to put up as collateral. I can pay the loan back at %%%d intrest over %d weeks]], + application.text, + application.collateral.name, + application.collateral.value, + application.intrest * 100, + math.ceil(application.repayment_time / 60) + ) + local name_label = gui.newlabel({{180,20},{480,400}},application_text,win) + local traits_tbl = {} + for k,v in pairs(person.traits) do + traits_tbl[k] = string.format("* %s.",v.text) + end + local traits_label = gui.newlabel({{20,200},{480,400}},table.concat(traits_tbl,"\n"),win) + cash_label_visible = true +end + +local function generate_applicant_lvl8() + print("Generated portrait",portrait_str) + local person = generate_person() + local tex = video.newtexturefromfile("../data/smol/" .. person.portrait_f) + + local win = gui.newwindow({{0,0},{480,480}}, "") + win.onClose = function() return true end + active_app = win + local portrait = gui.newiguiimage({20,40},true,tex, win) + win:settext(person.name) + local function cleanup() + applicants_left = applicants_left - 1 + win:remove() + if applicants_left > 0 then + generate_applicant_lvl7() + else + intro8() + end + end + local application = generate_loan_app() + local approve_but = gui.newbutton({{20,440},{220,460}},"Approve",win) + approve_but.onClick = function(self) + if money_left - application.ammount < 0 then + return false + end + solutions[applicants_left] = true + active_credit[#active_credit + 1] = { + loan = application, + person = person, + loan_start = get_time(), + deadline = get_time() + (application.repayment_time * 1000), + payment = (application.ammount * (1 + application.intrest)) / application.repayment_time, + repayment = application.repayment + } + money_left = money_left - application.ammount + cleanup() + end + local deny_but = gui.newbutton({{280,440},{460,460}},"Deny",win) + deny_but.onClick = function(self) + solutions[applicants_left] = false + cleanup() + end + local application_text = string.format([[ +%s I have a %s worth $%d to put up as collateral. I can pay the loan back at %%%d intrest over %d weeks]], + application.text, + application.collateral.name, + application.collateral.value, + application.intrest * 100, + math.ceil(application.repayment_time / 60) + ) + local name_label = gui.newlabel({{180,20},{480,400}},application_text,win) + local traits_tbl = {} + for k,v in pairs(person.traits) do + traits_tbl[k] = string.format("* %s.",v.text) + end + local traits_label = gui.newlabel({{20,200},{480,400}},table.concat(traits_tbl,"\n"),win) + cash_label_visible = true +end + +local function generate_applicant_lvl8() + print("Generated portrait",portrait_str) + local person = generate_person() + local tex = video.newtexturefromfile("../data/smol/" .. person.portrait_f) + + local win = gui.newwindow({{0,0},{480,480}}, "") + win.onClose = function() return true end + active_app = win + local portrait = gui.newiguiimage({20,40},true,tex, win) + win:settext(person.name) + local function cleanup() + applicants_left = applicants_left - 1 + win:remove() + if applicants_left > 0 then + generate_applicant_lvl8() + else + intro9() + end + end + local application = generate_loan_app() + local approve_but = gui.newbutton({{20,440},{220,460}},"Approve",win) + print("application",application) + approve_but.onClick = function(self) + if money_left - application.ammount < 0 then + return false + end + solutions[applicants_left] = true + active_credit[#active_credit + 1] = { + loan = application, + person = person, + loan_start = get_time(), + deadline = get_time() + (application.repayment_time * 1000), + payment = (application.ammount * (1 + application.intrest)) / application.repayment_time, + repayment = application.repayment + } + money_left = money_left - application.ammount + cleanup() + end + local deny_but = gui.newbutton({{280,440},{460,460}},"Deny",win) + deny_but.onClick = function(self) + solutions[applicants_left] = false + cleanup() + end + local application_text = string.format([[ +%s I have a %s worth $%d to put up as collateral. I can pay the loan back at %%%d intrest over %d weeks]], + application.text, + application.collateral.name, + application.collateral.value, + application.intrest * 100, + math.ceil(application.repayment_time / 60) + ) + local name_label = gui.newlabel({{180,20},{480,400}},application_text,win) + local traits_tbl = {} + for k,v in pairs(person.traits) do + traits_tbl[k] = string.format("* %s.",v.text) + end + local traits_label = gui.newlabel({{20,200},{480,400}},table.concat(traits_tbl,"\n"),win) + cash_label_visible = true +end + +local function generate_applicant_lvl9() + print("Generated portrait",portrait_str) + local person = generate_person() + local tex = video.newtexturefromfile("../data/smol/" .. person.portrait_f) + + local win = gui.newwindow({{0,0},{480,480}}, "") + win.onClose = function() return true end + active_app = win + local portrait = gui.newiguiimage({20,40},true,tex, win) + win:settext(person.name) + local function cleanup() + applicants_left = applicants_left - 1 + win:remove() + if applicants_left > 0 then + generate_applicant_lvl9() + else + intro10() + end + end + local application = generate_loan_app() + local approve_but = gui.newbutton({{20,440},{220,460}},"Approve",win) + print("application",application) + approve_but.onClick = function(self) + if money_left - application.ammount < 0 then + return false + end + solutions[applicants_left] = true + active_credit[#active_credit + 1] = { + loan = application, + person = person, + loan_start = get_time(), + deadline = get_time() + (application.repayment_time * 1000), + payment = (application.ammount * (1 + application.intrest)) / application.repayment_time, + repayment = application.repayment + } + money_left = money_left - application.ammount + cleanup() + end + local deny_but = gui.newbutton({{280,440},{460,460}},"Deny",win) + deny_but.onClick = function(self) + solutions[applicants_left] = false + cleanup() + end + local application_text = string.format([[ +%s I have a %s worth $%d to put up as collateral. I can pay the loan back at %%%d intrest over %d weeks]], + application.text, + application.collateral.name, + application.collateral.value, + application.intrest * 100, + math.ceil(application.repayment_time / 60) + ) + local name_label = gui.newlabel({{180,20},{480,400}},application_text,win) + local traits_tbl = {} + for k,v in pairs(person.traits) do + traits_tbl[k] = string.format("* %s.",v.text) + end + local traits_label = gui.newlabel({{20,200},{480,400}},table.concat(traits_tbl,"\n"),win) + cash_label_visible = true +end + +local function generate_applicant_lvl10() + print("Generated portrait",portrait_str) + local person = generate_person() + local tex = video.newtexturefromfile("../data/smol/" .. person.portrait_f) + + local win = gui.newwindow({{0,0},{480,480}}, "") + win.onClose = function() return true end + active_app = win + local portrait = gui.newiguiimage({20,40},true,tex, win) + win:settext(person.name) + local function cleanup() + applicants_left = applicants_left - 1 + win:remove() + if applicants_left > 0 then + generate_applicant_lvl10() + else + generate_applicant_lvl10() + end + end + local application = generate_loan_app() + local approve_but = gui.newbutton({{20,440},{220,460}},"Approve",win) + print("application",application) + approve_but.onClick = function(self) + if money_left - application.ammount < 0 then + return false + end + solutions[applicants_left] = true + active_credit[#active_credit + 1] = { + loan = application, + person = person, + loan_start = get_time(), + deadline = get_time() + (application.repayment_time * 1000), + payment = (application.ammount * (1 + application.intrest)) / application.repayment_time, + repayment = application.repayment + } + money_left = money_left - application.ammount + cleanup() + end + local deny_but = gui.newbutton({{280,440},{460,460}},"Deny",win) + deny_but.onClick = function(self) + solutions[applicants_left] = false + cleanup() + end + local application_text = string.format([[ +%s I have a %s worth $%d to put up as collateral. I can pay the loan back at %%%d intrest over %d weeks]], + application.text, + application.collateral.name, + application.collateral.value, + application.intrest * 100, + math.ceil(application.repayment_time / 60) + ) + local name_label = gui.newlabel({{180,20},{480,400}},application_text,win) + local traits_tbl = {} + for k,v in pairs(person.traits) do + traits_tbl[k] = string.format("* %s.",v.text) + end + local traits_label = gui.newlabel({{20,200},{480,400}},table.concat(traits_tbl,"\n"),win) + cash_label_visible = true +end + + +local last_tick = get_time() +local ogt = GAME.tick +function GAME.tick() + if cash_label then + cash_label:settext(string.format("Cash Available: $%d",money_left)) + cash_label:setvisible(cash_label_visible) + end + unrealized_credit_label:setvisible(unrealized_credit_visible) + unrealized_credit_types_label:setvisible(unrealized_credit_types_visible) + local been_a_second = false + if get_time() > last_tick + 1000 then + last_tick = get_time() + been_a_second = true + end + local unrealized_credit = 0 + unrealized_credit_types = {} + for k,loan in pairs(active_credit) do + if been_a_second then + money_left = money_left + loan.payment + end + local time_elapsed = loan.loan_start + (1000 * loan.loan.repayment_time) + local time_left = loan.deadline - get_time() + local loan_left = (time_left / 1000) * loan.payment + + unrealized_credit = unrealized_credit + loan_left + local coltype = loan.loan.collateral.short + unrealized_credit_types[coltype] = unrealized_credit_types[coltye] or 0 + unrealized_credit_types[coltype] = unrealized_credit_types[coltype] + loan_left + if loan.will_default == nil then + --people who default + local chance_to_default = 0 + local default_varience = 0 + for _,v in pairs(loan.person.traits) do + if v.payback_chance > 0 then + chance_to_default = chance_to_default + v.payback_chance + end + if v.payback_varience > 0 then + default_varience = default_varience + v.payback_varience + end + end + local num_traits = #loan.person.traits + chance_to_default = chance_to_default / num_traits + default_varience = default_varience / num_traits + if (math.random() + math.random(0,default_varience)) > chance_to_default then + print("Need a default time for", loan) + loan.will_default = true + loan.default_time = math.random(loan.loan.repayment_time * 1000) + loan.loan_start + print("Found a loan that will default at",loan.default_time) + else + loan.will_default = false + end + end + if loan.will_default and get_time() > loan.default_time then + print("defaulting on a loan, now is", get_time(), "default time is", loan.default_time) + print("loan",loan) + --Pop up a notification that the loan defaulted? + local default_win = gui.newwindow({{150,170},{490,310}},"Default!") + default_windows[#default_windows + 1] = default_win + local default_label = gui.newlabel({{0,20},{340,1000}},"",default_win) + local collateral_perc = math.random(90,100) / 100 + local collateral_collection = loan.loan.collateral.value * collateral_perc + local time_elapsed = loan.default_time - loan.loan_start + local value_collected = (time_elapsed / 1000) * loan.payment + print("value collected:",value_collected) + print("collateral collection:", collateral_collection) + local money_add = value_collected + collateral_collection + print("money to add:",money_add) + if value_collected + collateral_collection > loan.loan.ammount * (1 + loan.loan.intrest) then + + money_left = money_left + (loan.loan.ammount - value_collected) + else + money_left = money_left + money_add + end + print("After adding money, money left is", money_left) + default_label:settext(string.format("%s defaulted on their loan, we were able to collect %%%d of their collateral, a %s. We made/lost $%2.2f",loan.person.name,collateral_perc * 100, loan.loan.collateral.name,money_add)) + if money_left < 0 then + active_app:remove() + bankrupt() + end + active_credit[k] = nil + end + if get_time() > loan.deadline then + print("now is",get_time(),"and the loan deadline was", loan.deadline) + active_credit[k] = nil + end + end + if been_a_second and unrealized_credit_label then + unrealized_credit_label:settext(string.format("Unrealized cash: $%d",unrealized_credit)) + end + if been_a_second and unrealized_credit_types_label then + local ur_tbl = {} + for k,v in pairs(unrealized_credit_types) do + ur_tbl[#ur_tbl + 1] = string.format("%s: %0.2f",k,v) + end + unrealized_credit_types_label:settext(table.concat(ur_tbl,"\n")) + end +end + +local function setup_lvl1() + level = 1 + applicants_left = 10 + solutions = {} + generate_applicant_lvl1() +end + +local function setup_lvl2() + level = 2 + applicants_left = 10 + generate_applicant_lvl2() +end + +local function setup_lvl3() + level = 3 + applicants_left = 10 + generate_applicant_lvl3() +end + +local function setup_lvl4() + level = 4 + applicants_left = 10 + generate_applicant_lvl4() +end + +local function setup_lvl5() + level = 5 + applicants_left = 10 + generate_applicant_lvl5() +end + +local function setup_lvl6() + level = 6 + applicants_left = 10 + generate_applicant_lvl6() +end + +local function setup_lvl7() + level = 7 + applicants_left = 10 + generate_applicant_lvl7() +end + +local function setup_lvl8() + level = 8 + applicants_left = 10 + generate_applicant_lvl8() +end + +local function setup_lvl9() + level = 9 + applicants_left = 10 + for _,v in pairs(active_credit) do + if v.loan.collateral.name == "peice of golden jewlery" then + v.loan.collateral.value = v.loan.collateral.value * 0.1 + v.will_default = true + v.default_time = get_time() + end + end + generate_applicant_lvl9() +end + +local function setup_lvl10() + level = 10 + applicants_left = 10 + generate_applicant_lvl10() +end + +function intro() + local tex = video.newtexturefromfile("../data/lvl1_intro.png") + local introscreen = gui.newiguiimage({0,0},true,tex) + local startbutton = gui.newbutton({{250,420},{350,470}},"Start") + cash_label_visible = false + money_left = 1e6 + startbutton.onClick = function(self) + print("Start button clicked") + introscreen:remove() + startbutton:remove() + setup_lvl1() + end +end + +function bankrupt() + local tex = video.newtexturefromfile("../data/bankrupt.png") + local introscreen = gui.newiguiimage({0,0},true,tex) + local startbutton = gui.newbutton({{250,420},{350,470}},":(") + cash_label_visible = false + money_left = 1e6 + startbutton.onClick = function(self) + print("Start button clicked") + introscreen:remove() + startbutton:remove() + GAME.exit() + end +end + +function intro2() + hide_default_windows(true) + cash_label_visible = false + local tex = video.newtexturefromfile("../data/lvl2_intro.png") + local screen = gui.newiguiimage({0,0},true,tex) + local startbutton = gui.newbutton({{250,420},{350,470}},"Start") + startbutton.onClick = function(self) + print("Start button clicked") + screen:remove() + startbutton:remove() + setup_lvl2() + cash_label_visible = true + hide_default_windows(false) + end +end + +function intro3() + cash_label_visible = false + hide_default_windows(true) + local tex = video.newtexturefromfile("../data/lvl3_intro.png") + local screen = gui.newiguiimage({0,0},true,tex) + local startbutton = gui.newbutton({{250,420},{350,470}},"Start") + startbutton.onClick = function(self) + print("Start button clicked") + screen:remove() + startbutton:remove() + setup_lvl3() + cash_label_visible = true + hide_default_windows(false) + end +end + +function intro4() + hide_default_windows(true) + cash_label_visible = false + local tex = video.newtexturefromfile("../data/lvl4_intro.png") + local screen = gui.newiguiimage({0,0},true,tex) + local startbutton = gui.newbutton({{250,420},{350,470}},"Start") + startbutton.onClick = function(self) + print("Start button clicked") + screen:remove() + startbutton:remove() + setup_lvl4() + cash_label_visible = true + hide_default_windows(false) + end +end + +function intro5() + cash_label_visible = false + hide_default_windows(true) + local tex = video.newtexturefromfile("../data/lvl5_intro.png") + local screen = gui.newiguiimage({0,0},true,tex) + local startbutton = gui.newbutton({{250,420},{350,470}},"Start") + startbutton.onClick = function(self) + print("Start button clicked") + screen:remove() + startbutton:remove() + setup_lvl5() + cash_label_visible = true + hide_default_windows(false) + end +end + +function intro6() + cash_label_visible = false + hide_default_windows(true) + local tex = video.newtexturefromfile("../data/lvl6_intro.png") + local screen = gui.newiguiimage({0,0},true,tex) + local startbutton = gui.newbutton({{250,420},{350,470}},"Start") + startbutton.onClick = function(self) + print("Start button clicked") + screen:remove() + startbutton:remove() + setup_lvl6() + cash_label_visible = true + unrealized_credit_visible = true + hide_default_windows(false) + end +end + +function intro7() + cash_label_visible = false + unrealized_credit_visible = false + hide_default_windows(true) + local tex = video.newtexturefromfile("../data/lvl7_intro.png") + local screen = gui.newiguiimage({0,0},true,tex) + local startbutton = gui.newbutton({{250,420},{350,470}},"Start") + startbutton.onClick = function(self) + print("Start button clicked") + screen:remove() + startbutton:remove() + setup_lvl7() + cash_label_visible = true + unrealized_credit_visible = true + hide_default_windows(false) + end +end + +function intro8() + cash_label_visible = false + unrealized_credit_visible = false + hide_default_windows(true) + local tex = video.newtexturefromfile("../data/lvl8_intro.png") + local screen = gui.newiguiimage({0,0},true,tex) + local startbutton = gui.newbutton({{250,420},{350,470}},"Start") + startbutton.onClick = function(self) + print("Start button clicked") + screen:remove() + startbutton:remove() + setup_lvl8() + cash_label_visible = true + unrealized_credit_visible = true + unrealized_credit_types_visible = true + hide_default_windows(false) + end +end + +function intro9() + cash_label_visible = false + unrealized_credit_visible = false + unrealized_credit_types_visible = false + hide_default_windows(true) + local tex = video.newtexturefromfile("../data/lvl9_intro.png") + local screen = gui.newiguiimage({0,0},true,tex) + local startbutton = gui.newbutton({{250,420},{350,470}},"Start") + startbutton.onClick = function(self) + print("Start button clicked") + screen:remove() + startbutton:remove() + setup_lvl9() + cash_label_visible = true + unrealized_credit_visible = true + unrealized_credit_types_visible = true + hide_default_windows(false) + end +end + +function intro10() + cash_label_visible = false + unrealized_credit_visible = false + unrealized_credit_types_visible = false + hide_default_windows(true) + local tex = video.newtexturefromfile("../data/lvlfinal_intro.png") + local screen = gui.newiguiimage({0,0},true,tex) + local startbutton = gui.newbutton({{250,420},{350,470}},"Start") + startbutton.onClick = function(self) + print("Start button clicked") + screen:remove() + startbutton:remove() + setup_lvl10() + cash_label_visible = true + unrealized_credit_visible = true + unrealized_credit_types_visible = true + hide_default_windows(false) + end +end + +cash_label = gui.newlabel({{480,0},{640,100}},"") +unrealized_credit_label = gui.newlabel({{480,100},{640,200}},"") +unrealized_credit_types_label = gui.newlabel({{480,200},{640,300}}, "") +intro3() +--generate_applicant_lvl1() + |
