From 0453d5ae6b4f566ada113512b841464099e89edd Mon Sep 17 00:00:00 2001
From: jarod42 <>
Date: Thu, 14 Oct 2004 16:30:15 +0000
Subject: [PATCH] CleanUp

---
 src/include/campaign.h      |  2 --
 src/include/construct.h     |  7 +------
 src/include/cursor.h        |  7 +------
 src/include/missile.h       |  4 ----
 src/stratagus/construct.cpp |  6 ------
 src/ui/script_ui.cpp        | 10 +++-------
 src/video/cursor.cpp        | 17 +++++++++--------
 7 files changed, 14 insertions(+), 39 deletions(-)

diff --git a/src/include/campaign.h b/src/include/campaign.h
index f8723da20..71fd1cae7 100644
--- a/src/include/campaign.h
+++ b/src/include/campaign.h
@@ -117,8 +117,6 @@ struct _campaign_chapter_ {
 **  Campaign structure.
 */
 typedef struct _campaign_ {
-	const void* OType;  ///< Object type (future extensions)
-
 	char* Ident;    ///< Unique identifier
 	char* Name;     ///< Campaign name
 	int   Players;  ///< Campaign for X players
diff --git a/src/include/construct.h b/src/include/construct.h
index 0ecba9181..beca22fff 100644
--- a/src/include/construct.h
+++ b/src/include/construct.h
@@ -51,10 +51,6 @@
 **
 **  The construction structure members:
 **
-**  Construction::OType
-**
-**    Object type (future extensions).
-**
 **  Construction::Ident
 **
 **    Unique identifier of the construction, used to reference it in
@@ -125,7 +121,6 @@ typedef struct _construction_frame_ {
 
 	/// Construction shown during construction of a building
 typedef struct _construction_ {
-	const void* OType;  ///< Object type (future extensions)
 	char*       Ident;  ///< construction identifier
 	struct {
 		char* File;    ///< sprite file
@@ -152,7 +147,7 @@ typedef struct _construction_ {
 --  Variables
 ----------------------------------------------------------------------------*/
 
-extern const char ConstructionType[];  ///< Construction type
+//extern const char ConstructionType[];  ///< Construction type
 
 /*----------------------------------------------------------------------------
 --  Functions
diff --git a/src/include/cursor.h b/src/include/cursor.h
index 1ff334770..3170ad301 100644
--- a/src/include/cursor.h
+++ b/src/include/cursor.h
@@ -52,10 +52,6 @@
 **
 **  The cursor-type structure members:
 **
-**  CursorType::OType
-**
-**    Object type (future extensions).
-**
 **  CursorType::Ident
 **
 **    Unique identifier of the cursor, used to reference it in config
@@ -137,7 +133,6 @@ typedef struct _cursor_type_ CursorType;
 
 	/// Private type which specifies the cursor-type
 struct _cursor_type_ {
-	const void* OType;  ///< Object type (future extensions)
 	char*       Ident;  ///< Identifier to reference it
 	char*       Race;   ///< Race name
 
@@ -170,8 +165,8 @@ typedef enum _cursor_states_ {
 --  Variables
 ----------------------------------------------------------------------------*/
 
-extern const char CursorTypeType[];  ///< cursor-type type
 extern CursorType* Cursors;          ///< cursor-types description
+extern int CursorMax;                ///< Number of cursor.
 
 extern CursorStates CursorState;  ///< current cursor state (point,...)
 extern int CursorAction;          ///< action for selection
diff --git a/src/include/missile.h b/src/include/missile.h
index d3857c1cc..a8a46cda0 100644
--- a/src/include/missile.h
+++ b/src/include/missile.h
@@ -52,10 +52,6 @@
 **
 **  The missile-type structure members:
 **
-**  MissileType::OType
-**
-**  Object type (future extensions).
-**
 **  MissileType::Ident
 **
 **    Unique identifier of the missile-type, used to reference it in
diff --git a/src/stratagus/construct.cpp b/src/stratagus/construct.cpp
index e64fcc059..fba048d05 100644
--- a/src/stratagus/construct.cpp
+++ b/src/stratagus/construct.cpp
@@ -49,11 +49,6 @@
 --  Variables
 ----------------------------------------------------------------------------*/
 
-/**
-**  Construction type definition
-*/
-const char ConstructionType[] = "construction";
-
 /**
 **  Constructions.
 */
@@ -295,7 +290,6 @@ static int CclDefineConstruction(lua_State* l)
 		Constructions[i + 1] = NULL;
 		construction = Constructions[i];
 	}
-	construction->OType = ConstructionType;
 	construction->Ident = str;
 
 	//
diff --git a/src/ui/script_ui.cpp b/src/ui/script_ui.cpp
index 17bdff21b..e2e725f4a 100644
--- a/src/ui/script_ui.cpp
+++ b/src/ui/script_ui.cpp
@@ -55,7 +55,6 @@
 --  Variables
 ----------------------------------------------------------------------------*/
 
-
 char* ClickMissile;              ///< FIXME:docu
 char* DamageMissile;             ///< FIXME:docu
 
@@ -454,7 +453,7 @@ static int CclDefineCursor(lua_State* l)
 	ct = NULL;
 	i = 0;
 	if (Cursors) {
-		for (; Cursors[i].OType; ++i) {
+		for (; i < CursorMax; ++i) {
 			//
 			//  Race not same, not found.
 			//
@@ -475,12 +474,9 @@ static int CclDefineCursor(lua_State* l)
 	//  Not found, make a new slot.
 	//
 	if (!ct) {
-		ct = calloc(i + 2, sizeof(CursorType));
-		memcpy(ct, Cursors, sizeof(CursorType) * i);
-		free(Cursors);
-		Cursors = ct;
+		CursorMax++;
+		Cursors = realloc(Cursors, CursorMax * sizeof (*Cursors));
 		ct = &Cursors[i];
-		ct->OType = CursorTypeType;
 		ct->Ident = strdup(name);
 		ct->Race = race ? strdup(race) : NULL;
 	}
diff --git a/src/video/cursor.cpp b/src/video/cursor.cpp
index 6bd4d604f..c5f28d47e 100644
--- a/src/video/cursor.cpp
+++ b/src/video/cursor.cpp
@@ -59,7 +59,7 @@
 /**
 **  Cursor-type type definition
 */
-const char CursorTypeType[] = "cursor-type";
+int CursorMax = 0; ///< Number of cursor.
 
 /**
 **  Define cursor-types.
@@ -122,7 +122,7 @@ void LoadCursors(const char* race)
 	//
 	//  Load the graphics
 	//
-	for (i = 0; Cursors[i].OType; ++i) {
+	for (i = 0; i < CursorMax; ++i) {
 		//
 		//  Only load cursors of this race or universal cursors.
 		//
@@ -148,14 +148,14 @@ void LoadCursors(const char* race)
 */
 CursorType* CursorTypeByIdent(const char* ident)
 {
-	CursorType* cursortype;
+	int i;  // iterator.
 
-	for (cursortype = Cursors; cursortype->OType; ++cursortype) {
-		if (strcmp(cursortype->Ident, ident)) {
+	for (i = 0; i < CursorMax; i++) {
+		if (strcmp(Cursors[i].Ident, ident)) {
 			continue;
 		}
-		if (!cursortype->Race || cursortype->G) {
-			return cursortype;
+		if (!Cursors[i].Race || Cursors[i].G) {
+			return Cursors + i;
 		}
 	}
 	DebugPrint("Cursor `%s' not found, please check your code.\n" _C_ ident);
@@ -406,13 +406,14 @@ void CleanCursors(void)
 {
 	int i;
 
-	for (i = 0; Cursors[i].OType; ++i) {
+	for (i = 0; i < CursorMax; ++i) {
 		FreeGraphic(Cursors[i].G);
 		free(Cursors[i].Ident);
 		free(Cursors[i].Race);
 	}
 	free(Cursors);
 	Cursors = NULL;
+	CursorMax = 0;
 
 	CursorBuilding = 0;
 	GameCursor = 0;