168 lines
3.4 KiB
C
168 lines
3.4 KiB
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include "fileHandler.h"
|
|
#include "logHelper.h"
|
|
#include "main.h"
|
|
#include "arenaEngine.h"
|
|
|
|
|
|
/*
|
|
* Arena generate functions
|
|
*/
|
|
TILE* createTileList(void) {
|
|
TILE* origin = NULL;
|
|
|
|
return origin;
|
|
}
|
|
|
|
ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) {
|
|
ARENA_H_TILE* tile_h = NULL;
|
|
|
|
if (prevHTile == NULL) {
|
|
tile_h = calloc(1,sizeof(ARENA_H_TILE)); //Using calloc because of resetting all memory allocated to 0
|
|
tile_h->type_id = 0;
|
|
//tile_h->playerOnTile = NULL;
|
|
tile_h->nextRow = NULL;
|
|
tile_h->nextColumn = NULL;
|
|
} else if (prevHTile != NULL) {
|
|
tile_h = calloc(1,sizeof(ARENA_H_TILE));
|
|
prevHTile->nextRow = tile_h;
|
|
tile_h->type_id = 0;
|
|
//tile_h->playerOnTile = NULL;
|
|
tile_h->nextRow = NULL;
|
|
tile_h->nextColumn = NULL;
|
|
}
|
|
|
|
return tile_h;
|
|
}
|
|
|
|
ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
|
|
ARENA_W_TILE* tile_w = NULL;
|
|
|
|
if (prevHTile != NULL && prevWTile == NULL) {
|
|
tile_w = calloc(1,sizeof(ARENA_W_TILE));
|
|
prevHTile->nextColumn = tile_w;
|
|
tile_w->type_id = 0;
|
|
//tile_w->playerOnTile = NULL;
|
|
tile_w->nextColumn = NULL;
|
|
|
|
return tile_w;
|
|
} else if (prevHTile == NULL && prevWTile != NULL) {
|
|
tile_w = calloc(1,sizeof(ARENA_W_TILE));
|
|
prevWTile->nextColumn = tile_w;
|
|
tile_w->type_id = 0;
|
|
//tile_w->playerOnTile = NULL;
|
|
tile_w->nextColumn = NULL;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
ARENA_H_TILE* genNewArena(int size_h, int size_w) {
|
|
ARENA_H_TILE* arenaOrigin = NULL;
|
|
ARENA_H_TILE* TmpCursor_h = NULL;
|
|
ARENA_W_TILE* TmpCursor_w = NULL;
|
|
int i,j;
|
|
|
|
for(i=0;i<size_h;i++){
|
|
if (i==0) {
|
|
arenaOrigin = createHTile(NULL);
|
|
TmpCursor_h = arenaOrigin;
|
|
} else {
|
|
TmpCursor_h = createHTile(TmpCursor_h);
|
|
}
|
|
|
|
for(j=0;j<size_w;j++){
|
|
if (j==0) {
|
|
TmpCursor_w = createWTile(TmpCursor_h, NULL);
|
|
} else {
|
|
createWTile(NULL, TmpCursor_w);
|
|
}
|
|
|
|
if (j!=0) TmpCursor_w = TmpCursor_w->nextColumn;
|
|
}
|
|
}
|
|
|
|
return arenaOrigin;
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* Arena delete functions
|
|
*/
|
|
void deleteWTile(ARENA_W_TILE* WTile) {
|
|
if (WTile->nextColumn != NULL) {
|
|
deleteWTile(WTile->nextColumn);
|
|
}
|
|
|
|
free(WTile);
|
|
}
|
|
|
|
void deleteHTile(ARENA_H_TILE* HTile) {
|
|
if (HTile->nextRow != NULL) {
|
|
deleteHTile(HTile->nextRow);
|
|
}
|
|
|
|
deleteWTile(HTile->nextColumn);
|
|
free(HTile);
|
|
}
|
|
|
|
void deleteArena(ARENA_H_TILE* arena) {
|
|
deleteHTile(arena);
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* Arena status functions
|
|
*/
|
|
int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y) {
|
|
int type_id = -1;
|
|
int i;
|
|
|
|
if (coord_x > A_WIDTH || coord_y > A_HEIGHT) return -1;
|
|
|
|
if (coord_y == 0) {
|
|
ARENA_H_TILE* tile_h = NULL;
|
|
|
|
tile_h = arena;
|
|
if (coord_x != 0) {
|
|
for (i=0;i<coord_x;i++) {
|
|
tile_h = arena->nextRow;
|
|
}
|
|
}
|
|
|
|
type_id = tile_h->type_id;
|
|
} else {
|
|
ARENA_W_TILE* tile_w = NULL;
|
|
ARENA_H_TILE* tile_h = NULL;
|
|
|
|
tile_h = arena;
|
|
if (coord_x != 0) {
|
|
for (i=0;i<coord_x;i++) {
|
|
tile_h = tile_h->nextRow;
|
|
}
|
|
}
|
|
|
|
tile_w = tile_h->nextColumn;
|
|
if (coord_y != 0) {
|
|
for (i=0;i<coord_y;i++) {
|
|
tile_w = tile_w->nextColumn;
|
|
}
|
|
}
|
|
|
|
type_id = tile_w->type_id;
|
|
}
|
|
|
|
return type_id;
|
|
}
|
|
|
|
int isPlayerAdjacent(PLAYER* p1, PLAYER* p2) {
|
|
int adjPlayer = -1;
|
|
|
|
if ((p1->PositionX-1 || p1->PositionX+1) == p2->PositionX && (p1->PositionY-1 || p1->PositionY+1) == p2->PositionY) adjPlayer = 1;
|
|
|
|
return adjPlayer;
|
|
}
|