liblashgame

Pathfinder and path decision making library for 2D tile game
git clone git://holbrook.no/liblashgame.git
Log | Files | Refs

common.c (1034B)


      1 #include <stdlib.h>
      2 #include <stdio.h>
      3 #include <time.h>
      4 
      5 #include "liblashgame/lash_game_map.h"
      6 
      7 #include "common.h"
      8 
      9 void fillMapRandom(lash_map_simple_t *map, lash_map_simple_layer_item_t max_value) {
     10 	int i;
     11 	time_t t;
     12 	
     13 	srand((unsigned) time(&t));
     14 	
     15 	for (i = 0; i < *map->w * *map->h; i++) {
     16 		(map->layer_path + i)->val = rand() % max_value;
     17 	}
     18 }
     19 
     20 void dumpMapPathLayer(lash_map_simple_t *map, unsigned int unitsize, int start, int target, int position) {
     21 
     22 	
     23 	lash_game_coords_t tmpcoords;
     24 	lash_game_map_index_t tmpidx;
     25 	for (tmpcoords.y = 0; tmpcoords.y < *map->h; tmpcoords.y++) {
     26 		for (tmpcoords.x = 0; tmpcoords.x < *map->w; tmpcoords.x++) {
     27 			lash_cartesianToIndex(&tmpidx, map->w, map->h, &unitsize, &tmpcoords);
     28 			if (tmpidx == start) {
     29 				printf("XX ");
     30 			} else if (tmpidx == target) {
     31 				printf("-- ");
     32 			} else if (tmpidx == position) {
     33 				printf("?? ");
     34 			} else {
     35 				printf("%02i ", (int)lash_mapSimpleLayerPeek(map->layer_path, tmpidx));
     36 			}
     37 		}
     38 		printf("\n");
     39 	}
     40 	printf("\n");	
     41 	fflush(stdout);
     42 }