From f4f7f1154d69334bc86cad5946e74c6d7096cfb2 Mon Sep 17 00:00:00 2001
From: jarod42 <>
Date: Mon, 15 Mar 2004 01:47:39 +0000
Subject: [PATCH] correct bug when spell or autocast is not defined

---
 src/unit/script_unittype.cpp | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/unit/script_unittype.cpp b/src/unit/script_unittype.cpp
index 38a5f42ec..3328b9d03 100644
--- a/src/unit/script_unittype.cpp
+++ b/src/unit/script_unittype.cpp
@@ -639,18 +639,18 @@ local int CclDefineUnitType(lua_State* l)
 
 			}
 			for (k = 0; k < subargs; ++k) {
-				int id;
+				const SpellType *spell;
 
 				lua_rawgeti(l, -1, k + 1);
 				value = LuaToString(l, -1);
-				id = SpellTypeByIdent(value)->Slot;
-				lua_pop(l, 1);
+				spell = SpellTypeByIdent(value);
 				DebugLevel3Fn("%d \n" _C_ id);
-				if (id == -1) {
+				if (spell == NULL) {
 					lua_pushfstring(l, "Unknown spell type: %s", value);
 					lua_error(l);
 				}
-				type->CanCastSpell[id] = 1;
+				lua_pop(l, 1);
+				type->CanCastSpell[spell->Slot] = 1;
 			}
 		} else if (!strcmp(value, "AutoCastActive")) {
 			if (!lua_istable(l, -1)) {
@@ -672,18 +672,22 @@ local int CclDefineUnitType(lua_State* l)
 
 			}
 			for (k = 0; k < subargs; ++k) {
-				int id;
+				const SpellType *spell;
 
 				lua_rawgeti(l, -1, k + 1);
 				value = LuaToString(l, -1);
-				id = SpellTypeByIdent(value)->Slot;
-				lua_pop(l, 1);
+				spell = SpellTypeByIdent(value);
 				DebugLevel3Fn("%d \n" _C_ id);
-				if (id == -1) {
-					lua_pushfstring(l, "Unknown spell type: %s", value);
+				if (spell == NULL) {
+					lua_pushfstring(l, "AutoCastActive : Unknown spell type: %s", value);
 					lua_error(l);
 				}
-				type->AutoCastActive[id] = 1;
+				if (!spell->AutoCast) {
+					lua_pushfstring(l, "AutoCastActive : Define autocast method for %s.", value);
+					lua_error(l);
+				}
+				lua_pop(l, 1);
+				type->AutoCastActive[spell->Slot] = 1;
 			}
 		} else if (!strcmp(value, "CanTargetFlag")) {
 			//