git » fp-git.git » commit b85073a

implemented evaluateCondition in states

author ecalot
2004-10-19 17:49:39 UTC
committer ecalot
2004-10-19 17:49:39 UTC
parent d02760fea477b61dda0b874aeb77b898d577a0ce

implemented evaluateCondition in states

FP/src/Makefile +2 -1
FP/src/include/types.h +2 -1
FP/src/ker/states.c +41 -8

diff --git a/FP/src/Makefile b/FP/src/Makefile
index c2bd6e7..fdfacc1 100644
--- a/FP/src/Makefile
+++ b/FP/src/Makefile
@@ -185,7 +185,8 @@ config.o: res/config.c include/resources.h include/res_conf.h
 	$(CC) -c res/config.c $(OPTIONS)
 
 states.o: ker/states.c include/states.h include/states_conf.h\
-          include/resources.h include/res_conf.h
+          include/resources.h include/res_conf.h include/types.h\
+					include/tiles.h include/tiles_conf.h
 	$(INFO) compiling kernel states module...
 	$(CC) -c ker/states.c $(OPTIONS)
 
diff --git a/FP/src/include/types.h b/FP/src/include/types.h
index df7c894..450c5df 100644
--- a/FP/src/include/types.h
+++ b/FP/src/include/types.h
@@ -74,7 +74,8 @@ typedef struct {
 	int            totalPressables;
 	tEvent         events[256];
 	int            time;
-	unsigned char start[3];
+	unsigned char  start[3];
+	unsigned char  levelNumber;
 } tMap;
 
 typedef struct {
diff --git a/FP/src/ker/states.c b/FP/src/ker/states.c
index c828c74..01c11af 100644
--- a/FP/src/ker/states.c
+++ b/FP/src/ker/states.c
@@ -1,5 +1,6 @@
 #include "states.h"
 #include <stdlib.h>
+#include "tiles.h" /* isInGroup & groups */
 
 /* Private static state graph */
 static tsAction statesActionList[]=STATES_ACTIONS;
@@ -30,25 +31,57 @@ tState createState(int level) {
 /* private functions */
 
 /* Evaluates a condition indexed in the condition table */
-int evaluateCondition(int condition,tKey* key,tMap* map) {
+int evaluateCondition(int condition,tKey* key, tKid* kid, tRoom* room) {
 	tsCondition c=statesConditionList[condition];
+	int thisTile=kid->location/32+1+12*kid->floor;
+	int whereInTile=(kid->direction==eLeft)?(kid->location%32):32-(kid->location%32);
 	switch(c.type) {
 	case esKeyUp:
+		return inputGetUp(key->status)?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esKeyDown:
+		return inputGetDown(key->status)?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esKeyForward:
+		return ((kid->direction==eLeft)?inputGetLeft(key->status):inputGetRight(key->status))?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esKeyBack:
+		return ((kid->direction==eLeft)?inputGetRight(key->status):inputGetLeft(key->status))?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esKeyShift:
+		return inputGetShift(key->status)?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esMapUp:
+		return isInGroup(room->fore[thisTile-12],c.argument)?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esMapDown:
+		return isInGroup(room->fore[thisTile+12],c.argument)?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esMapForward:
+		return isInGroup(room->fore[thisTile+((kid->direction==eLeft)?-1:1)],c.argument)?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esMapBack:
+		return isInGroup(room->fore[thisTile+((kid->direction==eLeft)?1:-1)],c.argument)?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esMapOn:
+		return isInGroup(room->fore[thisTile],c.argument)?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esForwardTileNearerThan:
+		return (whereInTile<c.argument)?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esForwardTileFartherThan:
+		return (whereInTile>c.argument)?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esInScreen:
+		return (room->id==c.argument)?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esInLevel:
+		return (room->level->levelNumber==c.argument)?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esForwardChangeToScreen:
-		return STATES_CONDRESULT_TRUE;
+		return ((kid->direction==eLeft)&&(thisTile==1))
+			||((kid->direction==eRight)&&(thisTile==10))?
+			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esLast:
 		return STATES_CONDRESULT_END;
 	default:
@@ -57,31 +90,31 @@ int evaluateCondition(int condition,tKey* key,tMap* map) {
 }
 
 /* Evaluates all conditions needed for an action and returns true or false */
-int evaluateAction(int currentAction,tKey* key,tMap* map) {
+int evaluateAction(int currentAction,tKey* key, tKid* kid,tRoom* room) {
 	int i=statesActionList[currentAction].conditionId;
 	int result;
-	while ((result=evaluateCondition(i,key,map))==STATES_CONDRESULT_TRUE) i++;
+	while ((result=evaluateCondition(i,key,kid,room))==STATES_CONDRESULT_TRUE) i++;
 	if (result==STATES_CONDRESULT_FALSE) return 0;
 	return 1; /* Only returns true if STATES_CONDRESULT_END is reached */
 }
 
 /* Evaluates a state: all conditions for all actions until a true is found and returns the next state id*/
-int evaluateState(int state, tKey* key, tMap* map) {
+int evaluateState(int state, tKey* key, tKid* kid, tRoom* room) {
 	int i=state;
-	while (!evaluateAction(i,key,map)) i++;
+	while (!evaluateAction(i,key,kid,room)) i++;
 	return i;
 }
 
 /* This function should return the image frame and actions to be performed by this call
  * returns the animation number corresponding to this frame */
-int stateUpdate(tState* current,tKey* key,tMap* map) {
+int stateUpdate(tState* current,tKey* key, tKid* kid,tRoom* room) {
 	int imageFrame=statesAnimationList[current->animation[current->frame]];
 	if (current->frame) {
 		current->frame--;
 	} else {
 		int action;
 		/* free(current->animation) */
-		action=evaluateState(current->currentState,key,map);
+		action=evaluateState(current->currentState,key,kid,room);
 		current->animation=stateGetAnimation(action,&(current->frame));
 		current->currentState=statesActionList[action].nextStateId;
 	}