(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
authorrubidium
Sun, 08 Jul 2007 19:54:51 +0000
changeset 7205 0a6d45455ae5
parent 7204 ef8181ff2c1e
child 7206 fbba6cb67bc8
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
src/industry_cmd.cpp
src/newgrf_callbacks.h
--- a/src/industry_cmd.cpp	Sun Jul 08 18:57:00 2007 +0000
+++ b/src/industry_cmd.cpp	Sun Jul 08 19:54:51 2007 +0000
@@ -929,11 +929,6 @@
 	if (tile != INVALID_TILE) PlantFarmField(tile, i->index);
 }
 
-static void MaybePlantFarmField(const Industry *i)
-{
-	if (CHANCE16(1, 8)) PlantRandomFarmField(i);
-}
-
 /**
  * Search callback function for ChopLumberMillTrees
  * @param tile to test
@@ -998,10 +993,23 @@
 		i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + i->production_rate[0]);
 		i->produced_cargo_waiting[1] = min(0xffff, i->produced_cargo_waiting[1] + i->production_rate[1]);
 
-		if (indbehav & INDUSTRYBEH_PLANT_FIELDS) {
-			MaybePlantFarmField(i);
-		} else if ((indbehav & INDUSTRYBEH_CUT_TREES) && (i->counter & 0x1FF) == 0) {
-			ChopLumberMillTrees(i);
+		if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
+			bool plant;
+			if (HASBIT(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) {
+				plant = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->xy) != 0);
+			} else {
+				plant = CHANCE16(1, 8);
+			}
+
+			if (plant) PlantRandomFarmField(i);
+		}
+		if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) {
+			bool cut = ((i->counter & 0x1FF) == 0);
+			if (HASBIT(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) {
+				cut = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, 0, 1, i, i->type, i->xy) != 0);
+			}
+
+			if (cut) ChopLumberMillTrees(i);
 		}
 	}
 }
--- a/src/newgrf_callbacks.h	Sun Jul 08 18:57:00 2007 +0000
+++ b/src/newgrf_callbacks.h	Sun Jul 08 19:54:51 2007 +0000
@@ -153,7 +153,7 @@
 	CBID_INDUSTRY_WINDOW_MORE_TEXT  = 0x3A,
 
 	/* Called to determine industry special effects */
-	CBID_INDUSTRY_SPECIAL_EFFECT    = 0x3B, // not yet implemented
+	CBID_INDUSTRY_SPECIAL_EFFECT    = 0x3B,
 
 	/* Called to determine if industry can alter the ground below industry tile */
 	CBID_INDUSTRY_AUTOSLOPE         = 0x3C, // not yet implemented