git » fp-git.git » commit 12203cf

new wall randomization seed storing system

author ecalot
2005-01-04 03:16:25 UTC
committer ecalot
2005-01-04 03:16:25 UTC
parent 2de35a68d1058b8b322ce2d4c0458c6910928432

new wall randomization seed storing system

FP/src/Makefile +12 -7
FP/src/conf/awk/walls_conf.awk +215 -0
FP/src/conf/walls.conf +82 -0
FP/src/include/room.h +0 -16
FP/src/include/walls.h +41 -0
FP/src/ker/room.c +31 -27
FP/src/res/tiles.c +1 -6
FP/src/res/walls.c +47 -0

diff --git a/FP/src/Makefile b/FP/src/Makefile
index 0587764..f3fe810 100644
--- a/FP/src/Makefile
+++ b/FP/src/Makefile
@@ -6,8 +6,6 @@ CC         = @gcc
 LINKER     = @gcc
 INFO       = @echo
 MAKEDIR    = @mkdir -p
-INDEXER    = @cd ..;./install; cd src
-DOWNLOADER = @cd ..;./install -d; cd src
 REMOVER    = @rm -f
 AWK        = @awk
 
@@ -49,7 +47,7 @@ LINKERRELEASE =
 #Binary code files
 OBJFILES      = main.o kernel.o resources.o dat.o disk.o compress.o \
                 output.o maps.o config.o room.o titles.o \
-                input.o kid.o states.o tiles.o
+                input.o kid.o states.o tiles.o walls.o
 EXEFILE       = bin/freeprince
 
 GENERATEDRESHEADERS = include/res_conf_parts.h include/res_conf_files.h\
@@ -100,11 +98,11 @@ clean:
 	$(INFO) Erasing temporary object files...
 	$(REMOVER) $(OBJFILES) $(EXEFILE)\
 	           $(GENERATEDRESHEADERS) $(GENERATEDSTAHEADERS) $(GENERATEDTILHEADERS)\
-						 $(SRC2)
+						 $(SRC2) include/walls_conf.h
 
 build: clean $(EXEFILE)
 
-all: index build
+all: build
 
 install: download build
 
@@ -149,7 +147,7 @@ kernel.o: ker/kernel.c include/kernel.h include/resources.h include/res_conf.h i
 	$(INFO) Compiling main kernel...
 	$(CC) -c ker/kernel.c $(OPTIONS)
 
-room.o: ker/room.c include/room.h include/resources.h include/res_conf.h
+room.o: ker/room.c include/room.h include/resources.h include/res_conf.h include/walls_conf.h
 	$(INFO) Compiling kernel room object...
 	$(CC) -c ker/room.c $(OPTIONS)
 
@@ -192,10 +190,13 @@ states.o: ker/states.c include/states.h include/states_conf.h\
 	$(INFO) Compiling kernel states module...
 	$(CC) -c ker/states.c $(OPTIONS)
 
-tiles.o: res/tiles.c include/tiles.h include/tiles_conf.h
+tiles.o: res/tiles.c include/tiles.h include/tiles_conf.h 
 	$(INFO) Compiling resource tile classification module...
 	$(CC) -c res/tiles.c $(OPTIONS)
 
+walls.o: res/walls.c include/walls.h include/walls_conf.h
+	$(INFO) Compiling wall algorithm module...
+	$(CC) -c res/walls.c $(OPTIONS)
 
 #AWK scripts: header generation
 include/res_conf.h: $(GENERATEDRESHEADERS)
@@ -244,3 +245,7 @@ include/tiles_conf_groups.h: conf/tiles.conf conf/awk/tiles_conf_groups.awk
 	$(INFO) Creating tile groups configuration file...
 	$(AWK) -f conf/awk/tiles_conf_groups.awk conf/tiles.conf>include/tiles_conf_groups.h
 
+include/walls_conf.h: conf/walls.conf conf/awk/walls_conf.awk
+	$(INFO) Creating wall algorithm randomization file...
+	$(AWK) -f conf/awk/walls_conf.awk conf/walls.conf>include/walls_conf.h
+
diff --git a/FP/src/conf/awk/walls_conf.awk b/FP/src/conf/awk/walls_conf.awk
new file mode 100644
index 0000000..87fa189
--- /dev/null
+++ b/FP/src/conf/awk/walls_conf.awk
@@ -0,0 +1,215 @@
+#!/usr/bin/awk
+
+BEGIN {
+	env=-1
+	loc=-1
+	print "/* ENV and LOC defines */"
+}
+
+##########################
+# PART 1                 #
+# Parse file into memory #
+##########################
+
+#comments
+/^[[:space:]]*#/ {
+	halt
+}
+
+#environtment cathegories
+/^[[:space:]]*WALL[[:space:]]/ {
+	$2=toupper($2)
+	$3=toupper($3)
+	currentenvironment=$2
+	currentlocation=$3
+	currenttable=""
+	total=0
+	if ($2 && !environments[$2]) {
+		environments[$2]=1
+		env++
+		envnum[env]=$2
+		printf("#define WALL_ENV_%s %d\n",$2,env)
+	}
+	if ($3 && !locations[$3]) {
+		locations[$3]=1
+		loc++
+		locnum[loc]=$3
+		printf("#define WALL_LOC_%s %d\n",$3,loc)
+	}
+	tots[ $2 "-" $3 ]=$4/1
+	
+	halt
+}
+
+#tables
+/^[[:space:]]*TABLE[[:space:]]/ {
+	$2=toupper($2)
+	if (total>tots[ currentenvironment "-" currentlocation ]) tots[ currentenvironment "-" currentlocation ]=total
+	currenttable=$2
+	if ($2 && !tables[$2]) {
+		tables[$2]=1
+	}
+	total=0
+	halt
+}
+
+
+
+#add item
+function additem(base) {
+
+	# 1) detect strings: y,yes,t,true. f,false,n,no.
+	if (base ~ /[yY]([eE][sS])?/) base=1
+	if (base ~ /[nN]([oO]|[Uu][Ll][lL])?/) base=0
+	if (base ~ /[tT]([rR][uU][eE])?/) base=1
+	if (base ~ /[fF]([aA][Ll][sS][eE])?/) base=0
+	
+	# 2) calculate max and total
+	if (base>maxs[currenttable]) maxs[currenttable]=base
+	total++
+	 
+	# 3) save the element in the correct table  
+	items[currentenvironment "-" currentlocation "-" currenttable "-" total]=base/1
+}
+
+#parse items 
+/[[:space:]]*LINE[[:space:]]/ {
+	if (currentenvironment && currenttable) {
+		for (i=2;i<=NF;i++) {
+			if ($i ~ /\*/) {
+				split($i,a,"*")
+				mult=a[1]
+				base=a[2]
+				for (j=0;j<mult;j++) {
+					additem(base)
+				}
+			} else {
+				additem($i)
+			}
+		}
+	
+	} else {
+		#syntax error: items out of place
+	}
+}
+
+/[[:space:]]*PLACE[[:space:]]/ {
+	if (currentenvironment && currenttable) {
+		maxtt=0
+		for (i=2;i<=NF;i++) {
+			total=$i
+			if (total>maxtt) maxtt=total
+			additem(1)
+		}
+		total=maxtt
+	} else {
+		#syntax error: items out of place
+	}
+}
+
+
+#the end
+
+#calculate bits
+
+func getbits(k) {
+	i=0
+	for (;k;i++) k=(k-k%2)/2
+	return i
+}
+
+END {
+	if (total>tots[ currentenvironment "-" currentlocation ]) tots[ currentenvironment "-" currentlocation ]=total
+
+	# 1) calculate inc and tab for each table
+	inc=0
+	tab=0
+	maxsiz=0
+	for (table in tables) {
+		b=getbits(maxs[table])
+		if (inc+b>31) {
+			inc=0
+			tab++
+		}
+		#exception: in case max=0 (b=0) tab and inc will be 0
+		if (b==0) {
+			tableinfo[table "inc"]=0
+			tableinfo[table "tab"]=0
+			tableinfo[table "siz"]=0
+		} else {
+			tableinfo[table "inc"]=inc
+			tableinfo[table "tab"]=tab
+			tableinfo[table "siz"]=b
+			if (b>maxsiz) maxsiz=b
+		}
+		inc+=b;
+	}
+	
+	sizeoftab=getbits(tab)
+	if (tab) {
+		sizeofinc=5
+	} else {
+		sizeofinc=getbits(inc)
+	}
+	sizeofsiz=getbits(maxsiz)
+	
+	printf("\n/* TableId sizes */\n")
+	printf("/* maxtab=%d maxinc=%d maxsiz=%d. Size of tabincsiz is %d bits */\n",sizeoftab,sizeofinc,sizeofsiz,sizeofinc+sizeoftab+sizeofsiz)
+	printf("#define WALL_gettab(tabincsiz) (tabincsiz>>%d)\n",sizeofinc+sizeofsiz)
+	printf("#define WALL_getinc(tabincsiz) ((tabincsiz>>%d)&0x%X)\n",sizeofsiz,(2^sizeofinc)-1)
+	printf("#define WALL_getsiz(tabincsiz) (tabincsiz&0x%X)\n",(2^sizeofsiz)-1)
+	printf("#define WALL_gettabinc(tab,inc,siz) ((((tab<<%d)|inc)<<%d)|siz)\n\n",sizeofinc,sizeofsiz)
+	
+	for (table in tables) {
+		tableinfo[table "id"]=((((tableinfo[table "tab"]*2^sizeofinc)+tableinfo[table "inc"])*2^sizeofsiz)+tableinfo[table "siz"])
+		printf("#define WALL_TABLE_%s %d /* WALL_gettabinc(%d,%d,%d) */\n",table,tableinfo[table "id"],tableinfo[table "tab"],tableinfo[table "inc"],tableinfo[table "siz"])
+	}
+	
+	sizeofenv=getbits(env)
+	sizeofloc=getbits(loc)
+	
+	printf("\n/* Index sizes */\n")
+	printf("/* maxenv=%d maxloc=%d maxtab=%d. Size of envloctab is %d bits */\n",sizeofenv,sizeofloc,sizeoftab,sizeofenv+sizeofloc+sizeoftab)
+	printf("#define WALL_getenv(envloctab) (envloctab>>%d)\n",sizeofloc+sizeoftab)
+	printf("#define WALL_getloc(envloctab) ((envloctab>>%d)&0x%X)\n",sizeofloc,(2^sizeoftab)-1)
+	printf("#define WALL_gettab2(envloctab) (envloctab&0x%X)\n",(2^sizeoftab)-1)
+	printf("#define WALL_getenvloctab(env,loc,tab) ((((env<<%d)|loc)<<%d)|tab)\n\n",sizeofloc,sizeoftab)
+
+	printf("\n/* A total of %d arrays will be created */\n",2^(sizeofenv+sizeofloc+sizeoftab))
+	
+	printf("#define WALL_ARRAYS {\\\n")
+	totaltotal=0
+	coma2=""
+	for (e=0;e<2^sizeofenv;e++) {
+		environment=envnum[e]
+		for (l=0;l<2^sizeofloc;l++) {
+			location=locnum[l]
+			for (table in tables) {
+#				printf("/* table %s. e=%d(%s) l=%d(%s) t=%d i=%d s=%d */\n",table,e,environment,l,location,tableinfo[table "tab"],tableinfo[table "inc"],tableinfo[table "siz"])
+				for (i=1;i<=tots[environment "-" location];i++) {
+					key= ( environment "-" location "-" table "-" i )
+					res[tableinfo[table "tab"] "-" i]+=(items[key]/1)*2^(tableinfo[table "inc"])
+				}
+			}
+			for (t=0;t<2^sizeoftab;t++) {
+				printf("\t/* e=%d(%s) l=%d(%s) t=%d */ %s{",e,environment,l,location,t,coma2)
+				coma2=","
+				coma=""
+				#this is to allow al least one item and avoid empty brackets
+				if (!tots[environment "-" location]) tots[environment "-" location]=1
+				
+				for (i=1;i<=tots[environment "-" location];i++) {
+					printf("%s(unsigned long)%d",coma,res[t "-" i])
+					coma=","
+				}
+				totalcount++
+				if (tots[environment "-" location]>totaltotal) totaltotal=tots[environment "-" location]
+				printf("}\\\n")
+			}
+			delete res
+		}
+	}
+	printf("}\n")
+	printf("#define WALL_COUNT_TABLES %d\n#define WALL_SIZE_TABLES %d\n",totalcount,totaltotal)
+}
+
diff --git a/FP/src/conf/walls.conf b/FP/src/conf/walls.conf
new file mode 100644
index 0000000..32bf114
--- /dev/null
+++ b/FP/src/conf/walls.conf
@@ -0,0 +1,82 @@
+#   Princed V3 - Prince of Persia Level Editor for PC Version
+#   Copyright (C) 2003 Princed Development Team
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+#   The authors of this program may be contacted at http://forum.princed.com.ar
+
+# walls.conf: FreePrince : Tiles list
+# \xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
+# Copyright 2005, 2004, 2003 Princed Development Team
+#  Created: 3 Jan 2005
+#
+#  Author: Enrique Calot <ecalot.cod@princed.com.ar>
+#
+# Note:
+#  DO NOT remove this copyright notice
+#
+
+#WALL palace sws
+#	TABLE UL
+#		LINE 1 10*0 1 11*0 1
+#	TABLE DL
+#		LINE 10*no yes 30*no
+#	TABLE separator_position
+#		LINE 4 3 2 1 0 4 2 1 0 4 3 1 4 2 1 null 2 1
+
+WALL dungeon www
+
+#first row	
+	TABLE line1_darker
+		PLACE 2 5 14 17 20 32 35 50
+	TABLE line1_left_down
+		PLACE 2 11 36 45
+	TABLE line1_left_up
+		PLACE 37
+	TABLE line1_right_down
+		PLACE 27 33
+	TABLE line1_right_up 
+		PLACE 4 10 31 37
+
+#second row	
+	TABLE line2_offset
+		LINE 5 4 3 3 1 5 4 2 1 1 5 3 2 1 5 4 3 2 5 4
+	TABLE line2_darker 
+	TABLE line2_left_down 
+		PLACE 34 47
+	TABLE line2_left_up
+		PLACE 9 10
+	TABLE line2_right_down
+		PLACE 2 8 25 35
+	TABLE line2_right_up
+		PLACE 6 12 23 29 39
+	TABLE line2_sep
+		LINE no yes yes no no no yes yes no no yes yes yes no no yes yes yes no no yes yes yes no no yes yes yes no no yes yes yes no no yes yes yes no no yes yes no no no yes yes no no no yes yes no
+
+#third row	
+	TABLE line3_offset
+		LINE 5 4 3 3 1 5 4 2 1 1 5 3 2 1 5 4 3 2 5 4
+	TABLE line3_darker 
+	TABLE line3_left_down 
+	TABLE line3_left_up 
+		PLACE 16
+	TABLE line3_right_down
+	TABLE line3_right_up
+	TABLE line3_sep
+		LINE yes no no yes no no yes no yes yes no yes yes no yes yes no yes yes no yes yes no yes no no yes no no yes no no yes no no yes no no yes no yes yes no yes yes no yes yes no yes yes no yes
+
+WALL dungeon sww
+WALL dungeon wws
+WALL dungeon sws
diff --git a/FP/src/include/room.h b/FP/src/include/room.h
index 34c5efa..384f8e7 100644
--- a/FP/src/include/room.h
+++ b/FP/src/include/room.h
@@ -44,21 +44,5 @@ void roomDrawBackground(tRoom* room);
 void roomDrawForeground(tRoom* room);
 void roomLoadGfx(long environment); /* Only to initialize environment by mapStart */
 
-#define w1_darker(a)     ((a)&1)
-#define w1_left_down(a)  ((a>>1)&1)
-#define w1_right_down(a) ((a>>2)&1)
-#define w1_right_up(a)   ((a>>3)&1)
-#define w2_left_down(a)  ((a>>4)&1)
-#define w2_left_up(a)    ((a>>5)&1)
-#define w2_right_down(a) ((a>>6)&1)
-#define w2_right_up(a)   ((a>>7)&1)
-
-#define w2_sep(a)        ((a>>8)&1)
-#define w3_sep(a)        ((a>>9)&1)
-#define w2_offset(a)     ((a>>10)&7)
-#define w3_offset(a)     ((a>>13)&7)
-
-#define WALL_PROPERTIES {46592, 37187, 27904, 28168, 9217, 46208, 37632, 18752, 9760, 9768, 46338, 28544, 19200, 9217, 46592, 37632, 27905, 19200, 46592, 36865, 768, 768, 384, 512, 64, 256, 772, 256, 128, 512, 264, 257, 772, 16, 65, 770, 264, 256, 640, 0, 768, 768, 0, 512, 514, 256, 784, 512, 0, 513, 768, 256, 512}
-
 #endif
 
diff --git a/FP/src/include/walls.h b/FP/src/include/walls.h
new file mode 100644
index 0000000..217bf9c
--- /dev/null
+++ b/FP/src/include/walls.h
@@ -0,0 +1,41 @@
+/*  Princed V3 - Prince of Persia Level Editor for PC Version
+    Copyright (C) 2003 Princed Development Team
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    The authors of this program may be contacted at http://forum.princed.com.ar
+*/
+
+/*
+walls.h: FreePrince : Walls functions
+\xaf\xaf\xaf\xaf\xaf\xaf
+ Copyright 2005 Princed Development Team
+  Created: 3 Jan 2005
+
+  Author: Enrique Calot <ecalot.cod@princed.com.ar>
+
+ Note:
+  DO NOT remove this copyright notice
+*/
+
+#ifndef _WALLS_H_
+#define _WALLS_H_
+
+#include "walls_conf.h"
+
+int wallGet(unsigned short env,unsigned short loc,unsigned short tab,unsigned short n); 
+
+#endif
+
diff --git a/FP/src/ker/room.c b/FP/src/ker/room.c
index 9cc970e..87505a0 100644
--- a/FP/src/ker/room.c
+++ b/FP/src/ker/room.c
@@ -37,6 +37,7 @@ room.c: FreePrince : Room and Tile Object
 #include "output.h"
 #include "room.h"
 #include "maps.h"
+#include "walls.h"
 
 static struct {
 	tData* torch;
@@ -80,7 +81,7 @@ tTile roomGetTile(tRoom* room,int x, int y) {
 	result.back=room->back[x+12*y];
 	result.code=fore&0x1F;
 	
-	switch (result.code) { /* TODO: use arrays and a better algorithm */
+	switch (result.code) { /* TODO: use the tiles library */
 	case T_GATE:
 	case T_EXIT_LEFT:
 		roomId=room->id;
@@ -686,90 +687,93 @@ void drawForePanel(tRoom* room,int x, int y) {
 	}
 	/* wall */
 	if (tile.isWall) {
-		static unsigned short seedArray[]=WALL_PROPERTIES;
-		unsigned short seed;
+		/*static unsigned short seedArray[]=WALL_PROPERTIES;*/
+		register short seed;
+		int cases;
+		int env=WALL_ENV_DUNGEON;
 		tTile left;
 		tTile right;
 		left=roomGetTile(room,x-1,y);
 		right=roomGetTile(room,x+1,y);
+		seed=room->id+(x-1)+(y-1)*10-1;
 		/* there are 4 cases */
 		if (left.isWall&&right.isWall) { 
-			/* First step: calculate the seed position and get the element */	
-			seed=seedArray[room->id+(x-1)+(y-1)*10-1];
+			/* First step: calculate the seed position and get the element */
+			cases=WALL_LOC_WWW;
 			outputDrawBitmap(roomGfx.environment->pFrames[66],(x-1)*TILE_W,y*TILE_H);
 		} else if ((!left.isWall)&&(right.isWall)) {
+			cases=WALL_LOC_SWW;
 			outputDrawBitmap(roomGfx.environment->pFrames[72],(x-1)*TILE_W,y*TILE_H);
-			seed=seedArray[room->id+(x-1)+(y-1)*10-1];
 		} else if ((left.isWall)&&(!right.isWall)) {
+			cases=WALL_LOC_WWS;
 			outputDrawBitmap(roomGfx.environment->pFrames[68],(x-1)*TILE_W,y*TILE_H);
-			seed=seedArray[room->id+(x-1)+(y-1)*10-1];
 		} else {
+			cases=WALL_LOC_SWS;
 			outputDrawBitmap(roomGfx.environment->pFrames[70],(x-1)*TILE_W,y*TILE_H);
-			seed=seedArray[room->id+(x-1)+(y-1)*10-1];
 		}
 		/* TODO: use one seed per combination */
 			/* the seed generation algorithm */
 			/* Upper row */
-			if (w1_darker(seed)) outputDrawBitmap(
+			if (wallGet(env,cases,WALL_TABLE_LINE1_DARKER,seed)) outputDrawBitmap(
 				roomGfx.environment->pFrames[75],
 				(x-1)*TILE_W,
 				y*TILE_H-39
 			);
-			if (w1_left_down(seed)) outputDrawBitmap(
+			if (wallGet(env,cases,WALL_TABLE_LINE1_LEFT_DOWN,seed)) outputDrawBitmap(
 				roomGfx.environment->pFrames[77],
 				(x-1)*TILE_W,
 				y*TILE_H-39
 			);
-			if (w1_right_down(seed)) outputDrawBitmap(
+			if (wallGet(env,cases,WALL_TABLE_LINE1_RIGHT_DOWN,seed)) outputDrawBitmap(
 				roomGfx.environment->pFrames[79],
 				(x-1)*TILE_W+24,
 				y*TILE_H-39
 			);
-			if (w1_right_up(seed)) outputDrawBitmap(
+			if (wallGet(env,cases,WALL_TABLE_LINE1_RIGHT_UP,seed)) outputDrawBitmap(
 				roomGfx.environment->pFrames[78],
 				(x-1)*TILE_W+24,
 				y*TILE_H-49
 			);
-			if ((room->id+(x-1)+(y-1)*10)==37) outputDrawBitmap(
+			if (wallGet(env,cases,WALL_TABLE_LINE1_LEFT_UP,seed)) outputDrawBitmap(
 				roomGfx.environment->pFrames[76],
 				(x-1)*TILE_W,
 				y*TILE_H-54
 			);
 			/* Second row */
 			outputDrawBitmap(
-				roomGfx.environment->pFrames[74-w2_sep(seed)],
-				(x-1)*TILE_W+7+w2_offset(seed),
+				roomGfx.environment->pFrames[74-wallGet(env,cases,WALL_TABLE_LINE2_SEP,seed)],
+				(x-1)*TILE_W+7+wallGet(env,cases,WALL_TABLE_LINE2_OFFSET,seed),
 				y*TILE_H-18
 			);
-			if (w2_left_down(seed)) outputDrawBitmap(
+			if (wallGet(env,cases,WALL_TABLE_LINE2_LEFT_DOWN,seed)) outputDrawBitmap(
 				roomGfx.environment->pFrames[77],
-				(x-1)*TILE_W+7+w2_offset(seed)+5,
+				(x-1)*TILE_W+7+wallGet(env,cases,WALL_TABLE_LINE2_OFFSET,seed)+5,
 				y*TILE_H-39+21
 			);
-			if (w2_right_down(seed)) outputDrawBitmap(
+			if (wallGet(env,cases,WALL_TABLE_LINE2_RIGHT_DOWN,seed)) outputDrawBitmap(
 				roomGfx.environment->pFrames[79],
-				(x-1)*TILE_W+24+7+w2_offset(seed)-32+5,
+				(x-1)*TILE_W+24+7+wallGet(env,cases,WALL_TABLE_LINE2_OFFSET,seed)-32+5,
 				y*TILE_H-39+21
 			);
-			if (w2_right_up(seed)) outputDrawBitmap(
+			if (wallGet(env,cases,WALL_TABLE_LINE2_RIGHT_UP,seed)) outputDrawBitmap(
 				roomGfx.environment->pFrames[78],
-				(x-1)*TILE_W+24+7+w2_offset(seed)-32+5,
+				(x-1)*TILE_W+24+7+wallGet(env,cases,WALL_TABLE_LINE2_OFFSET,seed)-32+5,
 				y*TILE_H-49+21
 			);
-			if (w2_left_up(seed)) outputDrawBitmap(
+			if (wallGet(env,cases,WALL_TABLE_LINE2_LEFT_UP,seed)) outputDrawBitmap(
 				roomGfx.environment->pFrames[76],
-				(x-1)*TILE_W+7+w2_offset(seed)+5,
+				(x-1)*TILE_W+7+wallGet(env,cases,WALL_TABLE_LINE2_OFFSET,seed)+5,
 				y*TILE_H-54+21
 			);
 			/* Third row TODO: send to BottomTile */
 			outputDrawBitmap(
-				roomGfx.environment->pFrames[74-w3_sep(seed)],
-				(x-1)*TILE_W+3+w3_offset(seed),
+				roomGfx.environment->pFrames[74-wallGet(env,cases,WALL_TABLE_LINE3_SEP,seed)],
+				(x-1)*TILE_W+3+wallGet(env,cases,WALL_TABLE_LINE3_OFFSET,seed),
 				y*TILE_H+3
 			);
-			if ((room->id+(x-1)+(y-1)*10)==16) outputDrawBitmap(
+			if (wallGet(env,cases,WALL_TABLE_LINE3_LEFT_UP,seed)) outputDrawBitmap(
 				roomGfx.environment->pFrames[76],
-				(x-1)*TILE_W+5+w3_offset(seed)+5,
+				(x-1)*TILE_W+5+wallGet(env,cases,WALL_TABLE_LINE3_OFFSET,seed)+5,
 				y*TILE_H-55+21*2
 			);
 
diff --git a/FP/src/res/tiles.c b/FP/src/res/tiles.c
index 17e5dbf..4960a99 100644
--- a/FP/src/res/tiles.c
+++ b/FP/src/res/tiles.c
@@ -30,10 +30,7 @@ tiles.c: FreePrince : Tile functions
   DO NOT remove this copyright notice
 */
 
-#ifndef _TILES_H_
-#define _TILES_H_
-
-#include "tiles_conf.h"
+#include "tiles.h"
 
 int isInGroup(unsigned char tile,unsigned char backtile,short group) {
 	static unsigned char tileList[]=TILES_GROUP_LIST;
@@ -53,5 +50,3 @@ int isInGroup(unsigned char tile,unsigned char backtile,short group) {
 	return *i; /* returns non-zero if true and zero if false */
 }
 
-#endif
-
diff --git a/FP/src/res/walls.c b/FP/src/res/walls.c
new file mode 100644
index 0000000..5494f07
--- /dev/null
+++ b/FP/src/res/walls.c
@@ -0,0 +1,47 @@
+/*  Princed V3 - Prince of Persia Level Editor for PC Version
+    Copyright (C) 2003 Princed Development Team
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    The authors of this program may be contacted at http://forum.princed.com.ar
+*/
+
+/*
+tiles.c: FreePrince : Wall generation algorithm functions
+\xaf\xaf\xaf\xaf\xaf\xaf\xaf
+ Copyright 2005 Princed Development Team
+  Created: 3 Jan 2005
+
+  Author: Enrique Calot <ecalot.cod@princed.com.ar>
+
+ Note:
+  DO NOT remove this copyright notice
+*/
+
+#include "walls.h"
+
+int wallGet(unsigned short env,unsigned short loc,unsigned short tab,unsigned short n) {
+	static unsigned long wallList[WALL_COUNT_TABLES][WALL_SIZE_TABLES]=WALL_ARRAYS;
+
+	if (!tab) {
+		return 0;
+	}	else {
+		register unsigned short t=WALL_gettab(tab);
+		register unsigned short value=wallList[WALL_getenvloctab(env,loc,t)][n];
+		return (value>>WALL_getinc(tab))&((1<<WALL_getsiz(tab))-1);
+	}
+}
+
+