src/industry_cmd.cpp
branch0.6
changeset 10323 57d8fd25473e
parent 9152 35fa006cf0f0
child 10655 b862a4add8b0
--- a/src/industry_cmd.cpp	Mon Mar 31 22:09:27 2008 +0000
+++ b/src/industry_cmd.cpp	Thu Apr 24 11:48:09 2008 +0000
@@ -25,7 +25,6 @@
 #include "newgrf_industries.h"
 #include "newgrf_industrytiles.h"
 #include "newgrf_callbacks.h"
-#include "misc/autoptr.hpp"
 #include "autoslope.h"
 #include "transparency.h"
 #include "water.h"
@@ -1025,6 +1024,9 @@
 
 			if (cut) ChopLumberMillTrees(i);
 		}
+
+		TriggerIndustry(i, INDUSTRY_TRIGGER_INDUSTRY_TICK);
+		StartStopIndustryTileAnimation(i, IAT_INDUSTRY_TICK);
 	}
 }
 
@@ -1046,8 +1048,6 @@
 	if (_game_mode == GM_EDITOR) return;
 
 	FOR_ALL_INDUSTRIES(i) {
-		TriggerIndustry(i, INDUSTRY_TRIGGER_INDUSTRY_TICK);
-		StartStopIndustryTileAnimation(i, IAT_INDUSTRY_TICK);
 		ProduceIndustryGoods(i);
 	}
 }
@@ -1583,17 +1583,19 @@
 	if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL;
 	if (!CheckSuitableIndustryPos(tile)) return NULL;
 
-	Industry *i = new Industry(tile);
-	if (i == NULL) return NULL;
-	AutoPtrT<Industry> i_auto_delete = i;
+	if (!Industry::CanAllocateItem()) return NULL;
 
 	if (flags & DC_EXEC) {
+		Industry *i = new Industry(tile);
 		if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type);
 		DoCreateNewIndustry(i, tile, type, it, itspec_index, t, OWNER_NONE);
-		i_auto_delete.Detach();
+
+		return i;
 	}
 
-	return i;
+	/* We need to return a non-NULL pointer to tell we have created an industry.
+	 * However, we haven't created a real one (no DC_EXEC), so return a fake one. */
+	return GetIndustry(0);
 }
 
 /** Build/Fund an industry