branch | gamebalance |
changeset 9912 | 1ac8aac92385 |
parent 9911 | 0b8b245a2391 |
child 9913 | e79cd19772dd |
9911:0b8b245a2391 | 9912:1ac8aac92385 |
---|---|
35 void BuildOilRig(TileIndex tile); |
35 void BuildOilRig(TileIndex tile); |
36 |
36 |
37 static byte _industry_sound_ctr; |
37 static byte _industry_sound_ctr; |
38 static TileIndex _industry_sound_tile; |
38 static TileIndex _industry_sound_tile; |
39 |
39 |
40 int _total_industries; //general counter |
|
41 uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame |
|
42 |
|
43 const Industry **_industry_sort; |
|
44 bool _industry_sort_dirty; |
|
45 |
|
46 IndustrySpec _industry_specs[NUM_INDUSTRYTYPES]; |
|
47 IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES]; |
|
48 |
|
49 /** This function initialize the spec arrays of both |
|
50 * industry and industry tiles. |
|
51 * It adjusts the enabling of the industry too, based on climate availability. |
|
52 * This will allow for clearer testings */ |
|
53 void ResetIndustries() |
|
54 { |
|
55 memset(&_industry_specs, 0, sizeof(_industry_specs)); |
|
56 memcpy(&_industry_specs, &_origin_industry_specs, sizeof(_origin_industry_specs)); |
|
57 |
|
58 /* once performed, enable only the current climate industries */ |
|
59 for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) { |
|
60 _industry_specs[i].enabled = HASBIT(_origin_industry_specs[i].climate_availability, _opt.landscape); |
|
61 } |
|
62 |
|
63 |
|
64 memset(&_industry_tile_specs, 0, sizeof(_industry_tile_specs)); |
|
65 memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs)); |
|
66 } |
|
67 |
|
40 /** |
68 /** |
41 * Called if a new block is added to the industry-pool |
69 * Called if a new block is added to the industry-pool |
42 */ |
70 */ |
43 static void IndustryPoolNewBlock(uint start_item) |
71 static void IndustryPoolNewBlock(uint start_item) |
44 { |
72 { |
84 /** |
112 /** |
85 * Accessor for array _industry_tile_specs. |
113 * Accessor for array _industry_tile_specs. |
86 * This will ensure at once : proper access and |
114 * This will ensure at once : proper access and |
87 * not allowing modifications of it. |
115 * not allowing modifications of it. |
88 * @param gfx of industrytile (which is the index in _industry_specs) |
116 * @param gfx of industrytile (which is the index in _industry_specs) |
89 * @pre gfx < NUM_INDUSTRY_GFXES |
117 * @pre gfx < INVALID_INDUSTRYTILE |
90 * @return a pointer to the corresponding industrytile spec |
118 * @return a pointer to the corresponding industrytile spec |
91 **/ |
119 **/ |
92 const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx) |
120 const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx) |
93 { |
121 { |
94 assert(gfx < NUM_INDUSTRY_GFXES); |
122 assert(gfx < INVALID_INDUSTRYTILE); |
95 return &_industry_tile_specs[gfx]; |
123 return &_industry_tile_specs[gfx]; |
96 } |
124 } |
97 |
125 |
98 void DestroyIndustry(Industry *i) |
126 void DestroyIndustry(Industry *i) |
99 { |
127 { |
117 } |
145 } |
118 } END_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiff(21, 21)) |
146 } END_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiff(21, 21)) |
119 } |
147 } |
120 |
148 |
121 _industry_sort_dirty = true; |
149 _industry_sort_dirty = true; |
122 _total_industries--; |
150 DecIndustryTypeCount(i->type); |
151 |
|
123 DeleteSubsidyWithIndustry(i->index); |
152 DeleteSubsidyWithIndustry(i->index); |
124 DeleteWindowById(WC_INDUSTRY_VIEW, i->index); |
153 DeleteWindowById(WC_INDUSTRY_VIEW, i->index); |
125 InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
154 InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
126 } |
155 } |
127 |
156 |
285 static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac) |
314 static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac) |
286 { |
315 { |
287 const IndustryTileSpec *itspec = GetIndustryTileSpec(GetIndustryGfx(tile)); |
316 const IndustryTileSpec *itspec = GetIndustryTileSpec(GetIndustryGfx(tile)); |
288 CargoID a; |
317 CargoID a; |
289 |
318 |
290 a = itspec->accepts_cargo[0]; |
319 for (byte i = 0; i < lengthof(itspec->accepts_cargo); i++) { |
291 if (a != CT_INVALID) ac[a] = (a == CT_PASSENGERS) ? 1 : 8; |
320 a = itspec->accepts_cargo[i]; |
292 |
321 if (a != CT_INVALID) ac[a] = itspec->acceptance[i]; |
293 a = itspec->accepts_cargo[1]; |
322 } |
294 if (a != CT_INVALID) ac[a] = 8; |
|
295 |
|
296 a = itspec->accepts_cargo[2]; |
|
297 if (a != CT_INVALID) ac[a] = 8; |
|
298 } |
323 } |
299 |
324 |
300 static void GetTileDesc_Industry(TileIndex tile, TileDesc *td) |
325 static void GetTileDesc_Industry(TileIndex tile, TileDesc *td) |
301 { |
326 { |
302 const Industry *i = GetIndustryByTile(tile); |
327 const Industry *i = GetIndustryByTile(tile); |
341 i->cargo_waiting[0] -= cw; |
366 i->cargo_waiting[0] -= cw; |
342 |
367 |
343 /* fluctuating economy? */ |
368 /* fluctuating economy? */ |
344 if (_economy.fluct <= 0) cw = (cw + 1) / 2; |
369 if (_economy.fluct <= 0) cw = (cw + 1) / 2; |
345 |
370 |
346 i->last_mo_production[0] += cw; |
371 i->this_month_production[0] += cw; |
347 |
372 |
348 am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[0], cw); |
373 am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[0], cw); |
349 i->last_mo_transported[0] += am; |
374 i->this_month_transported[0] += am; |
350 if (am != 0) { |
375 if (am != 0) { |
351 uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production; |
376 uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production; |
352 |
377 |
353 if (newgfx != INDUTILE_NOANIM) { |
378 if (newgfx != INDUSTRYTILE_NOANIM) { |
354 ResetIndustryConstructionStage(tile); |
379 ResetIndustryConstructionStage(tile); |
355 SetIndustryCompleted(tile, true); |
380 SetIndustryCompleted(tile, true); |
356 SetIndustryGfx(tile, newgfx); |
381 SetIndustryGfx(tile, newgfx); |
357 MarkTileDirtyByTile(tile); |
382 MarkTileDirtyByTile(tile); |
358 } |
383 } |
363 if (cw > indspec->minimal_cargo) { |
388 if (cw > indspec->minimal_cargo) { |
364 i->cargo_waiting[1] -= cw; |
389 i->cargo_waiting[1] -= cw; |
365 |
390 |
366 if (_economy.fluct <= 0) cw = (cw + 1) / 2; |
391 if (_economy.fluct <= 0) cw = (cw + 1) / 2; |
367 |
392 |
368 i->last_mo_production[1] += cw; |
393 i->this_month_production[1] += cw; |
369 |
394 |
370 am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[1], cw); |
395 am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[1], cw); |
371 i->last_mo_transported[1] += am; |
396 i->this_month_transported[1] += am; |
372 } |
397 } |
373 } |
398 } |
374 |
399 |
375 |
400 |
376 static void AnimateTile_Industry(TileIndex tile) |
401 static void AnimateTile_Industry(TileIndex tile) |
634 if (_game_mode == GM_EDITOR) return; |
659 if (_game_mode == GM_EDITOR) return; |
635 |
660 |
636 TransportIndustryGoods(tile); |
661 TransportIndustryGoods(tile); |
637 |
662 |
638 newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_next; |
663 newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_next; |
639 if (newgfx != INDUTILE_NOANIM) { |
664 if (newgfx != INDUSTRYTILE_NOANIM) { |
640 ResetIndustryConstructionStage(tile); |
665 ResetIndustryConstructionStage(tile); |
641 SetIndustryGfx(tile, newgfx); |
666 SetIndustryGfx(tile, newgfx); |
642 MarkTileDirtyByTile(tile); |
667 MarkTileDirtyByTile(tile); |
643 return; |
668 return; |
644 } |
669 } |
733 static void ClickTile_Industry(TileIndex tile) |
758 static void ClickTile_Industry(TileIndex tile) |
734 { |
759 { |
735 ShowIndustryViewWindow(GetIndustryIndex(tile)); |
760 ShowIndustryViewWindow(GetIndustryIndex(tile)); |
736 } |
761 } |
737 |
762 |
738 static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode) |
763 static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_mode) |
739 { |
764 { |
740 return 0; |
765 return 0; |
741 } |
766 } |
742 |
767 |
743 static void GetProducedCargo_Industry(TileIndex tile, CargoID *b) |
768 static void GetProducedCargo_Industry(TileIndex tile, CargoID *b) |
1281 |
1306 |
1282 FOR_ALL_INDUSTRIES(i) { |
1307 FOR_ALL_INDUSTRIES(i) { |
1283 /* check if an industry that accepts the same goods is nearby */ |
1308 /* check if an industry that accepts the same goods is nearby */ |
1284 if (DistanceMax(tile, i->xy) <= 14 && |
1309 if (DistanceMax(tile, i->xy) <= 14 && |
1285 indspec->accepts_cargo[0] != CT_INVALID && |
1310 indspec->accepts_cargo[0] != CT_INVALID && |
1286 indspec->accepts_cargo[0] == indspec->accepts_cargo[0] && ( |
1311 indspec->accepts_cargo[0] == GetIndustrySpec(i->type)->accepts_cargo[0] && ( |
1287 _game_mode != GM_EDITOR || |
1312 _game_mode != GM_EDITOR || |
1288 !_patches.same_industry_close || |
1313 !_patches.same_industry_close || |
1289 !_patches.multiple_industry_per_town |
1314 !_patches.multiple_industry_per_town |
1290 )) { |
1315 )) { |
1291 _error_message = STR_INDUSTRY_TOO_CLOSE; |
1316 _error_message = STR_INDUSTRY_TOO_CLOSE; |
1327 { |
1352 { |
1328 const IndustrySpec *indspec = GetIndustrySpec(type); |
1353 const IndustrySpec *indspec = GetIndustrySpec(type); |
1329 uint32 r; |
1354 uint32 r; |
1330 int j; |
1355 int j; |
1331 |
1356 |
1332 _total_industries++; |
|
1333 i->xy = tile; |
1357 i->xy = tile; |
1334 i->width = i->height = 0; |
1358 i->width = i->height = 0; |
1335 i->type = type; |
1359 i->type = type; |
1360 IncIndustryTypeCount(type); |
|
1336 |
1361 |
1337 i->production_rate[0] = indspec->production_rate[0]; |
1362 i->production_rate[0] = indspec->production_rate[0]; |
1338 i->production_rate[1] = indspec->production_rate[1]; |
1363 i->production_rate[1] = indspec->production_rate[1]; |
1339 |
1364 |
1340 if (_patches.smooth_economy) { |
1365 if (_patches.smooth_economy) { |
1348 r = Random(); |
1373 r = Random(); |
1349 i->random_color = GB(r, 8, 4); |
1374 i->random_color = GB(r, 8, 4); |
1350 i->counter = GB(r, 0, 12); |
1375 i->counter = GB(r, 0, 12); |
1351 i->cargo_waiting[0] = 0; |
1376 i->cargo_waiting[0] = 0; |
1352 i->cargo_waiting[1] = 0; |
1377 i->cargo_waiting[1] = 0; |
1353 i->last_mo_production[0] = 0; |
1378 i->this_month_production[0] = 0; |
1354 i->last_mo_production[1] = 0; |
1379 i->this_month_production[1] = 0; |
1355 i->last_mo_transported[0] = 0; |
1380 i->this_month_transported[0] = 0; |
1356 i->last_mo_transported[1] = 0; |
1381 i->this_month_transported[1] = 0; |
1357 i->pct_transported[0] = 0; |
1382 i->last_month_pct_transported[0] = 0; |
1358 i->pct_transported[1] = 0; |
1383 i->last_month_pct_transported[1] = 0; |
1359 i->total_transported[0] = 0; |
1384 i->last_month_transported[0] = 0; |
1360 i->total_transported[1] = 0; |
1385 i->last_month_transported[1] = 0; |
1361 i->was_cargo_delivered = false; |
1386 i->was_cargo_delivered = false; |
1362 i->last_prod_year = _cur_year; |
1387 i->last_prod_year = _cur_year; |
1363 i->total_production[0] = i->production_rate[0] * 8; |
1388 i->last_month_production[0] = i->production_rate[0] * 8; |
1364 i->total_production[1] = i->production_rate[1] * 8; |
1389 i->last_month_production[1] = i->production_rate[1] * 8; |
1365 |
1390 |
1366 if (!_generating_world) i->total_production[0] = i->total_production[1] = 0; |
1391 if (!_generating_world) i->last_month_production[0] = i->last_month_production[1] = 0; |
1367 |
1392 |
1368 i->prod_level = 0x10; |
1393 i->prod_level = 0x10; |
1369 |
1394 |
1370 do { |
1395 do { |
1371 TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); |
1396 TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); |
1450 SET_EXPENSES_TYPE(EXPENSES_OTHER); |
1475 SET_EXPENSES_TYPE(EXPENSES_OTHER); |
1451 |
1476 |
1452 indspec = GetIndustrySpec(p1); |
1477 indspec = GetIndustrySpec(p1); |
1453 |
1478 |
1454 /* Check if the to-be built/founded industry is available for this climate. */ |
1479 /* Check if the to-be built/founded industry is available for this climate. */ |
1455 if (!HASBIT(indspec->climate_availability, _opt_ptr->landscape)) return CMD_ERROR; |
1480 if (!indspec->enabled) { |
1481 return CMD_ERROR; |
|
1482 } |
|
1456 |
1483 |
1457 /* If the patch for raw-material industries is not on, you cannot build raw-material industries. |
1484 /* If the patch for raw-material industries is not on, you cannot build raw-material industries. |
1458 * Raw material industries are industries that do not accept cargo (at least for now) |
1485 * Raw material industries are industries that do not accept cargo (at least for now) |
1459 * Exclude the lumber mill (only "raw" industry that can be built) */ |
1486 * Exclude the lumber mill (only "raw" industry that can be built) */ |
1460 if (!_patches.build_rawmaterial_ind && |
1487 if (!_patches.build_rawmaterial_ind && |
1461 indspec->accepts_cargo[0] == CT_INVALID && |
1488 indspec->accepts_cargo[0] == CT_INVALID && |
1462 indspec->accepts_cargo[1] == CT_INVALID && |
1489 indspec->accepts_cargo[1] == CT_INVALID && |
1463 indspec->accepts_cargo[2] == CT_INVALID && |
1490 indspec->accepts_cargo[2] == CT_INVALID && |
1464 p1 != IT_LUMBER_MILL) { |
1491 !(indspec->behaviour & INDUSTRYBEH_CUT_TREES)) { |
1465 return CMD_ERROR; |
1492 return CMD_ERROR; |
1466 } |
1493 } |
1467 |
1494 |
1468 num = indspec->num_table; |
1495 num = indspec->num_table; |
1469 itt = indspec->table; |
1496 itt = indspec->table; |
1472 if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE); |
1499 if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE); |
1473 } while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1)); |
1500 } while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1)); |
1474 |
1501 |
1475 if (CreateNewIndustryHelper(tile, p1, flags, indspec, it) == NULL) return CMD_ERROR; |
1502 if (CreateNewIndustryHelper(tile, p1, flags, indspec, it) == NULL) return CMD_ERROR; |
1476 |
1503 |
1477 return (_eco->GetPrice(CEconomy::BUILD_INDUSTRY) >> 5) * indspec->cost_multiplier; |
1504 return (_eco->GetPrice(CEconomy::BUILD_INDUSTRY) >> 8) * indspec->cost_multiplier; |
1478 } |
1505 } |
1479 |
1506 |
1480 |
1507 |
1481 Industry *CreateNewIndustry(TileIndex tile, IndustryType type) |
1508 Industry *CreateNewIndustry(TileIndex tile, IndustryType type) |
1482 { |
1509 { |
1500 * @param type IndustryType of the desired industry |
1527 * @param type IndustryType of the desired industry |
1501 * @param amount of industries that need to be built */ |
1528 * @param amount of industries that need to be built */ |
1502 static void PlaceInitialIndustry(IndustryType type, int amount) |
1529 static void PlaceInitialIndustry(IndustryType type, int amount) |
1503 { |
1530 { |
1504 int num = _numof_industry_table[_opt.diff.number_industries][amount]; |
1531 int num = _numof_industry_table[_opt.diff.number_industries][amount]; |
1532 const IndustrySpec *ind_spc = GetIndustrySpec(type); |
|
1505 |
1533 |
1506 /* These are always placed next to the coastline, so we scale by the perimeter instead. */ |
1534 /* These are always placed next to the coastline, so we scale by the perimeter instead. */ |
1507 num = (type == IT_OIL_REFINERY || type == IT_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num); |
1535 num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num); |
1508 |
1536 |
1509 if (_opt.diff.number_industries != 0) { |
1537 if (_opt.diff.number_industries != 0) { |
1510 PlayerID old_player = _current_player; |
1538 PlayerID old_player = _current_player; |
1511 _current_player = OWNER_NONE; |
1539 _current_player = OWNER_NONE; |
1512 assert(num > 0); |
1540 assert(num > 0); |
1534 IndustryType it; |
1562 IndustryType it; |
1535 const IndustrySpec *ind_spc; |
1563 const IndustrySpec *ind_spc; |
1536 |
1564 |
1537 /* Find the total amount of industries */ |
1565 /* Find the total amount of industries */ |
1538 for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) { |
1566 for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) { |
1539 int num; |
|
1540 |
1567 |
1541 ind_spc = GetIndustrySpec(it); |
1568 ind_spc = GetIndustrySpec(it); |
1542 chance = ind_spc->appear_creation[_opt.landscape]; |
1569 if (ind_spc->enabled) { |
1543 |
1570 chance = ind_spc->appear_creation[_opt.landscape]; |
1544 if (chance > 0) { |
1571 if (chance > 0) { |
1545 /* once the chance of appearance is determind, it have to be scaled by |
1572 /* once the chance of appearance is determind, it have to be scaled by |
1546 * the difficulty level. The "chance" in question is more an index into |
1573 * the difficulty level. The "chance" in question is more an index into |
1547 * the _numof_industry_table,in fact */ |
1574 * the _numof_industry_table,in fact */ |
1548 num = _numof_industry_table[_opt.diff.number_industries][chance]; |
1575 int num = _numof_industry_table[_opt.diff.number_industries][chance]; |
1549 |
1576 |
1550 /* These are always placed next to the coastline, so we scale by the perimeter instead. */ |
1577 /* These are always placed next to the coastline, so we scale by the perimeter instead. */ |
1551 num = (it == IT_OIL_REFINERY || it == IT_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num); |
1578 num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num); |
1552 i += num; |
1579 i += num; |
1580 } |
|
1553 } |
1581 } |
1554 } |
1582 } |
1555 |
1583 |
1556 SetGeneratingWorldProgress(GWP_INDUSTRY, i); |
1584 SetGeneratingWorldProgress(GWP_INDUSTRY, i); |
1557 |
1585 |
1559 /* Once the number of industries has been determined, let's really create them. |
1587 /* Once the number of industries has been determined, let's really create them. |
1560 * The test for chance allows us to try create industries that are available only |
1588 * The test for chance allows us to try create industries that are available only |
1561 * for this landscape. |
1589 * for this landscape. |
1562 * @todo : Do we really have to pass chance as un-scaled value, since we've already |
1590 * @todo : Do we really have to pass chance as un-scaled value, since we've already |
1563 * processed that scaling above? No, don't think so. Will find a way. */ |
1591 * processed that scaling above? No, don't think so. Will find a way. */ |
1564 chance = GetIndustrySpec(it)->appear_creation[_opt.landscape]; |
1592 ind_spc = GetIndustrySpec(it); |
1565 if (chance > 0) PlaceInitialIndustry(it, chance); |
1593 if (ind_spc->enabled) { |
1594 chance = ind_spc->appear_creation[_opt.landscape]; |
|
1595 if (chance > 0) PlaceInitialIndustry(it, chance); |
|
1596 } |
|
1566 }; |
1597 }; |
1567 } |
1598 } |
1568 |
1599 |
1569 /* Change industry production or do closure */ |
1600 /* Change industry production or do closure */ |
1570 static void ExtChangeIndustryProduction(Industry *i) |
1601 static void ExtChangeIndustryProduction(Industry *i) |
1589 int mag; |
1620 int mag; |
1590 |
1621 |
1591 new_prod = old_prod = i->production_rate[j]; |
1622 new_prod = old_prod = i->production_rate[j]; |
1592 if (CHANCE16I(20, 1024, r)) |
1623 if (CHANCE16I(20, 1024, r)) |
1593 new_prod -= ((RandomRange(50) + 10) * old_prod) >> 8; |
1624 new_prod -= ((RandomRange(50) + 10) * old_prod) >> 8; |
1594 if (CHANCE16I(20 + (i->pct_transported[j] * 20 >> 8), 1024, r >> 16)) |
1625 if (CHANCE16I(20 + (i->last_month_pct_transported[j] * 20 >> 8), 1024, r >> 16)) |
1595 new_prod += ((RandomRange(50) + 10) * old_prod) >> 8; |
1626 new_prod += ((RandomRange(50) + 10) * old_prod) >> 8; |
1596 |
1627 |
1597 new_prod = clamp(new_prod, 0, 255); |
1628 new_prod = clamp(new_prod, 0, 255); |
1598 if (new_prod == old_prod) { |
1629 if (new_prod == old_prod) { |
1599 closeit = false; |
1630 closeit = false; |
1641 const IndustrySpec *indsp = GetIndustrySpec(i->type); |
1672 const IndustrySpec *indsp = GetIndustrySpec(i->type); |
1642 |
1673 |
1643 for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) { |
1674 for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) { |
1644 if (indsp->produced_cargo[j] != CT_INVALID) { |
1675 if (indsp->produced_cargo[j] != CT_INVALID) { |
1645 pct = 0; |
1676 pct = 0; |
1646 if (i->last_mo_production[j] != 0) { |
1677 if (i->this_month_production[j] != 0) { |
1647 i->last_prod_year = _cur_year; |
1678 i->last_prod_year = _cur_year; |
1648 pct = min(i->last_mo_transported[j] * 256 / i->last_mo_production[j], 255); |
1679 pct = min(i->this_month_transported[j] * 256 / i->this_month_production[j], 255); |
1649 } |
1680 } |
1650 i->pct_transported[j] = pct; |
1681 i->last_month_pct_transported[j] = pct; |
1651 |
1682 |
1652 i->total_production[j] = i->last_mo_production[j]; |
1683 i->last_month_production[j] = i->this_month_production[j]; |
1653 i->last_mo_production[j] = 0; |
1684 i->this_month_production[j] = 0; |
1654 |
1685 |
1655 i->total_transported[j] = i->last_mo_transported[j]; |
1686 i->last_month_transported[j] = i->this_month_transported[j]; |
1656 i->last_mo_transported[j] = 0; |
1687 i->this_month_transported[j] = 0; |
1657 refresh = true; |
1688 refresh = true; |
1658 } |
1689 } |
1659 } |
1690 } |
1660 |
1691 |
1661 if (refresh) |
1692 if (refresh) |
1741 if ((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE) |
1772 if ((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE) |
1742 only_decrease = true; |
1773 only_decrease = true; |
1743 |
1774 |
1744 if (only_decrease || CHANCE16(1, 3)) { |
1775 if (only_decrease || CHANCE16(1, 3)) { |
1745 /* If you transport > 60%, 66% chance we increase, else 33% chance we increase */ |
1776 /* If you transport > 60%, 66% chance we increase, else 33% chance we increase */ |
1746 if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1, 3)) { |
1777 if (!only_decrease && (i->last_month_pct_transported[0] > 153) != CHANCE16(1, 3)) { |
1747 /* Increase production */ |
1778 /* Increase production */ |
1748 if (i->prod_level != 0x80) { |
1779 if (i->prod_level != 0x80) { |
1749 byte b; |
1780 byte b; |
1750 |
1781 |
1751 i->prod_level <<= 1; |
1782 i->prod_level <<= 1; |
1822 void InitializeIndustries() |
1853 void InitializeIndustries() |
1823 { |
1854 { |
1824 CleanPool(&_Industry_pool); |
1855 CleanPool(&_Industry_pool); |
1825 AddBlockToPool(&_Industry_pool); |
1856 AddBlockToPool(&_Industry_pool); |
1826 |
1857 |
1827 _total_industries = 0; |
1858 ResetIndustryCounts(); |
1828 _industry_sort_dirty = true; |
1859 _industry_sort_dirty = true; |
1829 _industry_sound_tile = 0; |
1860 _industry_sound_tile = 0; |
1830 } |
1861 } |
1831 |
1862 |
1832 extern const TileTypeProcs _tile_type_industry_procs = { |
1863 extern const TileTypeProcs _tile_type_industry_procs = { |
1844 NULL, /* vehicle_enter_tile_proc */ |
1875 NULL, /* vehicle_enter_tile_proc */ |
1845 GetSlopeTileh_Industry, /* get_slope_tileh_proc */ |
1876 GetSlopeTileh_Industry, /* get_slope_tileh_proc */ |
1846 }; |
1877 }; |
1847 |
1878 |
1848 static const SaveLoad _industry_desc[] = { |
1879 static const SaveLoad _industry_desc[] = { |
1849 SLE_CONDVAR(Industry, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
1880 SLE_CONDVAR(Industry, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
1850 SLE_CONDVAR(Industry, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
1881 SLE_CONDVAR(Industry, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
1851 SLE_VAR(Industry, width, SLE_UINT8), |
1882 SLE_VAR(Industry, width, SLE_UINT8), |
1852 SLE_VAR(Industry, height, SLE_UINT8), |
1883 SLE_VAR(Industry, height, SLE_UINT8), |
1853 SLE_REF(Industry, town, REF_TOWN), |
1884 SLE_REF(Industry, town, REF_TOWN), |
1854 SLE_CONDNULL( 2, 2, 60), ///< used to be industry's produced_cargo |
1885 SLE_CONDNULL( 2, 2, 60), ///< used to be industry's produced_cargo |
1855 SLE_ARR(Industry, cargo_waiting, SLE_UINT16, 2), |
1886 SLE_ARR(Industry, cargo_waiting, SLE_UINT16, 2), |
1856 SLE_ARR(Industry, production_rate, SLE_UINT8, 2), |
1887 SLE_ARR(Industry, production_rate, SLE_UINT8, 2), |
1857 SLE_CONDNULL( 3, 2, 60), ///< used to be industry's accepts_cargo |
1888 SLE_CONDNULL( 3, 2, 60), ///< used to be industry's accepts_cargo |
1858 SLE_VAR(Industry, prod_level, SLE_UINT8), |
1889 SLE_VAR(Industry, prod_level, SLE_UINT8), |
1859 SLE_ARR(Industry, last_mo_production, SLE_UINT16, 2), |
1890 SLE_ARR(Industry, this_month_production, SLE_UINT16, 2), |
1860 SLE_ARR(Industry, last_mo_transported, SLE_UINT16, 2), |
1891 SLE_ARR(Industry, this_month_transported, SLE_UINT16, 2), |
1861 SLE_ARR(Industry, pct_transported, SLE_UINT8, 2), |
1892 SLE_ARR(Industry, last_month_pct_transported, SLE_UINT8, 2), |
1862 SLE_ARR(Industry, total_production, SLE_UINT16, 2), |
1893 SLE_ARR(Industry, last_month_production, SLE_UINT16, 2), |
1863 SLE_ARR(Industry, total_transported, SLE_UINT16, 2), |
1894 SLE_ARR(Industry, last_month_transported, SLE_UINT16, 2), |
1864 |
1895 |
1865 SLE_VAR(Industry, counter, SLE_UINT16), |
1896 SLE_VAR(Industry, counter, SLE_UINT16), |
1866 |
1897 |
1867 SLE_VAR(Industry, type, SLE_UINT8), |
1898 SLE_VAR(Industry, type, SLE_UINT8), |
1868 SLE_VAR(Industry, owner, SLE_UINT8), |
1899 SLE_VAR(Industry, owner, SLE_UINT8), |
1869 SLE_VAR(Industry, random_color, SLE_UINT8), |
1900 SLE_VAR(Industry, random_color, SLE_UINT8), |
1870 SLE_CONDVAR(Industry, last_prod_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30), |
1901 SLE_CONDVAR(Industry, last_prod_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30), |
1871 SLE_CONDVAR(Industry, last_prod_year, SLE_INT32, 31, SL_MAX_VERSION), |
1902 SLE_CONDVAR(Industry, last_prod_year, SLE_INT32, 31, SL_MAX_VERSION), |
1872 SLE_VAR(Industry, was_cargo_delivered, SLE_UINT8), |
1903 SLE_VAR(Industry, was_cargo_delivered, SLE_UINT8), |
1873 |
1904 |
1874 /* reserve extra space in savegame here. (currently 32 bytes) */ |
1905 /* reserve extra space in savegame here. (currently 32 bytes) */ |
1875 SLE_CONDNULL(32, 2, SL_MAX_VERSION), |
1906 SLE_CONDNULL(32, 2, SL_MAX_VERSION), |
1876 |
1907 |
1877 SLE_END() |
1908 SLE_END() |
1890 |
1921 |
1891 static void Load_INDY() |
1922 static void Load_INDY() |
1892 { |
1923 { |
1893 int index; |
1924 int index; |
1894 |
1925 |
1895 _total_industries = 0; |
1926 ResetIndustryCounts(); |
1896 |
1927 |
1897 while ((index = SlIterateArray()) != -1) { |
1928 while ((index = SlIterateArray()) != -1) { |
1898 Industry *i; |
1929 Industry *i; |
1899 |
1930 |
1900 if (!AddBlockIfNeeded(&_Industry_pool, index)) |
1931 if (!AddBlockIfNeeded(&_Industry_pool, index)) |
1901 error("Industries: failed loading savegame: too many industries"); |
1932 error("Industries: failed loading savegame: too many industries"); |
1902 |
1933 |
1903 i = GetIndustry(index); |
1934 i = GetIndustry(index); |
1904 SlObject(i, _industry_desc); |
1935 SlObject(i, _industry_desc); |
1905 |
1936 IncIndustryTypeCount(i->type); |
1906 _total_industries++; |
|
1907 } |
1937 } |
1908 } |
1938 } |
1909 |
1939 |
1910 extern const ChunkHandler _industry_chunk_handlers[] = { |
1940 extern const ChunkHandler _industry_chunk_handlers[] = { |
1911 { 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST}, |
1941 { 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST}, |