getfreespace.c (1447B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #include "liblashgame/lash_game_path_simple.h" 5 #include "liblashgame/lash_game_map.h" 6 7 #include "common.h" 8 9 int main() { 10 11 int i; 12 13 unsigned int w = 10; 14 unsigned int h = 10; 15 16 int freespacecount = 0; 17 18 lash_map_simple_t map; 19 20 lash_path_simple_obstacle_t *obstacles; 21 unsigned char obstaclecount; 22 23 unsigned int *indices; 24 25 if (lash_mapSimpleInit(&map, &w, &h) == NULL) 26 return 1; 27 28 fillMapRandom(&map, 3); 29 dumpMapPathLayer(&map, 1, -1, -1, -1); 30 31 obstacles = (lash_path_simple_obstacle_t*)malloc(sizeof(lash_path_simple_obstacle_t) * 3); 32 if (obstacles == NULL) 33 return 1; 34 35 obstacles->val = 0; 36 obstacles->modifier = LASH_GAME_PATH_SIMPLE_OBSTACLE_MODIFIER_NONE; 37 (obstacles+1)->val = 1; 38 (obstacles+1)->modifier = LASH_GAME_PATH_SIMPLE_OBSTACLE_MODIFIER_FULL; 39 (obstacles+2)->val = 2; 40 (obstacles+2)->modifier = LASH_GAME_PATH_SIMPLE_OBSTACLE_MODIFIER_HALF; 41 42 obstaclecount = 3; 43 44 indices = (unsigned int*)malloc(sizeof(unsigned int) * *(map.w) * *(map.h)); 45 if (indices == NULL) { 46 if (obstacles != NULL) 47 free(obstacles); 48 return 1; 49 } 50 51 freespacecount = lash_pathSimpleCompileFreeSpaces(&indices, *(map.w) * *(map.h), map.layer_path, *(map.w) * *(map.h), obstacles, obstaclecount); 52 53 printf("Found %d free spaces: ", freespacecount); 54 55 for (i = 0; i < freespacecount; i++) { 56 printf("%02d ", *(indices + i)); 57 } 58 printf("\n"); 59 60 free(indices); 61 free(obstacles); 62 63 return 0; 64 }