Devlog #47 - TaxSystem/FinanceSystem ,Update-FIx -LoanFixes-- TruckSystem Update - Upgrade/BuyNEwTruck - Costs Prices introduced / OfficeSystem CreateNewOffice, upgrade office - other Fixes
****TaxSystem/FinanceSystem update, added new variables "nonTaxable and LoanRepayment"
-TruckSystem addedUpgrade System - BuyNew Truck-
-OfficeSystem, upgradeOffice, Construct new office - code refactoring -
other fixes *****
TaxSystem/FinanceSystem:
PROBLEM 1 : The loan repayments and not calculated in the expense. And I KNOW we fixed that and changed i to this, but the issue here is that the netProfit now shows for example -200$, but the actuall deduct amount is -1200, because 1000$ is debt repayment per day. So yeah, very confusing, and if we add that to the expense like before :
So here, it was working well, because we avoided the problem of taxing the loan as well as loan repayment reducing the taxes . So it was all good haha, but now issue again. We have to cound it but we cannot tax it, one way or another, and because of the structure , the Banktick happens way before any market changes, but the tax tick is at the end of the turn to calculate all events.
The solution: Introducing another variable in the CalculateDailyRevenue, like loanExpense,so then we can do something liek this:
if (evt.type == MoneyEventType.LoanRepayment)
{
loanExpense += Mathf.Abs(evt.amount);
continue;
}
Basically with this we then we write in the TaxSystem:
(float revenue, float expenses, _,_,_) = FinanceSystem.CalculateCompanyDailyTotal(WorldManager.Instance.currentTurnNumber);
and the method has:
Which in the TaxSystem we basically skip the entry , because the tax system also enters the expense as Tax,and then when the method is called then we calculate everything, revenue, expenses tax , loanexpense and nonTaxable.
public static (float revenue, float expenses, float taxPaid, float loanExpense, float nonTaxable) CalculateCompanyDailyTotal(int turnNumber)
So you might wonder, why there is no loan(not)expense, because there is no need, its kinda game design choice. When the loan is taken its clear,the money is increased you get money in the ledger event, but when its deducted its critical to know how much money you are actually spending per day. so ***game design choice*** hahah
_____________________________
_____________________________
oh yes and new category that we didnt have before?
NonTaxable was related to the truck Issue that we will adress later, but essentially that was another problem and change. Becuase of the introduction of TruckUpgrade system ( long planned , now implemented) , also truck sale was introduced. For example, imagine you want to sell at truck, the money you receive, shouldn't be taxable! because its not a income, so again, we had to find a way around the taxSystem. So there it is, not only it solves this problem, but any future problem that will come as non taxable income. Bam! New solution for later scalability.
____________________________________________________________________________________
TruckSystem upgrade/buy truck. We will go briefly through the changes, but essentially it is the same principle as the Hub, and future Office.
The trickier part was that you actually had to pick a truck from within the hub, so what we needed was
cityIndex, hubIndex,truckIndex, to locate it, and then a truckType to change it.
Now another touchy thing was the route, what if a player upgrades a truck on a route, and we load the defaultState from the truckDatabase. It would override. Simple, soultion was to choose what changes, and everything else stayed.
NonTaxable was related to the truck Issue that we will adress later, but essentially that was another problem and change. Becuase of the introduction of TruckUpgrade system ( long planned , now implemented) , also truck sale was introduced. For example, imagine you want to sell at truck, the money you receive, shouldn't be taxable! because its not a income, so again, we had to find a way around the taxSystem. So there it is, not only it solves this problem, but any future problem that will come as non taxable income. Bam! New solution for later scalability.
____________________________________________________________________________________
TruckSystem upgrade/buy truck. We will go briefly through the changes, but essentially it is the same principle as the Hub, and future Office.
The trickier part was that you actually had to pick a truck from within the hub, so what we needed was
cityIndex, hubIndex,truckIndex, to locate it, and then a truckType to change it.
Now another touchy thing was the route, what if a player upgrades a truck on a route, and we load the defaultState from the truckDatabase. It would override. Simple, soultion was to choose what changes, and everything else stayed.
So we change, for example: fuelConsumption, maxCapacity upkeep etc. and the rest stays.
but also upgrade would require that the old truck is traded in, so we simply said
float upgradeCost = newTruck.price - (oldtruck.Price * usedPriceModifier) ; // to reduce the value of the oldtruck..
Simple yet effective!
And instead of calculating there we built a separate method for code cleanliness. (but does the same thing) .
Ok and for adding a new truck, simply, check if enough money, if is, check if hub has space, if is, deduct money, add a new truck based on the type, copy all the values and done.
but also upgrade would require that the old truck is traded in, so we simply said
float upgradeCost = newTruck.price - (oldtruck.Price * usedPriceModifier) ; // to reduce the value of the oldtruck..
Simple yet effective!
float upgradeCost = CalculateTruckUpgradeCost(oldTruck, newType);
if (currentCash >= upgradeCost)
{
if (newType <= oldTruck.truckType) return;
And instead of calculating there we built a separate method for code cleanliness. (but does the same thing) .
Ok and for adding a new truck, simply, check if enough money, if is, check if hub has space, if is, deduct money, add a new truck based on the type, copy all the values and done.
Very important note: What this also required is not just writing the logic, but actually writing the data for each truck..fuel consumption, maxCapactiy that will fit within the game, etc...
____________________________________________________________________________________
OfficeSystem! Yes, same principle same way, similar to Hub. Only this time we guard the office build if there is one already, because its limited to one per city. So the costs we have here are upgrade and construciton costs. Time to build, time to upgrade etc. Same structure! That what makes this sound and( is) easier then it sounds! Then it is, or sounds or both! hah
But what was very interesing here (for me at least) is that i noticed that my code could be more optimized! ****code refactoring****
OfficeSystem! Yes, same principle same way, similar to Hub. Only this time we guard the office build if there is one already, because its limited to one per city. So the costs we have here are upgrade and construciton costs. Time to build, time to upgrade etc. Same structure! That what makes this sound and( is) easier then it sounds! Then it is, or sounds or both! hah
**(yeah I know, the names are random and it can be better,but damn this clean code is sexy) **
For example:

Looks fine? well,..the problem was that each tick, for each city, it would call for each method for(int, and go through all. Now admittedly, its only one office per city, so who cares.. but still! it can be better, and it will be . So simply, instead of going through each method, we move the for to go through cities once and then do all methods and calculations.
Then I saw ok, office also we can get already in city at the tick method, so we also forward that to everything, and we send the ref so writeback is not necessary( for this exact context, we still need to include cityWriteback, because we removed it from the methods) ! For example:

Looks fine? well,..the problem was that each tick, for each city, it would call for each method for(int, and go through all. Now admittedly, its only one office per city, so who cares.. but still! it can be better, and it will be . So simply, instead of going through each method, we move the for to go through cities once and then do all methods and calculations.
Then I saw ok, office also we can get already in city at the tick method, so we also forward that to everything, and we send the ref so writeback is not necessary( for this exact context, we still need to include cityWriteback, because we removed it from the methods) ! For example:
public static void Tick(ref CityState city, OfficeDatabase officeDatabase)
{
for (int o = 0; o < city.cityOffices.Count; o++)
{
OfficeState currentOffice = city.cityOffices[o];
and we forward:
CalculateOfficeWorkload(ref city, ref currentOffice);
CalculateOfficeEfficiency(ref city, ref currentOffice);
CalculateOfficeExpenses(ref city, ref currentOffice);
Simple fix! Cleaner code! (performance...hmm..sure) , my coding is 1% better. Its a win!!
(same note here...had to write all the officeTypes, calculate upgradecost, proportions, time to upgrade etc..) - yet to be balanced...
Thank you!!
Also, added in the transactionSnapshot Loanexpense, as well as nonTaxable,so we can put it in a chart!!!
Also, added in the transactionSnapshot Loanexpense, as well as nonTaxable,so we can put it in a chart!!!


Comments
Post a Comment