# Tradenode and Price based Trading System # By KJH # This system is a set of scripts that work together to, # 1. Take supply and demand as input, # 2. Calculate local price of a tradenode # 3. Calculate export and import between tradenodes based on price difference # 4. Return resulting trade income, production income, and demand fulfillment to provinces # Check TN_Init and TN_CalcMain at the bottom to see the general flow # Inputs: # id = name of the variable whose value indicates the province id of tradenode center being searched for # return = event target scope that contains tradenode center that was being searched for # It checks for a tradenode center whose id is equal to the id input parameter then returns that province as event target TN_GetNode = { set_variable = { which = TN_GetNodeCheck which = $id$ } tradenode_centers = { limit = { NOT = { province_id = PREV } } set_variable = { which = TN_GetNodeCheck which = PREV } if = { limit = { is_variable_equal = { which = TN_GetNodeCheck which = prov_id } } save_event_target_as = $return$ } set_variable = { which = TN_GetNodeCheck value = 0 } } set_variable = { which = TN_GetNodeCheck value = 0 } } # Inputs: # type = type of the produce whose value increase per distance is being calculated # return = amount of value increase per distance # Return the the amount of value increase per distance depending on type of produce TN_GetValDist = { set_province_flag = TN_GetValDistCheck$type$ trigger_switch = { on_trigger = has_province_flag TN_GetValDistCheckRP = { set_variable = { which = $return$ value = 0.05 } } TN_GetValDistCheckUL = { set_variable = { which = $return$ value = 0.2 } } } clr_province_flag = TN_GetValDistCheck$type$ } # Intput parameters: # node = the other node the current node is trading with # type = type of the good being traded # return = finished multiplier which represents the amount of value increase # Calculate value of a good increasing by distance TN_GetValueIncrease = { POP_GetDist = { targ1 = THIS targ2 = $node$ x_coord = TN_CoordX y_coord = TN_CoordY return = $return$ } TN_GetValDist = { type = $type$ return = TN_GetValueIncreaseMult } multiply_variable = { which = $return$ which = TN_GetValueIncreaseMult } divide_variable = { which = $return$ value = 1000 } change_variable = { which = $return$ value = 1 } set_variable = { which = TN_GetValueIncreaseMult value = 0 } } # Set tradenode outward links TN_InitLink = { 867 = { set_variable = { which = TN_Link0 value = 2801 } } 867 = { set_variable = { which = TN_Link1 value = 843 } } 867 = { set_variable = { which = TN_Link2 value = 1464 } } 513 = { set_variable = { which = TN_Link0 value = 784 } } 513 = { set_variable = { which = TN_Link1 value = 650 } } 650 = { set_variable = { which = TN_Link0 value = 624 } } 2801 = { set_variable = { which = TN_Link0 value = 697 } } 2801 = { set_variable = { which = TN_Link1 value = 715 } } 2801 = { set_variable = { which = TN_Link2 value = 1019 } } 715 = { set_variable = { which = TN_Link0 value = 697 } } 715 = { set_variable = { which = TN_Link1 value = 2442 } } 680 = { set_variable = { which = TN_Link0 value = 662 } } 680 = { set_variable = { which = TN_Link1 value = 660 } } 660 = { set_variable = { which = TN_Link0 value = 2442 } } 660 = { set_variable = { which = TN_Link1 value = 508 } } 784 = { set_variable = { which = TN_Link0 value = 771 } } 784 = { set_variable = { which = TN_Link1 value = 3506 } } 771 = { set_variable = { which = TN_Link0 value = 742 } } 697 = { set_variable = { which = TN_Link0 value = 877 } } 662 = { set_variable = { which = TN_Link0 value = 651 } } 1019 = { set_variable = { which = TN_Link0 value = 877 } } 843 = { set_variable = { which = TN_Link0 value = 902 } } 843 = { set_variable = { which = TN_Link1 value = 481 } } 843 = { set_variable = { which = TN_Link2 value = 877 } } 877 = { set_variable = { which = TN_Link0 value = 651 } } 2442 = { set_variable = { which = TN_Link0 value = 295 } } 2442 = { set_variable = { which = TN_Link1 value = 551 } } 651 = { set_variable = { which = TN_Link0 value = 3506 } } 651 = { set_variable = { which = TN_Link1 value = 4048 } } 3506 = { set_variable = { which = TN_Link0 value = 481 } } 408 = { set_variable = { which = TN_Link0 value = 4048 } } 4048 = { set_variable = { which = TN_Link0 value = 624 } } 4048 = { set_variable = { which = TN_Link1 value = 661 } } 624 = { set_variable = { which = TN_Link0 value = 1100 } } 661 = { set_variable = { which = TN_Link0 value = 561 } } 510 = { set_variable = { which = TN_Link0 value = 503 } } 510 = { set_variable = { which = TN_Link1 value = 561 } } 510 = { set_variable = { which = TN_Link2 value = 508 } } 508 = { set_variable = { which = TN_Link0 value = 551 } } 508 = { set_variable = { which = TN_Link1 value = 503 } } 556 = { set_variable = { which = TN_Link0 value = 421 } } 556 = { set_variable = { which = TN_Link1 value = 561 } } 421 = { set_variable = { which = TN_Link0 value = 527 } } 503 = { set_variable = { which = TN_Link0 value = 527 } } 503 = { set_variable = { which = TN_Link1 value = 430 } } 527 = { set_variable = { which = TN_Link0 value = 1100 } } 527 = { set_variable = { which = TN_Link1 value = 388 } } 5160 = { set_variable = { which = TN_Link0 value = 1132 } } 5160 = { set_variable = { which = TN_Link1 value = 388 } } 5160 = { set_variable = { which = TN_Link2 value = 1136 } } 388 = { set_variable = { which = TN_Link0 value = 356 } } 388 = { set_variable = { which = TN_Link1 value = 1100 } } 388 = { set_variable = { which = TN_Link2 value = 430 } } 1136 = { set_variable = { which = TN_Link0 value = 1100 } } 1136 = { set_variable = { which = TN_Link1 value = 1098 } } 1100 = { set_variable = { which = TN_Link0 value = 1160 } } 1160 = { set_variable = { which = TN_Link0 value = 742 } } 1160 = { set_variable = { which = TN_Link1 value = 1098 } } 742 = { set_variable = { which = TN_Link0 value = 1110 } } 742 = { set_variable = { which = TN_Link1 value = 3370 } } 1098 = { set_variable = { which = TN_Link0 value = 1110 } } 1110 = { set_variable = { which = TN_Link0 value = 342 } } 1110 = { set_variable = { which = TN_Link1 value = 1132 } } 1110 = { set_variable = { which = TN_Link2 value = 1381 } } 1132 = { set_variable = { which = TN_Link0 value = 356 } } 342 = { set_variable = { which = TN_Link0 value = 334 } } 551 = { set_variable = { which = TN_Link0 value = 1009 } } 430 = { set_variable = { which = TN_Link0 value = 1009 } } 430 = { set_variable = { which = TN_Link1 value = 392 } } 392 = { set_variable = { which = TN_Link0 value = 1424 } } 392 = { set_variable = { which = TN_Link1 value = 356 } } 334 = { set_variable = { which = TN_Link0 value = 1323 } } 334 = { set_variable = { which = TN_Link1 value = 339 } } 356 = { set_variable = { which = TN_Link0 value = 105 } } 356 = { set_variable = { which = TN_Link1 value = 339 } } 356 = { set_variable = { which = TN_Link2 value = 1424 } } 339 = { set_variable = { which = TN_Link0 value = 68 } } 1009 = { set_variable = { which = TN_Link0 value = 1427 } } 295 = { set_variable = { which = TN_Link0 value = 1 } } 295 = { set_variable = { which = TN_Link1 value = 261 } } 261 = { set_variable = { which = TN_Link0 value = 254 } } 261 = { set_variable = { which = TN_Link1 value = 1427 } } 1427 = { set_variable = { which = TN_Link0 value = 1424 } } 1464 = { set_variable = { which = TN_Link0 value = 908 } } 1464 = { set_variable = { which = TN_Link1 value = 902 } } 902 = { set_variable = { which = TN_Link0 value = 890 } } 902 = { set_variable = { which = TN_Link1 value = 904 } } 902 = { set_variable = { which = TN_Link2 value = 481 } } 908 = { set_variable = { which = TN_Link0 value = 890 } } 890 = { set_variable = { which = TN_Link0 value = 12 } } 890 = { set_variable = { which = TN_Link1 value = 916 } } 904 = { set_variable = { which = TN_Link0 value = 916 } } 904 = { set_variable = { which = TN_Link1 value = 481 } } 481 = { set_variable = { which = TN_Link0 value = 3370 } } 481 = { set_variable = { which = TN_Link1 value = 1381 } } 916 = { set_variable = { which = TN_Link0 value = 1381 } } 254 = { set_variable = { which = TN_Link0 value = 38 } } 254 = { set_variable = { which = TN_Link1 value = 60 } } 129 = { set_variable = { which = TN_Link0 value = 60 } } 129 = { set_variable = { which = TN_Link1 value = 1424 } } 1424 = { set_variable = { which = TN_Link0 value = 105 } } 1424 = { set_variable = { which = TN_Link1 value = 68 } } 60 = { set_variable = { which = TN_Link0 value = 105 } } 60 = { set_variable = { which = TN_Link1 value = 52 } } 52 = { set_variable = { which = TN_Link0 value = 56 } } 3370 = { set_variable = { which = TN_Link0 value = 68 } } 56 = { set_variable = { which = TN_Link0 value = 199 } } 56 = { set_variable = { which = TN_Link1 value = 44 } } 1323 = { set_variable = { which = TN_Link0 value = 68 } } 1323 = { set_variable = { which = TN_Link1 value = 199 } } 199 = { set_variable = { which = TN_Link0 value = 1381 } } 1 = { set_variable = { which = TN_Link0 value = 12 } } 38 = { set_variable = { which = TN_Link0 value = 12 } } 38 = { set_variable = { which = TN_Link1 value = 44 } } 12 = { set_variable = { which = TN_Link0 value = 44 } } } # Inputs: # ind = index of the link # It is a helper function that checks a given link of a node and set a corresponding link in the opposite side of the link TN_InitLinkPlusHelper = { if = { limit = { check_variable = { which = TN_Link$ind$ value = 1 } NOT = { has_province_flag = TN_Link$ind$Block } } TN_GetNode = { id = TN_Link$ind$ return = TN_InitLinkPlusHelperNode } set_variable = { which = TN_InitLinkPlusHelperInformSend which = prov_id } event_target:TN_InitLinkPlusHelperNode = { set_variable = { which = TN_InitLinkPlusHelperInformSend which = PREV } # Failsafe if = { limit = { NOT = { is_variable_equal = { which = TN_Link0 which = TN_InitLinkPlusHelperInformSend } is_variable_equal = { which = TN_Link1 which = TN_InitLinkPlusHelperInformSend } is_variable_equal = { which = TN_Link2 which = TN_InitLinkPlusHelperInformSend } is_variable_equal = { which = TN_Link3 which = TN_InitLinkPlusHelperInformSend } is_variable_equal = { which = TN_Link4 which = TN_InitLinkPlusHelperInformSend } is_variable_equal = { which = TN_Link5 which = TN_InitLinkPlusHelperInformSend } is_variable_equal = { which = TN_Link6 which = TN_InitLinkPlusHelperInformSend } is_variable_equal = { which = TN_Link7 which = TN_InitLinkPlusHelperInformSend } is_variable_equal = { which = TN_Link8 which = TN_InitLinkPlusHelperInformSend } } } if = { limit = { NOT = { check_variable = { which = TN_Link0 value = 1 } } } set_variable = { which = TN_Link0 which = TN_InitLinkPlusHelperInformSend } set_province_flag = TN_Link0Block } else_if = { limit = { NOT = { check_variable = { which = TN_Link1 value = 1 } } } set_variable = { which = TN_Link1 which = TN_InitLinkPlusHelperInformSend } set_province_flag = TN_Link1Block } else_if = { limit = { NOT = { check_variable = { which = TN_Link2 value = 1 } } } set_variable = { which = TN_Link2 which = TN_InitLinkPlusHelperInformSend } set_province_flag = TN_Link2Block } else_if = { limit = { NOT = { check_variable = { which = TN_Link3 value = 1 } } } set_variable = { which = TN_Link3 which = TN_InitLinkPlusHelperInformSend } set_province_flag = TN_Link3Block } else_if = { limit = { NOT = { check_variable = { which = TN_Link4 value = 1 } } } set_variable = { which = TN_Link4 which = TN_InitLinkPlusHelperInformSend } set_province_flag = TN_Link4Block } else_if = { limit = { NOT = { check_variable = { which = TN_Link5 value = 1 } } } set_variable = { which = TN_Link5 which = TN_InitLinkPlusHelperInformSend } set_province_flag = TN_Link5Block } else_if = { limit = { NOT = { check_variable = { which = TN_Link6 value = 1 } } } set_variable = { which = TN_Link6 which = TN_InitLinkPlusHelperInformSend } set_province_flag = TN_Link6Block } else_if = { limit = { NOT = { check_variable = { which = TN_Link7 value = 1 } } } set_variable = { which = TN_Link7 which = TN_InitLinkPlusHelperInformSend } set_province_flag = TN_Link7Block } else_if = { limit = { NOT = { check_variable = { which = TN_Link8 value = 1 } } } set_variable = { which = TN_Link8 which = TN_InitLinkPlusHelperInformSend } set_province_flag = TN_Link8Block } } set_variable = { which = TN_InitLinkPlusHelperInformSend value = 0 } } set_variable = { which = TN_InitLinkPlusHelperInformSend value = 0 } } } # It is a script that sets corresponding tradenode links to the opposite side of a link TN_InitLinkPlus = { tradenode_centers = { TN_InitLinkPlusHelper = { ind = 0 } TN_InitLinkPlusHelper = { ind = 1 } TN_InitLinkPlusHelper = { ind = 2 } TN_InitLinkPlusHelper = { ind = 3 } TN_InitLinkPlusHelper = { ind = 4 } TN_InitLinkPlusHelper = { ind = 5 } TN_InitLinkPlusHelper = { ind = 6 } TN_InitLinkPlusHelper = { ind = 7 } TN_InitLinkPlusHelper = { ind = 8 } } tradenode_centers = { clr_province_flag = TN_Link0Block clr_province_flag = TN_Link1Block clr_province_flag = TN_Link2Block clr_province_flag = TN_Link3Block clr_province_flag = TN_Link4Block clr_province_flag = TN_Link5Block clr_province_flag = TN_Link6Block clr_province_flag = TN_Link7Block clr_province_flag = TN_Link8Block } } # It is a script that calculates the average coordinates of tradenodes, which is then saved in tradenode center TN_InitCoord = { every_province = { set_variable = { which = TN_CoordX which = x_coord } set_variable = { which = TN_CoordY which = y_coord } divide_variable = { which = TN_CoordX value = 1000 } divide_variable = { which = TN_CoordY value = 1000 } } tradenode_centers = { set_variable = { which = TN_Num value = 0.001 } TN_effect = { effect = TN_effect2 } } every_province = { if = { limit = { has_province_flag = TN_Cent } divide_variable = { which = TN_CoordX which = TN_Num } divide_variable = { which = TN_CoordY which = TN_Num } set_variable = { which = TN_Num value = 0 } } else = { set_variable = { which = TN_CoordX value = 0 } set_variable = { which = TN_CoordY value = 0 } } } } # Input: # ind = index of a link being assessed # It is a script that checks the current node's index link and see if that link is open TN_CheckLink = { if = { limit = { check_variable = { which = TN_Link$ind$ value = 1 } } save_event_target_as = TN_CheckLinkTarg1 TN_GetNode = { id = TN_Link$ind$ return = TN_CheckLinkTarg2 } if = { limit = { OR = { # A country has 24% trade share in both any_country = { TN_CheckLinkTrig = { node1 = event_target:TN_CheckLinkTarg1 node2 = event_target:TN_CheckLinkTarg2 share = 12 } } # One country has 16% trade share in both while another has 8% in both AND = { any_country = { TN_CheckLinkTrig = { node1 = event_target:TN_CheckLinkTarg1 node2 = event_target:TN_CheckLinkTarg2 share = 8 } any_country = { NOT = { tag = PREV } TN_CheckLinkTrig = { node1 = event_target:TN_CheckLinkTarg1 node2 = event_target:TN_CheckLinkTarg2 share = 4 } } } } # 3 or more countries have 8% trade share in both calc_true_if = { all_country = { TN_CheckLinkTrig = { node1 = event_target:TN_CheckLinkTarg1 node2 = event_target:TN_CheckLinkTarg2 share = 4 } } amount = 3 } } NOT = { has_province_flag = TN_Link$ind$Open } } set_province_flag = TN_Link$ind$Open } else_if = { limit = { has_province_flag = TN_Link$ind$Open } clr_province_flag = TN_Link$ind$Open set_variable = { which = TN_Link$ind$RPExport value = 0 } set_variable = { which = TN_Link$ind$RPImport value = 0 } set_variable = { which = TN_Link$ind$ULExport value = 0 } set_variable = { which = TN_Link$ind$ULImport value = 0 } } } } # Inputs: # supply, demand = variable name that stores supply and demand values of tradenode member provinces # returnSupply, returnDemand = Total summed supply and demand that gets saved in tradenode center # It collects supply and demand values from tradenode member provinces then aggregate them in tradenode center TN_GetSupplyDemand = { # Initialize temporary variables every_province = { set_variable = { which = TN_GetSupplyDemandSupply which = $supply$ } set_variable = { which = TN_GetSupplyDemandDemand which = $demand$ } } # Use POP_Centers to sum up the variables tradenode_centers = { TN_effect = { effect = TN_effect1 } } # Tally up tradenode_centers = { set_variable = { which = $returnSupply$ which = TN_GetSupplyDemandSupply } set_variable = { which = $returnDemand$ which = TN_GetSupplyDemandDemand } TN_effect = { effect = TN_effect5 } } every_province = { set_variable = { which = $share$ which = TN_GetSupplyDemandSupply } set_variable = { which = TN_GetSupplyDemandSupply value = 0 } set_variable = { which = TN_GetSupplyDemandDemand value = 0 } } } # Inputs: # ind = index of a link # type = type of a produce # return = a variable name that aggregates total import # It is a helper script that assesses the import of a type produce at ind link then add that to return variable TN_GetImport = { if = { limit = { check_variable = { which = TN_Link$ind$ value = 1 } has_province_flag = TN_Link$ind$Open check_variable = { which = TN_Link$ind$$type$Import value = 0.001 } } TN_GetNode = { id = TN_Link$ind$ return = TN_GetImportNode } TN_GetValueIncrease = { node = TN_GetImportNode type = $type$ return = TN_GetImportVal } multiply_variable = { which = TN_GetImportVal which = TN_Link$ind$$type$Import } change_variable = { which = $return$ which = TN_GetImportVal } set_variable = { which = TN_GetImportVal value = 0 } } } # Inputs: # ind = index of a link # type = type of a produce # return = a variable name that aggregates total export # It is a helper script that assesses the export of a type produce at ind link then add that to return variable TN_GetExport = { if = { limit = { check_variable = { which = TN_Link$ind$ value = 1 } has_province_flag = TN_Link$ind$Open check_variable = { which = TN_Link$ind$$type$Export value = 0.001 } } change_variable = { which = $return$ which = TN_Link$ind$$type$Export } } } # Inputs: # type = type of produce # return = total import of tradenode # It aggregates the total type of typeProduce produce in a given node then saves it in return variable TN_GetImportExport = { set_variable = { which = $return$ value = 0 } TN_Get$type$ = { ind = 0 type = $typeProduce$ return = $return$ } TN_Get$type$ = { ind = 1 type = $typeProduce$ return = $return$ } TN_Get$type$ = { ind = 2 type = $typeProduce$ return = $return$ } TN_Get$type$ = { ind = 3 type = $typeProduce$ return = $return$ } TN_Get$type$ = { ind = 4 type = $typeProduce$ return = $return$ } TN_Get$type$ = { ind = 5 type = $typeProduce$ return = $return$ } TN_Get$type$ = { ind = 6 type = $typeProduce$ return = $return$ } TN_Get$type$ = { ind = 7 type = $typeProduce$ return = $return$ } TN_Get$type$ = { ind = 8 type = $typeProduce$ return = $return$ } } # Inputs: # type = type of the produce # demand = name of the variable whose value represents total tradenode demand # suppply = name of the variable whose value represents total tradenode supply # It calculates local tradenode price based on demand, supply, import and export TN_GetPrice = { TN_GetImportExport = { type = Import typeProduce = $type$ return = TN_GetPriceImport } TN_GetImportExport = { type = Export typeProduce = $type$ return = TN_GetPriceExport } set_variable = { which = TN_Price$type$ which = $demand$ } set_variable = { which = TN_GetPriceDiv which = $supply$ } change_variable = { which = TN_GetPriceDiv which = TN_GetPriceImport } subtract_variable = { which = TN_GetPriceDiv which = TN_GetPriceExport } change_variable = { which = TN_GetPriceDiv which = TN_Surp$type$ } divide_variable = { which = TN_Price$type$ which = TN_GetPriceDiv } set_variable = { which = TN_GetPriceDiv value = 0 } set_variable = { which = TN_GetPriceImport value = 0 } set_variable = { which = TN_GetPriceExport value = 0 } } # Inputs: # ind = index of the link # type = type of produce # A helper script that sets export variable from calculated import variable to a correct link TN_CalcImportHelperHelper = { if = { limit = { is_variable_equal = { which = TN_CalcImportHelperInformSend2 which = TN_Link$ind$ } } set_variable = { which = TN_Link$ind$$type$Export which = TN_CalcImportHelperInformSend1 } } } # Inputs: # type = type of produce # ind = index of node1's link with node2 # supply = variable whose value represents total tradenode supply # demand = variable whose value represents total tradenode demand # Calculates change in import of the current node to the node connected through Link$ind$ # based on price differences, infra, and value increase per distance TN_CalcImportHelper = { if = { limit = { check_variable = { which = TN_Link$ind$ value = 1 } has_province_flag = TN_Link$ind$Open } # Set event targets save_event_target_as = TN_CalcImportHelperNode1 # Import node TN_GetNode = { id = TN_Link$ind$ return = TN_CalcImportHelperNode2 # Export node } # Main code set_variable = { which = TN_CalcImportHelperPrice which = TN_Price$type$ } # Apply infrastructure effects subtract_variable = { which = TN_CalcImportHelperPrice which = TN_Link$ind$$type$Infra } set_variable = { which = TN_CalcImportHelperInformSend which = TN_Link$ind$$type$Infra } event_target:TN_CalcImportHelperNode2 = { set_variable = { which = TN_CalcImportHelperInformSend which = PREV } set_variable = { which = TN_CalcImportHelperPrice which = TN_Price$type$ } change_variable = { which = TN_CalcImportHelperPrice which = TN_CalcImportHelperInformSend } # Effect of increase in value due to distance # Since they get more value per price, price is effectively decreased TN_GetValueIncrease = { node = event_target:TN_CalcImportHelperNode1 type = $type$ return = TN_CalcImportHelperDiv } divide_variable = { which = TN_CalcImportHelperPrice which = TN_CalcImportHelperDiv } # Send total supply to node1 for determining size of trade change TN_GetImportExport = { type = Import typeProduce = $type$ return = TN_CalcImportHelperInformSend } change_variable = { which = TN_CalcImportHelperInformSend which = $supply$ } PREV = { set_variable = { which = TN_CalcImportHelperInformSend which = PREV } } set_variable = { which = TN_CalcImportHelperInformSend value = 0 } set_variable = { which = TN_CalcImportHelperDiv value = 0 } } # Calculate Change divide_variable = { which = TN_CalcImportHelperPrice which = event_target:TN_CalcImportHelperNode2 } subtract_variable = { which = TN_CalcImportHelperPrice value = 1 } TN_GetImportExport = { type = Export typeProduce = $type$ return = TN_CalcImportHelperChange } change_variable = { which = TN_CalcImportHelperChange which = TN_CalcImportHelperInformSend } change_variable = { which = TN_CalcImportHelperChange which = $demand$ } multiply_variable = { which = TN_CalcImportHelperChange which = TN_CalcImportHelperPrice } multiply_variable = { which = TN_CalcImportHelperChange value = 0.01 } change_variable = { which = TN_Link$ind$$type$Import which = TN_CalcImportHelperChange } # Import can never be negative if = { limit = { NOT = { check_variable = { which = TN_Link$ind$$type$Import value = 0 } } } set_variable = { which = TN_Link$ind$$type$Import value = 0 } } # Set to the linked node a value opposite to the amount just set set_variable = { which = TN_CalcImportHelperInformSend1 which = TN_Link$ind$$type$Import } set_variable = { which = TN_CalcImportHelperInformSend2 which = prov_id } event_target:TN_CalcImportHelperNode2 = { set_variable = { which = TN_CalcImportHelperInformSend1 which = PREV } set_variable = { which = TN_CalcImportHelperInformSend2 which = PREV } TN_CalcImportHelperHelper = { ind = 0 type = $type$ } TN_CalcImportHelperHelper = { ind = 1 type = $type$ } TN_CalcImportHelperHelper = { ind = 2 type = $type$ } TN_CalcImportHelperHelper = { ind = 3 type = $type$ } TN_CalcImportHelperHelper = { ind = 4 type = $type$ } TN_CalcImportHelperHelper = { ind = 5 type = $type$ } TN_CalcImportHelperHelper = { ind = 6 type = $type$ } TN_CalcImportHelperHelper = { ind = 7 type = $type$ } TN_CalcImportHelperHelper = { ind = 8 type = $type$ } set_variable = { which = TN_CalcImportHelperInformSend1 value = 0 } set_variable = { which = TN_CalcImportHelperInformSend2 value = 0 } set_variable = { which = TN_CalcImportHelperPrice value = 0 } } set_variable = { which = TN_CalcImportHelperInformSend value = 0 } set_variable = { which = TN_CalcImportHelperInformSend1 value = 0 } set_variable = { which = TN_CalcImportHelperInformSend2 value = 0 } set_variable = { which = TN_CalcImportHelperPrice value = 0 } set_variable = { which = TN_CalcImportHelperChange value = 0 } } } # What it does: # It calculates change in import with every open link # Read comments for TN_CalcImportHelper above for more detail TN_CalcImport = { TN_CalcImportHelper = { ind = 0 type = $type$ demand = $demand$ supply = $supply$ } TN_CalcImportHelper = { ind = 1 type = $type$ demand = $demand$ supply = $supply$ } TN_CalcImportHelper = { ind = 2 type = $type$ demand = $demand$ supply = $supply$ } TN_CalcImportHelper = { ind = 3 type = $type$ demand = $demand$ supply = $supply$ } TN_CalcImportHelper = { ind = 4 type = $type$ demand = $demand$ supply = $supply$ } TN_CalcImportHelper = { ind = 5 type = $type$ demand = $demand$ supply = $supply$ } TN_CalcImportHelper = { ind = 6 type = $type$ demand = $demand$ supply = $supply$ } TN_CalcImportHelper = { ind = 7 type = $type$ demand = $demand$ supply = $supply$ } TN_CalcImportHelper = { ind = 8 type = $type$ demand = $demand$ supply = $supply$ } } # Inputs: # ind = index of a link # type = type of produce # It calculates change in wealth of tradenode due to import and export TN_CalcWealthTradeHelper = { if = { limit = { check_variable = { which = TN_Link$ind$ value = 1 } has_province_flag = TN_Link$ind$Open } # Loss of wealth through import if = { limit = { check_variable = { which = TN_Link$ind$$type$Import value = 0.001 } } TN_GetNode = { id = TN_Link$ind$ return = TN_CalcWealthTradeNode } event_target:TN_CalcWealthTradeNode = { set_variable = { which = TN_CalcWealthTradeImport which = TN_Price$type$ } PREV = { set_variable = { which = TN_CalcWealthTradeImport which = PREV } } set_variable = { which = TN_CalcWealthTradeImport value = 0 } } change_variable = { which = TN_CalcWealthTradeImport which = TN_Link$ind$$type$Infra } multiply_variable = { which = TN_CalcWealthTradeImport which = TN_Link$ind$$type$Import } # Merchants actually buy things a bit cheaper than price multiply_variable = { which = TN_CalcWealthTradeImport value = 0.9 } subtract_variable = { which = TN_Wealth$type$ which = TN_CalcWealthTradeImport } set_variable = { which = TN_CalcWealthTradeImport value = 0 } } # Addition of wealth through export if = { limit = { check_variable = { which = TN_Link$ind$$type$Export value = 0.001 } } set_variable = { which = TN_CalcWealthTradeExport which = TN_Price$type$ } subtract_variable = { which = TN_CalcWealthTradeExport which = TN_Link$ind$$type$Infra } multiply_variable = { which = TN_CalcWealthTradeExport which = TN_Link$ind$$type$Export } # Merchants actually sell things a bit expensive than price divide_variable = { which = TN_CalcWealthTradeExport value = 0.9 } change_variable = { which = TN_Wealth$type$ which = TN_CalcWealthTradeExport } set_variable = { which = TN_CalcWealthTradeExport value = 0 } } } } # Input: # type = type of produce # Calls TN_CalcWealthTradeHelper for all the links TN_CalcWealthTrade = { TN_CalcWealthTradeHelper = { ind = 0 type = $type$ } TN_CalcWealthTradeHelper = { ind = 1 type = $type$ } TN_CalcWealthTradeHelper = { ind = 2 type = $type$ } TN_CalcWealthTradeHelper = { ind = 3 type = $type$ } TN_CalcWealthTradeHelper = { ind = 4 type = $type$ } TN_CalcWealthTradeHelper = { ind = 5 type = $type$ } TN_CalcWealthTradeHelper = { ind = 6 type = $type$ } TN_CalcWealthTradeHelper = { ind = 7 type = $type$ } TN_CalcWealthTradeHelper = { ind = 8 type = $type$ } } # Inputs: # type = type of produce # demand = variable that stores total demand of a node # supply = variable that stores total supply of a node # return = amount purchased from local producers by a tradenode # It calculates how much produce the tradenode purchased from local producers TN_GetAmountBought = { TN_GetImportExport = { type = Import typeProduce = $type$ return = TN_GetAmountBoughtImport } TN_GetImportExport = { type = Export typeProduce = $type$ return = TN_GetAmountBoughtExport } set_variable = { which = $return$ which = $demand$ } change_variable = { which = $return$ which = TN_GetAmountBoughtExport } subtract_variable = { which = $return$ which = TN_GetAmountBoughtImport } subtract_variable = { which = $return$ which = TN_Surp$type$ } # Merchants can't buy more than what is produced if = { limit = { check_variable = { which = $return$ which = $supply$ } } set_variable = { which = $return$ which = $supply$ } } change_variable = { which = $return$ which = TN_Surp$type$ } set_variable = { which = TN_GetAmountBoughtImport value = 0 } set_variable = { which = TN_GetAmountBoughtExport value = 0 } } # Inputs: # type = type of produce # demand = variable that stores total demand of a node # supply = variable that stores total supply of a node # It calculates change in wealth of a tradnoede due to internal trade TN_CalcWealthSelf = { # Amount purchased by merchants TN_GetAmountBought = { type = $type$ demand = $demand$ supply = $supply$ return = TN_CalcWealthSelfBought } # Amount sold by merchants set_variable = { which = TN_CalcWealthSelfSold which = $demand$ } # Merchants profit multiply_variable = { which = TN_CalcWealthSelfBought value = 0.9 } divide_variable = { which = TN_CalcWealthSelfSold value = 0.9 } # Price multiply_variable = { which = TN_CalcWealthSelfBought which = TN_Price$type$ } multiply_variable = { which = TN_CalcWealthSelfSold which = TN_Price$type$ } subtract_variable = { which = TN_Wealth$type$ which = TN_CalcWealthSelfBought } change_variable = { which = TN_Wealth$type$ which = TN_CalcWealthSelfSold } set_variable = { which = TN_CalcWealthSelfBought value = 0 } set_variable = { which = TN_CalcWealthSelfSold value = 0 } } # Inputs: # type = type of produce # demand = variable that stores total demand of a node # supply = variable that stores total supply of a node # It calculates new tradenode wealth from supply, demand, import and export TN_CalcWealth = { set_variable = { which = TN_Wealth$type$ value = 0 } TN_CalcWealthTrade = { type = $type$ } TN_CalcWealthSelf = { type = $type$ demand = $demand$ supply = $supply$ } } # It checks calculated tradenode wealth and assigns corresponding tradenode value to the tradenode TN_SetTradeIncome = { set_variable = { which = TN_SetTradeIncomeInp which = TN_WealthRP } change_variable = { which = TN_SetTradeIncomeInp which = TN_WealthUL } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 819.2 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 409.6 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 204.8 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 102.4 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 51.2 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 25.6 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 12.8 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 6.4 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 3.2 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 1.6 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 0.8 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 0.4 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 0.2 } POP_SetMod = { varname = TN_SetTradeIncomeInp modname = TN_TradeVal type = province value = 0.1 } } # Input: # type = type of produce # demand = total tradenode demand of a produce # supply = total tradenode supply of a produce # This script calculates change in produce surplus TN_CalcSurplus = { # How much has been bought TN_GetAmountBought = { type = $type$ demand = $demand$ supply = $supply$ return = TN_CalcSurplusBought } # Surplus diminishes over time multiply_variable = { which = TN_Surp$type$ value = 0.9 } # Change in surplus change_variable = { which = TN_Surp$type$ which = $supply$ } subtract_variable = { which = TN_Surp$type$ which = TN_CalcSurplusBought } # Surplus can never be negative if = { limit = { NOT = { check_variable = { which = TN_Surp$type$ value = 0 } } } set_variable = { which = TN_Surp$type$ value = 0 } } set_variable = { which = TN_CalcSurplusBought value = 0 } } # Input: # type = type of produce # demand = total tradenode demand of a produce # supply = total tradenode supply of a produce # A helper script that calculates total producer income generated in a tradenode, soon to be distributed to producers TN_GetLocalProducerIncomeHelper = { # How much has been bought TN_GetAmountBought = { type = $type$ demand = $demand$ supply = $supply$ return = TN_GetLocalProducerIncomeTotal } multiply_variable = { which = TN_GetLocalProducerIncomeTotal which = TN_Price$type$ } TN_effect = { effect = TN_effect3 } } # Input: # type = type of produce # demand = total tradenode demand of a produce # supply = total tradenode supply of a produce # share = share of production previously calculated in TN_GetSupplyDemand # return = name of a variable where the province's producer income is stored # It calculates total tradenode producer income and distributed to provinces based on their production share TN_SetLocalProducerIncome = { tradenode_centers = { TN_GetLocalProducerIncomeHelper = { type = $type$ demand = $demand$ supply = $supply$ } } every_province = { multiply_variable = { which = TN_GetLocalProducerIncomeTotal which = $share$ } set_variable = { which = $return$ which = TN_GetLocalProducerIncomeTotal } set_variable = { which = TN_GetLocalProducerIncomeTotal value = 0 } } } # Input: # type = type of produce # demand = total tradenode demand of a produce # supply = total tradenode supply of a produce # A helper script that calculates how much demand has been fulfilled by supply TN_SetLocalDemandFulfillHelper = { TN_GetAmountBought = { type = $type$ demand = $demand$ supply = $supply$ return = TN_SetLocalDemandFulfillHelperConsume } TN_GetImportExport = { type = Export typeProduce = $type$ return = TN_SetLocalDemandFulfillHelperExport } subtract_variable = { which = TN_SetLocalDemandFulfillHelperConsume which = TN_SetLocalDemandFulfillHelperExport } divide_variable = { which = TN_SetLocalDemandFulfillHelperConsume which = $demand$ } TN_effect = { effect = TN_effect4 } } # Input: # type = type of produce # demand = total tradenode demand of a produce # supply = total tradenode supply of a produce # return = province's level of fulfilment of demand # It calculates how much of province's demand has been fulfilled TN_SetLocalDemandFulfill = { tradenode_centers = { TN_SetLocalDemandFulfillHelper = { type = $type$ demand = $demand$ supply = $supply$ } } every_province = { set_variable = { which = $return$ which = TN_SetLocalDemandFulfillHelperConsume } set_variable = { which = TN_SetLocalDemandFulfillHelperConsume value = 0 } } } # Initializes TN related informations TN_Init = { TN_InitLink = yes TN_InitLinkPlus = yes set_variable = { which = TN_id value = 1 } tradenode_centers = { set_province_flag = TN_Cent set_variable = { which = TN_id which = ROOT } ROOT = { change_variable = { which = TN_id value = 1 } } } TN_InitCoord = yes } # Inputs: # supplyInp = province's produce supply variable # demandInp = province's produce demand variable # type = type of produce # income = province's income from produce # fulfill = province's level of fulfillment of demand # Calls main TN effects in sequence TN_CalcMain = { tradenode_centers = { clr_province_flag = TN_Link0Open clr_province_flag = TN_Link1Open clr_province_flag = TN_Link2Open clr_province_flag = TN_Link3Open clr_province_flag = TN_Link4Open clr_province_flag = TN_Link5Open clr_province_flag = TN_Link6Open clr_province_flag = TN_Link7Open clr_province_flag = TN_Link8Open } tradenode_centers = { TN_CheckLink = { ind = 0 } TN_CheckLink = { ind = 1 } TN_CheckLink = { ind = 2 } TN_CheckLink = { ind = 3 } TN_CheckLink = { ind = 4 } TN_CheckLink = { ind = 5 } TN_CheckLink = { ind = 6 } TN_CheckLink = { ind = 7 } TN_CheckLink = { ind = 8 } } TN_GetSupplyDemand = { supply = $supplyInp$ demand = $demandInp$ share = TN_CalcMainShare returnSupply = TN_CalcMainSupply returnDemand = TN_CalcMainDemand } tradenode_centers = { TN_GetPrice = { type = $type$ supply = TN_CalcMainSupply demand = TN_CalcMainDemand } TN_CalcImport = { type = $type$ supply = TN_CalcMainSupply demand = TN_CalcMainDemand } TN_CalcSurplus = { type = $type$ supply = TN_CalcMainSupply demand = TN_CalcMainDemand } TN_GetPrice = { type = $type$ supply = TN_CalcMainSupply demand = TN_CalcMainDemand } TN_CalcWealth = { type = $type$ supply = TN_CalcMainSupply demand = TN_CalcMainDemand } TN_SetTradeIncome = yes } TN_SetLocalProducerIncome = { type = $type$ supply = TN_CalcMainSupply demand = TN_CalcMainDemand share = TN_CalcMainShare return = $income$ } TN_SetLocalDemandFulfill = { type = $type$ supply = TN_CalcMainSupply demand = TN_CalcMainDemand return = $fulfill$ } }