From 957f41517f228e4cfec06c8274ac7ece41033e7c Mon Sep 17 00:00:00 2001 From: Anselme Date: Tue, 13 Jan 2015 09:54:27 +0100 Subject: [PATCH] added alternative map generator, for testing purposes, type 'make anselme' to use it --- Makefile | 3 +++ generator_anselme.c | 65 +++++++++++++++++++++++++++++++++++++++++++++ main.c | 12 --------- 3 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 generator_anselme.c diff --git a/Makefile b/Makefile index 5d23f2e..0be5ad9 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,9 @@ main : main.o generator.o $(BINARY) : orange.o purple.o main.o generator.o $(CC) main.o generator.o orange.o purple.o -o $(BINARY) $(LIB) +anselme : orange.o purple.o main.o generator_anselme.o + $(CC) main.o generator_anselme.o orange.o purple.o -o $(BINARY) $(LIB) + %.o: %.c $(CC) -o $@ -c $< $(FLAGS) diff --git a/generator_anselme.c b/generator_anselme.c new file mode 100644 index 0000000..2ced43f --- /dev/null +++ b/generator_anselme.c @@ -0,0 +1,65 @@ +#include "main.h" + +// functions +int distance_manhattan(int x1,int y1, int x2, int y2); + +int absolute(int val); + +int min(int a, int b) +{ + return a < b ? a : b; +} + +int max(int a, int b) +{ + return a > b ? a : b; +} + +void create_map(t_pixel** map, t_team* teams, int w, int h){ + int i,j, k; + int r = (w/NB_TEAMS < h ? w/NB_TEAMS : h)/2; + + for(i=0; i r+15){ + map[i][j].type = rand()%8 ? ROCK : IRON_ORE; + }else if(l < r-15){ + map[i][j].type = rand()%15 ? GRASS : BERRIES; + }else{ + l = rand()%10; + map[i][j].type = l > 5 ? TREE : l ? GRASS : BERRIES; + } + } + } + } + } +} + +int distance_manhattan(int x1,int y1, int x2, int y2){ + return absolute(x1-x2) + absolute(y1-y2); +} + +int absolute(int val){ + return val > 0 ? val : -val; +} diff --git a/main.c b/main.c index af4cdd6..25bf36d 100755 --- a/main.c +++ b/main.c @@ -208,18 +208,6 @@ void generateImg(){ } } -int min(int a, int b) -{ - if (ab) return a; - else return b; -} - Uint32 getpixel(SDL_Surface *surface, int x, int y) { int bpp = surface->format->BytesPerPixel;