typedef struct RefActor{
double * x;
double * y;
char * name;
char * clonename;
//ect..
} RefActor;
RefActor * CurrentActor;
CurrentActor->x = &myActor->x;
CurrentActor->y = &myActor->y;
CurrentActor->name = &myActor->name;
CurrentActor->clonename = &myActor->clonename;
//ect..
//Structures
typedef struct WorldNode{
double wn_GameX;
double wn_GameY;
int wn_NodeX;
int wn_NodeY;
int wn_NodeID;
struct Tile *wn_pTile;
struct FloatingTile *wn_pFTile;
struct Creature *wn_pCreature;
struct Object *wn_pObject;
struct WorldNode *wn_pPrevYNode;
struct WorldNode *wn_pNextYNode;
struct WorldNode *wn_pPrevXNode;
struct WorldNode *wn_pNextXNode;
}WorldNode;
typedef struct Tile{
int t_Anim;
int t_Unique;
char t_CloneName[32];
char t_Name[27];
WorldNode* t_pWorldNode;
}Tile;
g_WorldNodeList[mh][mw]->wn_pTile = g_TileList[mh][mw]; // Doesn't work...
g_TileList[mh][mw]->t_pWorldNode = g_WorldNodeList[mh][mw]; // WORKS, same thing as above.
EvanBlack wrote:huh... well once my code is cleaned up and I remove unnecessary code maybe we can find the problem. I am sure it has something to do with the way I coded it but I am not sure.
Its strange how some things work in one ged but don't work in another.
//Structures
typedef struct WorldNode{
double wn_GameX;
double wn_GameY;
int wn_NodeX;
int wn_NodeY;
int wn_NodeID;
struct Tile *wn_pTile;
struct FloatingTile *wn_pFTile;
struct Creature *wn_pCreature;
struct Object *wn_pObject;
struct WorldNode *wn_pPrevYNode;
struct WorldNode *wn_pNextYNode;
struct WorldNode *wn_pPrevXNode;
struct WorldNode *wn_pNextXNode;
}WorldNode;
typedef struct Tile{
int t_Anim;
int t_Unique;
char t_CloneName[32];
char t_Name[27];
struct WorldNode* t_pWorldNode;
struct Tile *t_pPrevY;
struct Tile *t_pNextY;
struct Tile *t_pPrevX;
struct Tile *t_pNextX;
}Tile;
typedef struct FloatingTile{
int ft_Unique;
int ft_Anim;
char ft_CloneName[32];
char ft_Name[27];
WorldNode* ft_pWorldNode;
}FloatingTile;
typedef struct Object{
int o_Anim;
char o_CloneName[32];
char o_Name[27];
WorldNode* o_pWorldNode;
} Object;
typedef struct Creature{
int cr_Anim;
char cr_CloneName[32];
char cr_Name[27];
WorldNode* cr_pWorldNode;
} Creature;
//IF YOU CHANGE MAPSIZE[] THEN YOU HAVE TO CHANGE cMAPSIZE TO EQUAL THAT AMOUNT IN TILES
//ALSO YOU HAVE TO EDIT YOUR MAP!!
const int g_SQVIEWMAPWIDTH = 5;
const int g_SQVIEWMAPHEIGHT = 5;
const int g_ISOVIEWMAPWIDTH = 35;
const int g_ISOVIEWMAPHEIGHT = 35;
const int g_SQTILESIZE[2] = {100, 100};
const int g_ISOTILESIZE[2] = {64, 32}; //size of each tile. W x H
const int g_UNREACHABLETILE = 255; //The start of the unwalkable tile animation
int g_MapHeight = 0;
int g_MapWidth = 0;
int g_MapSize = 0; //Amount of tiles to be created
int g_Move[4];
//2D Pointer Arrays for Structures
WorldNode *** g_WorldNodeList;
Tile *** g_TileList;
//2D array
int ** g_Map;
Tile *g_FirstTile, *g_LastTile;
//MISC variables
int g_TileClicked;
int g_Saved = 0;
int g_TextCloneCount = 0;
int g_ToggleGUI = 1;
int g_ToggleTP = 0;
int g_ToggleOP = 0;
int g_CurrentSelectedTile = 0;
int g_CurrentSelectedObject = 0;
int g_setTile = 0;
//Function Declarations
//MOVE VIEW
void MoveFloorRight(int playerNode, int VIEW_MH, int VIEW_MW);
void MoveFloorLeft(int playerNode, int VIEW_MH, int VIEW_MW);
void MoveFloorDown(int playerNode, int VIEW_MH, int VIEW_MW);
void MoveFloorUp(int playerNode, int VIEW_MH, int VIEW_MW);
//MAP CREATION
void CreateMap();
void CreateMapIso();
int GenerateMap();
void initalizeTile(Tile *pTile);
void initalizeWorldNode(WorldNode *pWorldNode);
//MISC
int GetNodeIDFromXY(int x, int y);
int GetAIIDFromNode(int tID);
int GetAIIDFromXY(int x, int y);
void UpdateText(char string[40], int i);
void UpdateTileActor(Actor* pActor, Tile* pTile);
void FreeMemory();
void PlaceTile(Actor* pTile, int nID);
Actor* getTileByNode(int node);
void MoveTileToArray(Actor* myActor);
//This is all the game data variables.
///////////////////////////////////////////////////////////////////////////////////////////////
//ALL FUNCTIONS BELOW
///////////////////////////////////////////////////////////////////////////////////////////////
void CreateMapIso()
{
int mh=0;
int mw=0;
int tX = 0;
int tY = 0;
int tNum = 0;
int tH = g_ISOTILESIZE[1];
int tW = g_ISOTILESIZE[0];
char tAnim[10];
Actor* myActor = 0;
g_FirstTile = g_TileList[0][0];
for(mh = 0; mh < g_MapHeight; ++mh)
{
for(mw = 0; mw < g_MapWidth; ++mw)
{
tX = (tW/2 * mw)+ tW + (tW/2 * mh);
tY = (tH/2 * mh)-(tH/2 * mw);
g_WorldNodeList[mh][mw]->wn_GameX = tX;
g_WorldNodeList[mh][mw]->wn_GameY = tY;
g_WorldNodeList[mh][mw]->wn_NodeX = mw;
g_WorldNodeList[mh][mw]->wn_NodeY = mh;
g_WorldNodeList[mh][mw]->wn_NodeID = tNum;
//g_WorldNodeList[mh][mw]->wn_pTile = g_TileList[mh][mw]; //This is the erroring line
tNum = tNum +1;
}
}
for(mh = 0; mh < g_ISOVIEWMAPHEIGHT; ++mh)
{
for(mw = 0; mw < g_ISOVIEWMAPWIDTH; ++mw)
{
tX = (tW/2 * mw)+ tW + (tW/2 * mh);
tY = (tH/2 * mh)-(tH/2 * mw);
sprintf(tAnim, "tile%i", g_Map[mh][mw]);
myActor = CreateActor("ISO_FloorTile", tAnim, "no parent", "no path", tX, tY, true);
MoveTileToArray(myActor);
strcpy(g_TileList[mh][mw]->t_Name, myActor->name);
strcpy(g_TileList[mh][mw]->t_CloneName, myActor->clonename);
g_TileList[mh][mw]->t_Anim = g_Map[mh][mw];
g_TileList[mh][mw]->t_pWorldNode = g_WorldNodeList[mh][mw];
myActor->a_nX = g_TileList[mh][mw]->t_pWorldNode->wn_NodeX;
myActor->a_nY = g_TileList[mh][mw]->t_pWorldNode->wn_NodeY;
myActor->a_nID = g_TileList[mh][mw]->t_pWorldNode->wn_NodeID;
}
}
g_LastTile = g_TileList[mh-1][mw-1];
CreateActor("MiddlePoint", "Pointer", "no parent", "no path", 0, 0, true);
//ChangeParent("view", "MiddlePoint");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void MoveFloorRight(int playerNode, int VIEW_MH, int VIEW_MW)
{
Actor *MyActor;
Actor *Doodad;
int tID;
int i;
int o;
char tAnim[20];
for(i = (-VIEW_MH/2); i < VIEW_MH/2 +1; ++i)
{
tID = playerNode + (g_MapWidth * i) - VIEW_MW/2;
MyActor=getclone(getTileByNode(tID)->clonename);
tID = tID + VIEW_MW;
//UpdateTileActor();
//sprintf(tAnim, "tile%i", g_Map[g_NodeY[tID]][g_NodeX[tID]]);
//ChangeAnimation(MyActor->clonename,tAnim,NO_CHANGE);
}
}
void MoveFloorLeft(int playerNode, int VIEW_MH, int VIEW_MW)
{
Actor *MyActor;
Actor * Doodad;
int tID;
int i;
int o;
char tAnim[20];
for(i = (-VIEW_MH/2); i < VIEW_MH/2 +1; ++i)
{
tID = playerNode + (g_MapWidth * i) + VIEW_MW/2;
}
}
void MoveFloorDown(int playerNode, int VIEW_MH, int VIEW_MW)
{
Actor *MyActor;
Actor * Doodad;
int tID;
int i;
int o;
char tAnim[20];
for(i = (-VIEW_MW/2); i < VIEW_MW/2 +1; ++i)
{
tID = playerNode + (g_MapWidth*(-VIEW_MH/2)) + i;
}
}
void MoveFloorUp(int playerNode, int VIEW_MH, int VIEW_MW)
{
Actor *MyActor;
Actor * Doodad;
int tID;
int i;
int o;
char tAnim[20];
for(i = (-VIEW_MW/2); i < VIEW_MW/2 +1; ++i)
{
tID = playerNode - (g_MapWidth*(-VIEW_MH/2)) + i;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
int GenerateMap()
{
int i;
int a;
if(!g_MapHeight || !g_MapWidth || g_MapSize)
{
return 1;
}
g_MapSize = g_MapHeight * g_MapWidth;
//Allocate memory for 2D array g_Map
g_Map = malloc(g_MapHeight * sizeof(int *));
if(g_Map == NULL)
{
UpdateText("ERROR: OUT OF MEMORY", 0);
g_MapSize = 0;
return 1;
}
for(i = 0; i < g_MapHeight; i++)
{
g_Map[i] = malloc(g_MapWidth * sizeof(int));
if(g_Map[i] == NULL)
{
UpdateText("ERROR: OUT OF MEMORY", 0);
g_MapSize = 0;
return 1;
}
}
//Allocate memory for 2D array g_WorldNodeList
g_WorldNodeList = malloc(g_MapHeight * sizeof(WorldNode **));
if(g_WorldNodeList == NULL)
{
UpdateText("ERROR: OUT OF MEMORY", 0);
return 1;
}
for(i = 0; i < g_MapHeight; i++)
{
g_WorldNodeList[i] = malloc(g_MapWidth * sizeof(WorldNode*));
if(g_WorldNodeList[i] == NULL)
{
UpdateText("ERROR: OUT OF MEMORY", 0);
return 1;
}
}
for(i = 0; i < g_MapHeight; i++)
{
for(a = 0; a < g_MapWidth; a++)
{
g_WorldNodeList[i][a] = (WorldNode *)malloc(sizeof(WorldNode));
if(g_WorldNodeList[i][a] == NULL)
{
UpdateText("ERROR: OUT OF MEMORY", 0);
return 1;
}
initalizeWorldNode(g_WorldNodeList[i][a]);
}
}
//Allocate memory for 2D array g_TileList
g_TileList = malloc(g_MapHeight * sizeof(Tile **));
if(g_TileList == NULL)
{
UpdateText("ERROR: OUT OF MEMORY", 0);
return 1;
}
for(i = 0; i < g_MapHeight; i++)
{
g_TileList[i] = malloc(g_MapWidth * sizeof(Tile*));
if(g_TileList[i] == NULL)
{
UpdateText("ERROR: OUT OF MEMORY", 0);
return 1;
}
}
for(i = 0; i < g_MapHeight; i++)
{
for(a = 0; a < g_MapWidth; a++)
{
g_TileList[i][a] = (Tile *)malloc(sizeof(Tile));
if(g_TileList[i][a] == NULL)
{
UpdateText("ERROR: OUT OF MEMORY", 0);
return 1;
}
initalizeTile(g_TileList[i][a]);
}
}
UpdateText("GENERATED MAP, NUMBER OF TILES:", g_MapSize);
return 0; //If failed return 1; If completed return 0;
}
void FreeMemory()
{
int i;
int a;
for(i = 0; i < g_MapHeight; i++)
{
free(g_Map[i]);
}
for(i = 0; i < g_MapHeight; i++)
{
for(a = 0; a < g_MapWidth; a++)
{
free(g_WorldNodeList[i][a]);
}
free(g_WorldNodeList[i]);
}
for(i = 0; i < g_MapHeight; i++)
{
for(a = 0; a < g_MapWidth; a++)
{
free(g_TileList[i][a]);
}
free(g_TileList[i]);
}
free(g_TileList);
free(g_WorldNodeList);
free(g_Map);
UpdateText("Memory Freed", 0);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void UpdateText(char string[40], int i)
{
Actor* NewText;
Actor* OldText;
char buffer[20];
sprintf(buffer, "UPDATESTATUSTEXT.%i", g_TextCloneCount);
OldText = getclone(buffer);
++g_TextCloneCount;
NewText = CreateActor("UPDATESTATUSTEXT", "", "view", "no path", OldText->x, OldText->y+15, false);
if(!i)
{
strcpy(NewText->text, string);
}
else
{
sprintf(NewText->text, "%s %i", string, i);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/*
void PlaceTile(Actor* pTile, int nID)
{
char tAnim[20];
sprintf(tAnim, "tile%i", g_CurrentSelectedTile );
ChangeAnimation(pTile->clonename,tAnim,NO_CHANGE);
if(nID != -1){ g_Map[g_NodeY[nID]][g_NodeX[nID]] = g_CurrentSelectedTile; }
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////////
void initalizeTile(Tile *pTile)
{
pTile->t_Anim = 0;
pTile->t_Unique = 0;
strcpy(pTile->t_CloneName,"\0");
strcpy(pTile->t_Name, "\0");
pTile->t_pWorldNode = NULL;
pTile->t_pPrevY = NULL;
pTile->t_pNextY = NULL;
pTile->t_pPrevX = NULL;
pTile->t_pNextX = NULL;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void initalizeWorldNode(WorldNode *pWorldNode)
{
pWorldNode->wn_GameX = 0;
pWorldNode->wn_GameY = 0;
pWorldNode->wn_NodeX = 0;
pWorldNode->wn_NodeY = 0;
pWorldNode->wn_NodeID = 0;
pWorldNode->wn_pTile = NULL;
pWorldNode->wn_pFTile = NULL;
pWorldNode->wn_pCreature = NULL;
pWorldNode->wn_pObject = NULL;
pWorldNode->wn_pPrevYNode = NULL;
pWorldNode->wn_pNextYNode = NULL;
pWorldNode->wn_pPrevXNode = NULL;
pWorldNode->wn_pNextXNode = NULL;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void UpdateTileActor(Actor* pActor, Tile* pTile)
{
pActor->x = pTile->t_pWorldNode->wn_GameX;
pActor->y = pTile->t_pWorldNode->wn_GameY;
pActor->a_nX = pTile->t_pWorldNode->wn_NodeX;
pActor->a_nY = pTile->t_pWorldNode->wn_NodeY;
pActor->a_nID = pTile->t_pWorldNode->wn_NodeID;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void InitGame()
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//CREATED BY EVAN BLACK, 2011
// www.game-editor.com/forum USERNAME: EVANBLACK
g_WorldNodeList[mh][mw]->wn_NodeID = tNum;
//g_WorldNodeList[mh][mw]->wn_pTile = g_TileList[mh][mw]; //This is the erroring line.
tNum = tNum +1;
//Structures
struct WorldNode;
struct Tile;
Users browsing this forum: No registered users and 1 guest