30 #include "newgrf_engine.h" |
30 #include "newgrf_engine.h" |
31 #include "unmovable.h" |
31 #include "unmovable.h" |
32 |
32 |
33 // Score info |
33 // Score info |
34 const ScoreInfo _score_info[] = { |
34 const ScoreInfo _score_info[] = { |
35 {SCORE_VEHICLES, 120, 100}, |
35 { SCORE_VEHICLES, 120, 100 }, |
36 {SCORE_STATIONS, 80, 100}, |
36 { SCORE_STATIONS, 80, 100 }, |
37 {SCORE_MIN_PROFIT, 10000, 100}, |
37 { SCORE_MIN_PROFIT, 10000, 100 }, |
38 {SCORE_MIN_INCOME, 50000, 50}, |
38 { SCORE_MIN_INCOME, 50000, 50 }, |
39 {SCORE_MAX_INCOME, 100000, 100}, |
39 { SCORE_MAX_INCOME, 100000, 100 }, |
40 {SCORE_DELIVERED, 40000, 400}, |
40 { SCORE_DELIVERED, 40000, 400 }, |
41 {SCORE_CARGO, 8, 50}, |
41 { SCORE_CARGO, 8, 50 }, |
42 {SCORE_MONEY, 10000000, 50}, |
42 { SCORE_MONEY, 10000000, 50 }, |
43 {SCORE_LOAN, 250000, 50}, |
43 { SCORE_LOAN, 250000, 50 }, |
44 {SCORE_TOTAL, 0, 0} |
44 { SCORE_TOTAL, 0, 0 } |
45 }; |
45 }; |
46 |
46 |
47 int _score_part[MAX_PLAYERS][NUM_SCORE]; |
47 int _score_part[MAX_PLAYERS][NUM_SCORE]; |
48 |
48 |
49 int64 CalculateCompanyValue(const Player* p) |
49 int64 CalculateCompanyValue(const Player* p) |
100 int32 min_profit = 0; |
100 int32 min_profit = 0; |
101 bool min_profit_first = true; |
101 bool min_profit_first = true; |
102 uint num = 0; |
102 uint num = 0; |
103 |
103 |
104 FOR_ALL_VEHICLES(v) { |
104 FOR_ALL_VEHICLES(v) { |
105 if (v->owner != owner) |
105 if (v->owner != owner) continue; |
106 continue; |
|
107 if ((v->type == VEH_Train && IsFrontEngine(v)) || |
106 if ((v->type == VEH_Train && IsFrontEngine(v)) || |
108 v->type == VEH_Road || |
107 v->type == VEH_Road || |
109 (v->type == VEH_Aircraft && v->subtype <= 2) || |
108 (v->type == VEH_Aircraft && v->subtype <= 2) || |
110 v->type == VEH_Ship) { |
109 v->type == VEH_Ship) { |
111 num++; |
110 num++; |
112 if (v->age > 730) { |
111 if (v->age > 730) { |
113 /* Find the vehicle with the lowest amount of profit */ |
112 /* Find the vehicle with the lowest amount of profit */ |
114 if (min_profit_first == true) { |
113 if (min_profit_first == true) { |
115 min_profit = v->profit_last_year; |
114 min_profit = v->profit_last_year; |
116 min_profit_first = false; |
115 min_profit_first = false; |
117 } else if (min_profit > v->profit_last_year) |
116 } else if (min_profit > v->profit_last_year) { |
118 min_profit = v->profit_last_year; |
117 min_profit = v->profit_last_year; |
|
118 } |
119 } |
119 } |
120 } |
120 } |
121 } |
121 } |
122 |
122 |
123 _score_part[owner][SCORE_VEHICLES] = num; |
123 _score_part[owner][SCORE_VEHICLES] = num; |
227 // We always want the score scaled to SCORE_MAX (1000) |
227 // We always want the score scaled to SCORE_MAX (1000) |
228 if (total_score != SCORE_MAX) score = score * SCORE_MAX / total_score; |
228 if (total_score != SCORE_MAX) score = score * SCORE_MAX / total_score; |
229 } |
229 } |
230 |
230 |
231 if (update) { |
231 if (update) { |
232 p->old_economy[0].performance_history = score; |
232 p->old_economy[0].performance_history = score; |
233 UpdateCompanyHQ(p, score); |
233 UpdateCompanyHQ(p, score); |
234 p->old_economy[0].company_value = CalculateCompanyValue(p); |
234 p->old_economy[0].company_value = CalculateCompanyValue(p); |
235 } |
235 } |
236 |
236 |
237 InvalidateWindow(WC_PERFORMANCE_DETAIL, 0); |
237 InvalidateWindow(WC_PERFORMANCE_DETAIL, 0); |
238 return score; |
238 return score; |
239 } |
239 } |
240 |
240 |
247 if (new_player == OWNER_SPECTATOR) { |
247 if (new_player == OWNER_SPECTATOR) { |
248 Subsidy *s; |
248 Subsidy *s; |
249 |
249 |
250 for (s = _subsidies; s != endof(_subsidies); s++) { |
250 for (s = _subsidies; s != endof(_subsidies); s++) { |
251 if (s->cargo_type != CT_INVALID && s->age >= 12) { |
251 if (s->cargo_type != CT_INVALID && s->age >= 12) { |
252 if (GetStation(s->to)->owner == old_player) |
252 if (GetStation(s->to)->owner == old_player) s->cargo_type = CT_INVALID; |
253 s->cargo_type = CT_INVALID; |
|
254 } |
253 } |
255 } |
254 } |
256 } |
255 } |
257 |
256 |
258 /* Take care of rating in towns */ |
257 /* Take care of rating in towns */ |
288 |
287 |
289 // Determine Ids for the new vehicles |
288 // Determine Ids for the new vehicles |
290 FOR_ALL_VEHICLES(v) { |
289 FOR_ALL_VEHICLES(v) { |
291 if (v->owner == new_player) { |
290 if (v->owner == new_player) { |
292 switch (v->type) { |
291 switch (v->type) { |
293 case VEH_Train: |
292 case VEH_Train: if (IsFrontEngine(v)) num_train++; break; |
294 if (IsFrontEngine(v)) num_train++; |
293 case VEH_Road: num_road++; break; |
295 break; |
294 case VEH_Ship: num_ship++; break; |
296 case VEH_Road: |
295 case VEH_Aircraft: if (v->subtype <= 2) num_aircraft++; break; |
297 num_road++; |
|
298 break; |
|
299 case VEH_Ship: |
|
300 num_ship++; |
|
301 break; |
|
302 case VEH_Aircraft: |
|
303 if (v->subtype <= 2) num_aircraft++; |
|
304 break; |
|
305 default: break; |
296 default: break; |
306 } |
297 } |
307 } |
298 } |
308 } |
299 } |
309 |
300 |
350 |
340 |
351 /* Check for shares */ |
341 /* Check for shares */ |
352 FOR_ALL_PLAYERS(p) { |
342 FOR_ALL_PLAYERS(p) { |
353 for (i = 0; i < 4; i++) { |
343 for (i = 0; i < 4; i++) { |
354 /* 'Sell' the share if this player has any */ |
344 /* 'Sell' the share if this player has any */ |
355 if (p->share_owners[i] == _current_player) |
345 if (p->share_owners[i] == _current_player) { |
356 p->share_owners[i] = OWNER_SPECTATOR; |
346 p->share_owners[i] = OWNER_SPECTATOR; |
|
347 } |
357 } |
348 } |
358 } |
349 } |
359 p = GetPlayer(_current_player); |
350 p = GetPlayer(_current_player); |
360 /* Sell all the shares that people have on this company */ |
351 /* Sell all the shares that people have on this company */ |
361 for (i = 0; i < 4; i++) |
352 for (i = 0; i < 4; i++) |
1209 { |
1200 { |
1210 bool subsidised; |
1201 bool subsidised; |
1211 Station *s_from, *s_to; |
1202 Station *s_from, *s_to; |
1212 int32 profit; |
1203 int32 profit; |
1213 |
1204 |
1214 assert(num_pieces > 0); |
1205 assert(num_pieces > 0); |
1215 |
1206 |
1216 // Update player statistics |
1207 // Update player statistics |
1217 { |
1208 { |
1218 Player *p = GetPlayer(_current_player); |
1209 Player *p = GetPlayer(_current_player); |
1219 p->cur_economy.delivered_cargo += num_pieces; |
1210 p->cur_economy.delivered_cargo += num_pieces; |