Skip to content

Commit

Permalink
Merge pull request #515 from Nashet/AddMoneyIncomeStatistics
Browse files Browse the repository at this point in the history
AddMoneyIncomeStatistics
  • Loading branch information
Nashet authored Sep 6, 2018
2 parents 6778640 + 56b41c0 commit c97e7b9
Show file tree
Hide file tree
Showing 66 changed files with 1,377 additions and 1,188 deletions.
131 changes: 120 additions & 11 deletions Assets/EconomicSimulation/ES-base.unity
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OcclusionCullingSettings:
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
serializedVersion: 8
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
Expand All @@ -39,7 +39,6 @@ RenderSettings:
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
Expand All @@ -55,10 +54,11 @@ LightmapSettings:
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 10
serializedVersion: 9
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
Expand Down Expand Up @@ -5810,6 +5810,114 @@ CanvasRenderer:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 266232590}
--- !u!1 &269487111
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 269487116}
- component: {fileID: 269487115}
- component: {fileID: 269487112}
- component: {fileID: 269487114}
- component: {fileID: 269487113}
m_Layer: 5
m_Name: BalanceText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &269487112
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 269487111}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 3
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: BalanceText
--- !u!114 &269487113
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 269487111}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 99f87c8e4381dd140816922f1be162f7, type: 3}
m_Name:
m_EditorClassIdentifier:
text:
isDynamic: 1
--- !u!114 &269487114
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 269487111}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1679637790, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreLayout: 0
m_MinWidth: -1
m_MinHeight: 16
m_PreferredWidth: -1
m_PreferredHeight: -1
m_FlexibleWidth: -1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!222 &269487115
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 269487111}
--- !u!224 &269487116
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 269487111}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 894451432}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 1}
--- !u!1 &270931659
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -7616,7 +7724,7 @@ RectTransform:
- {fileID: 1405478120}
- {fileID: 971685174}
m_Father: {fileID: 894451432}
m_RootOrder: 5
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -10677,7 +10785,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 894451432}
m_RootOrder: 2
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -13090,7 +13198,6 @@ MeshRenderer:
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 4294967295
m_Materials:
- {fileID: 2100000, guid: 52b7d70b1de7c4ce09662b77c14d9fda, type: 2}
m_StaticBatchInfo:
Expand Down Expand Up @@ -15209,7 +15316,7 @@ RectTransform:
- {fileID: 691940029}
- {fileID: 1429246073}
m_Father: {fileID: 894451432}
m_RootOrder: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -19550,6 +19657,7 @@ MonoBehaviour:
caption: {fileID: 2108871203}
onSaleText: {fileID: 0}
ownership: {fileID: 509497467}
profitText: {fileID: 269487112}
--- !u!114 &889415546
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -19703,6 +19811,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1065585675}
- {fileID: 269487116}
- {fileID: 1270452772}
- {fileID: 509497471}
- {fileID: 706810820}
Expand Down Expand Up @@ -27156,7 +27265,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 894451432}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -32149,7 +32258,7 @@ RectTransform:
- {fileID: 887769459}
- {fileID: 1642616029}
m_Father: {fileID: 894451432}
m_RootOrder: 4
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -40202,7 +40311,7 @@ RectTransform:
m_Children:
- {fileID: 786814484}
m_Father: {fileID: 894451432}
m_RootOrder: 6
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down
38 changes: 15 additions & 23 deletions Assets/EconomicSimulation/Scripts/Logic/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace Nashet.EconomicSimulation
public abstract class Agent : IHasCountry, IStatisticable
{
/// <summary> Used to calculate income tax, now it's only for statistics </summary>
public Money moneyIncomeThisTurn = new Money(0);
//public Money moneyIncomeThisTurn = new Money(0);

protected readonly Money moneyIncomeLastTurn = new Money(0);
//protected readonly Money moneyIncomeLastTurn = new Money(0);
protected readonly Money cash = new Money(0);
public MoneyView Cash { get { return cash; } }

Expand All @@ -25,7 +25,7 @@ public abstract class Agent : IHasCountry, IStatisticable

public Money deposits = new Money(0);

public Money incomeTaxPayed = new Money(0);
//public Money incomeTaxPayed = new Money(0);

public abstract void simulate();

Expand Down Expand Up @@ -57,9 +57,6 @@ public void GiveMoneyFromNoWhere(decimal money)

public virtual void SetStatisticToZero()
{
moneyIncomeLastTurn.Set(moneyIncomeThisTurn);
moneyIncomeThisTurn.SetZero();
incomeTaxPayed.SetZero();
Register.SetStatisticToZero();
}

Expand Down Expand Up @@ -210,15 +207,15 @@ public bool CanPayCashOnly(MoneyView howMuchPay)

/// <summary>
/// Checks inside. Wouldn't pay if can't. Takes back deposits from bank, if needed
/// Doesn't pay tax, doesn't register transaction
/// Doesn't pay tax
/// </summary>
public bool PayWithoutRecord(Agent whom, MoneyView howMuch, bool showMessageAboutNegativeValue = true)
public bool PayWithoutRecord(Agent whom, MoneyView howMuch, Register.Account account, bool showMessageAboutNegativeValue = true)
{
if (CanPay(howMuch))// It does has enough cash or deposit
{
if (!CanPayCashOnly(howMuch))
Bank.ReturnDeposit(this, HowMuchLacksMoneyCashOnly(howMuch));

Register.RecordPayment(whom, account, howMuch.Get());
whom.cash.Add(howMuch);
cash.Subtract(howMuch);
return true;
Expand All @@ -234,18 +231,19 @@ public bool PayWithoutRecord(Agent whom, MoneyView howMuch, bool showMessageAbou
}

/// <summary>
/// used only to pay to stash, should be removed
/// Checks inside. Wouldn't pay if can't. Takes back deposits from bank, if needed
/// Doesn't pay tax, doesn't register transaction
/// Doesn't pay tax
/// </summary>

// todo remove it #510
public bool PayWithoutRecord(Money whom, MoneyView howMuch, bool showMessageAboutNegativeValue = true)
{
// todo remove it
if (CanPay(howMuch))// It does has enough cash or deposit
{
if (!CanPayCashOnly(howMuch))
Bank.ReturnDeposit(this, HowMuchLacksMoneyCashOnly(howMuch));

whom.Add(howMuch);
cash.Subtract(howMuch);
return true;
}
else
Expand All @@ -265,15 +263,9 @@ public bool PayWithoutRecord(Money whom, MoneyView howMuch, bool showMessageAbou
public bool Pay(Agent incomeReceiver, MoneyView howMuch, Register.Account account, bool showMessageAboutNegativeValue = true)
{
if (howMuch.isNotZero())
if (PayWithoutRecord(incomeReceiver, howMuch, showMessageAboutNegativeValue)) // pays here
if (PayWithoutRecord(incomeReceiver, howMuch, account, showMessageAboutNegativeValue)) // pays here
{
Register.RecordPayment(incomeReceiver, account, howMuch.Get());
//this.moneyFlow.AddAndSum(account, howMuch.Get() * -1m);//giver
//incomeReceiver.moneyFlow.AddAndSum(account, howMuch.Get());


Money howMuchPayReally = howMuch.Copy();
incomeReceiver.moneyIncomeThisTurn.Add(howMuchPayReally);

if (incomeReceiver is Market) // Market wouldn't pay taxes cause it's abstract entity
return true;
Expand All @@ -285,7 +277,7 @@ public bool Pay(Agent incomeReceiver, MoneyView howMuch, Register.Account accoun
&& payer.country != incomeReceiver.country
&& payer is Factory) // pay taxes in enterprise jurisdiction only if it's factory
{
var payed = payer.country.TakeIncomeTaxFrom(incomeReceiver, howMuchPayReally, false);
var payed = payer.country.TakeIncomeTaxFrom(incomeReceiver, howMuchPayReally, false);
howMuchPayReally.Subtract(payed);//and reduce taxable base
}

Expand Down Expand Up @@ -313,11 +305,11 @@ public void PayAllAvailableMoney(Agent whom, Register.Account account)
Pay(whom, cash, account);
}

public void PayAllAvailableMoneyWithoutRecord(Agent whom)
public void PayAllAvailableMoneyWithoutRecord(Agent whom, Register.Account account)
{
if (Bank != null)
Bank.ReturnAllDeposits(this);
PayWithoutRecord(whom, cash);
PayWithoutRecord(whom, cash, account);
}

public override string ToString()
Expand Down
2 changes: 1 addition & 1 deletion Assets/EconomicSimulation/Scripts/Logic/Army.cs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ public string getName()
{
//foreach (var next in getAmountByTypes())
// sb.Append(next.Value).Append(" ").Append(next.Key).Append(", ");
sb.Append(getAmountByTypes().getString(": ", ", "));
sb.Append(getAmountByTypes().ToString(": ", ", "));
sb.Append(", Total size: ").Append(getSize());
sb.Append(", Morale: ").Append(GetAverageCorps(x => x.getMorale()));
sb.Append(", Provision: ").Append(getConsumption());
Expand Down
8 changes: 4 additions & 4 deletions Assets/EconomicSimulation/Scripts/Logic/Bank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Bank(Country country) : base(country)
/// </summary>
public void ReceiveMoney(Agent giver, MoneyView sum)
{
if (giver.PayWithoutRecord(this, sum))
if (giver.PayWithoutRecord(this, sum, Register.Account.BankOperation))
if (giver.loans.isNotZero()) //has debt (meaning has no deposits)
if (sum.isBiggerOrEqual(giver.loans)) // cover debt
{
Expand Down Expand Up @@ -78,7 +78,7 @@ public bool GiveCredit(Agent taker, MoneyView desiredCredit) // todo check
{
taker.loans.Set(restOfTheSum);//important
givenCredits.Add(restOfTheSum);
PayWithoutRecord(taker, restOfTheSum);
PayWithoutRecord(taker, restOfTheSum, Register.Account.BankOperation);
return true;
}
else
Expand All @@ -102,7 +102,7 @@ public bool GiveCredit(Agent taker, MoneyView desiredCredit) // todo check
{
taker.loans.Add(desiredCredit);
givenCredits.Add(desiredCredit);
PayWithoutRecord(taker, desiredCredit);
PayWithoutRecord(taker, desiredCredit, Register.Account.BankOperation);
return true;
}
else
Expand Down Expand Up @@ -147,7 +147,7 @@ public MoneyView ReturnDeposit(Agent toWhom, MoneyView howMuchWants)
{
//giveMoney(toWhom, moneyToReturn);
toWhom.deposits.Subtract(returnMoney);
PayWithoutRecord(toWhom, returnMoney);
PayWithoutRecord(toWhom, returnMoney, Register.Account.BankOperation);
}
return returnMoney;
}
Expand Down
Loading

0 comments on commit c97e7b9

Please sign in to comment.