git » fp-git.git » commit bfe44ee

Finished the macro function evaluation for tile conditions. Improved the state condition evaluator.

author ecalot
2005-01-23 21:15:29 UTC
committer ecalot
2005-01-23 21:15:29 UTC
parent a11445cfb8d89e6d339216f15af086e30268f7da

Finished the macro function evaluation for tile conditions. Improved the state condition evaluator.

FP/src/Makefile +3 -2
FP/src/ker/room.c +1 -0
FP/src/ker/states.c +36 -41
FP/src/res/tiles.c +1 -0

diff --git a/FP/src/Makefile b/FP/src/Makefile
index 76d8498..161037e 100644
--- a/FP/src/Makefile
+++ b/FP/src/Makefile
@@ -157,7 +157,7 @@ dat.o: res/dat.c include/disk.h include/dat.h
 
 kernel.o: ker/kernel.c include/kernel.h include/resources.h\
           include/res_conf.h include/output.h include/object.h\
-          $(GENERATEDSTAHEADERS)
+          $(GENERATEDSTAHEADERS) $(GENERATEDTILHEADERS)
 	$(INFO) Compiling main kernel...
 	$(CC) -c ker/kernel.c $(OPTIONS)
 
@@ -224,7 +224,8 @@ walls.o: res/walls.c include/walls.h include/walls_conf.h
 	$(CC) -c res/walls.c $(OPTIONS)
 
 anims.o: res/anims.c include/anims.h include/anims_conf.h\
-         $(GENERATEDRESHEADERS) $(GENERATEDSTAHEADERS)
+         $(GENERATEDRESHEADERS) $(GENERATEDSTAHEADERS)\
+         $(GENERATEDTILHEADERS)
 	$(INFO) Compiling animation loader module...
 	$(CC) -c res/anims.c $(OPTIONS)
 	
diff --git a/FP/src/ker/room.c b/FP/src/ker/room.c
index 680d381..fa156b5 100644
--- a/FP/src/ker/room.c
+++ b/FP/src/ker/room.c
@@ -80,6 +80,7 @@ tTile roomGetTile(tRoom* room,int x, int y) {
 	
 	result.back=room->back[x+12*y];
 	result.code=room->fore[x+12*y]&0x1F;
+	result.moreInfo=(void*)1/*NULL*/;
 	
 	/* TODO: use a tile group: special, with GATES, PRESSABLE, SPIKES,
 	 * CHOPPER.
diff --git a/FP/src/ker/states.c b/FP/src/ker/states.c
index 5cf2012..9de1254 100644
--- a/FP/src/ker/states.c
+++ b/FP/src/ker/states.c
@@ -32,9 +32,10 @@ states.c: FreePrince : State object
 
 #include "states.h"
 #include <stdlib.h>
-#include "tiles.h" /* isInGroup & groups */
+#include "tiles.h" /* isIn & groups */
 #include <stdio.h> /* For debug purposes */
 #include "object.h" /* DIR_LEFT DIR_RIGHT */
+#include "room.h" /* getTile */
 
 #ifdef DEBUGSTATES
 void debugShowFlag(short optionflag) {
@@ -89,81 +90,75 @@ tState createState(short stateId) {
 /* private functions */
 
 /* Evaluates a condition indexed in the condition table */
-#define DefaultTrue(pointer) if (!pointer) return STATES_CONDRESULT_TRUE
-#define DefaultFalse(pointer) if (!pointer) return STATES_CONDRESULT_TRUE
+#define DefaultTrue(pointer)  if (!pointer) return STATES_CONDRESULT_TRUE
+#define DefaultFalse(pointer) if (!pointer) return STATES_CONDRESULT_FALSE
+
+#define statesKidLeft (kid->direction==DIR_LEFT)
+
+#define whereInTile (statesKidLeft? \
+	(kid->location%STATES_STEPS_PER_TILE): \
+	STATES_STEPS_PER_TILE-(kid->location%STATES_STEPS_PER_TILE))
+
+#define kidX (kid->location/STATES_STEPS_PER_TILE+1)
+#define kidY (kid->floor+1)
+#define statesTile(x,y) roomGetTile(room,kidX+x,kidY+y)
+#define kidDirection (statesKidLeft?-1:1)
+
+#define statesCondRet(a) return (a)?STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE
+
+/* Memory interpreter */
 int evaluateCondition(int condition,tKey* key, tObject* kid, tRoom* room) {
 	tsCondition c=statesConditionList[condition];
-#define thisTile (kid->location/STATES_STEPS_PER_TILE+13+12*kid->floor)
-#define whereInTile ((kid->direction==DIR_LEFT)?(kid->location%STATES_STEPS_PER_TILE):STATES_STEPS_PER_TILE-(kid->location%STATES_STEPS_PER_TILE))
 	switch(c.type) {
 	case esKeyUp:
 		DefaultFalse(key);
-		return inputGetUp(key->status)? /* TODO: argument notPressed isn't supported */
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet(inputGetUp(key->status));
+		/* TODO: argument notPressed isn't supported */
 	case esKeyDown:
 		DefaultFalse(key);
-		return inputGetDown(key->status)?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet(inputGetDown(key->status));
 	case esKeyForward:
 		DefaultFalse(key);
-		return ((kid->direction==DIR_LEFT)?inputGetLeft(key->status):inputGetRight(key->status))?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet((statesKidLeft?inputGetLeft(key->status):inputGetRight(key->status)));
 	case esKeyBack:
 		DefaultFalse(key);
-		return ((kid->direction==DIR_LEFT)?inputGetRight(key->status):inputGetLeft(key->status))?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet((statesKidLeft?inputGetRight(key->status):inputGetLeft(key->status)));
 	case esKeyShift:
 		DefaultFalse(key);
-		return inputGetShift(key->status)?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet(inputGetShift(key->status));
 	case esMapUpForward:
 		DefaultFalse(room);
-		{
-			int t=thisTile-12+((kid->direction==DIR_LEFT)?-1:1);
-		return isInGroup(room->fore[t],room->back[t],c.argument)?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
-		}
+		statesCondRet(isIn(statesTile(kidDirection,-1),c.argument));
 	case esMapUp:
 		DefaultFalse(room);
-		return isInGroup(room->fore[thisTile-12],room->back[thisTile-12],c.argument)?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet(isIn(statesTile(0,-1),c.argument));
 	case esMapDown:
 		DefaultFalse(room);
-		return isInGroup(room->fore[thisTile+12],room->back[thisTile+12],c.argument)?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet(isIn(statesTile(0,1),c.argument));
 	case esMapForward:
 		DefaultFalse(room);
-		return isInGroup(room->fore[thisTile+((kid->direction==DIR_LEFT)?-1:1)],room->back[thisTile+((kid->direction==DIR_LEFT)?-1:1)],c.argument)?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet(isIn(statesTile(kidDirection,0),c.argument));
 	case esMapBack:
 		DefaultFalse(room);
-		return isInGroup(room->fore[thisTile+((kid->direction==DIR_LEFT)?1:-1)],room->back[thisTile+((kid->direction==DIR_LEFT)?1:-1)],c.argument)?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet(isIn(statesTile(-kidDirection,0),c.argument));
 	case esMapOn:
 		DefaultFalse(room);
-		return isInGroup(room->fore[thisTile],room->back[thisTile],c.argument)?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet(isIn(statesTile(0,0),c.argument));
 	case esForwardTileNearerThan:
 		DefaultFalse(kid);
-		return (whereInTile<c.argument)?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet((whereInTile<c.argument));
 	case esForwardTileFartherThan:
 		DefaultFalse(kid);
-		return (whereInTile>c.argument)?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet((whereInTile>c.argument));
 	case esInScreen:
 		DefaultFalse(room);
-		return (room->id==c.argument)?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet((room->id==c.argument));
 	case esInLevel:
 		DefaultFalse(room);
-		return (room->level->levelNumber==c.argument)?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet((room->level->levelNumber==c.argument));
 	case esForwardChangeToScreen:
 		DefaultFalse(kid);
-		return ((kid->direction==DIR_LEFT)&&(thisTile==1))
-			||((kid->direction==DIR_RIGHT)&&(thisTile==10))?
-			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
+		statesCondRet(((statesKidLeft)&&(kidX==1))||((!statesKidLeft)&&(kidX==10)));
 	case esLast:
 		return STATES_CONDRESULT_END;
 	default:
diff --git a/FP/src/res/tiles.c b/FP/src/res/tiles.c
index b8f3ef7..f0caf21 100644
--- a/FP/src/res/tiles.c
+++ b/FP/src/res/tiles.c
@@ -36,6 +36,7 @@ tiles.c: FreePrince : Tile functions
 int evaluate(tTile tile,int type) { /* type is the number in the modifier */
 	if (!tile.moreInfo) {
 		printf("Tile Error: trying to use a tile that hasn't extra information\n");
+		printf("code=%d back=%d\n",tile.code-1,tile.back);
 		return 0;
 	}
 	TILES_MACROS_CASE(type,tile)