MCPcopy Create free account
hub / github.com/SimHacker/micropolis / doBudgetNow

Method doBudgetNow

MicropolisCore/src/MicropolisEngine/src/budget.cpp:107–315  ·  view source on GitHub ↗

* Handle budget window. * @param fromMenu User requested the budget window. * @todo Simplify this code. Instead of this nested mess, make a sequence of * assigning funds to road, fire, and police. */

Source from the content-addressed store, hash-verified

105 * assigning funds to road, fire, and police.
106 */
107void Micropolis::doBudgetNow(bool fromMenu)
108{
109 Quad fireInt = (int)(fireFund * firePercent);
110 Quad policeInt = (int)(policeFund * policePercent);
111 Quad roadInt = (int)(roadFund * roadPercent);
112
113 Quad total = fireInt + policeInt + roadInt;
114
115 Quad yumDuckets = taxFund + totalFunds;
116
117 if (yumDuckets > total) {
118
119 // Enough yumDuckets to fully fund fire, police and road.
120
121 fireValue = fireInt;
122 policeValue = policeInt;
123 roadValue = roadInt;
124
125 /// @todo Why are we not subtracting from yumDuckets what we
126 /// spend, like the code below is doing?
127
128 } else if (total > 0) {
129
130 assert(yumDuckets <= total);
131
132 // Not enough yumDuckets to fund everything.
133 // First spend on roads, then on fire, then on police.
134
135 if (yumDuckets > roadInt) {
136
137 // Enough yumDuckets to fully fund roads.
138
139 roadValue = roadInt;
140 yumDuckets -= roadInt;
141
142 if (yumDuckets > fireInt) {
143
144 // Enough yumDuckets to fully fund fire.
145
146 fireValue = fireInt;
147 yumDuckets -= fireInt;
148
149 if (yumDuckets > policeInt) {
150
151 // Enough yumDuckets to fully fund police.
152 // Hey what are we doing here? Should never get here.
153 // We tested for yumDuckets > total above
154 // (where total = fireInt + policeInt + roadInt),
155 // so this should never happen.
156
157 policeValue = policeInt;
158 yumDuckets -= policeInt;
159
160 } else {
161
162 // Fuly funded roads and fire.
163 // Partially fund police.
164

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected