git » fp-git.git » commit 5178090

improved tRoom object support

author dessaya
2004-07-24 02:34:44 UTC
committer dessaya
2004-07-24 02:34:44 UTC
parent 137c2d072b2f722b96a80fbd28af27c1dd584098

improved tRoom object support

FP/src/include/map_defs.h +5 -1
FP/src/include/maps.h +5 -0
FP/src/include/room.h +5 -2
FP/src/include/titles.h +1 -1
FP/src/ker/kernel.c +8 -20
FP/src/ker/titles.c +11 -13
FP/src/out/input.c +12 -8
FP/src/res/maps.c +131 -15

diff --git a/FP/src/include/map_defs.h b/FP/src/include/map_defs.h
index 77b1793..c5a4447 100644
--- a/FP/src/include/map_defs.h
+++ b/FP/src/include/map_defs.h
@@ -83,7 +83,6 @@ Len	Offs	BlockName & Description
 #define MAPS_BLOCK_SIZEOF_FILE              37031
 
 
-
 /* Constantes copadas */
 #define MAPS_sUp			2
 #define MAPS_sDown		3
@@ -148,4 +147,9 @@ Len	Offs	BlockName & Description
 #define MAPS_BCK_PIN_3 0x02
 #define MAPS_BCK_PIN_4 0x03
 
+
+#define MAP_B_NONE 0
+#define MAP_F_WALL 0
+#define MAP_F_FREE 0
+
 #endif
diff --git a/FP/src/include/maps.h b/FP/src/include/maps.h
index 5ab0096..9be2ac2 100644
--- a/FP/src/include/maps.h
+++ b/FP/src/include/maps.h
@@ -30,6 +30,9 @@ maps.c: Freeprince : Map handling library
   DO NOT remove this copyright notice
 */
 
+#ifndef _MAPS_H_
+#define _MAPS_H_
+
 #include "map_defs.h"
 
 typedef enum {eLeft=0,eRight=1,eUp=2,eDown=3}tDirection;
@@ -80,3 +83,5 @@ int levelGetStarPosition(int* screen, int* position); /* TODO: define
 int levelGetInformation(int *thisScreen, unsigned char* LRUDscreens, unsigned char* cornerScreens);
 /* TODO: define the format of cornerscreens */
 
+#endif
+
diff --git a/FP/src/include/room.h b/FP/src/include/room.h
index 1250046..f99aa65 100644
--- a/FP/src/include/room.h
+++ b/FP/src/include/room.h
@@ -36,9 +36,12 @@ room.h: FreePrince : Draw Screen
 
 #include "maps.h"
 
+typedef char tRoomId;
+
 typedef struct {
-	int id;
-	tDirection     links[4];
+	tRoomId        id;
+	tRoomId        links[4];
+	tRoomId        corners[4];
 	unsigned char  fore [60];	
 	unsigned char  back [60];
 	/* TODO: add guards */
diff --git a/FP/src/include/titles.h b/FP/src/include/titles.h
index 7547387..7403759 100644
--- a/FP/src/include/titles.h
+++ b/FP/src/include/titles.h
@@ -34,7 +34,7 @@ titles.h: FreePrince : Titles, animation and presentation
 #ifndef _TITLES_H_
 #define _TITLES_H_
 
-typedef enum {sQuit=0,sLoad=1,sStart,sNone}tMenuOption;
+typedef enum {menuQuit=0,menuLoad=1,menuStart,menuNone}tMenuOption;
 
 tMenuOption showTitles();
 /* Show the titles animation
diff --git a/FP/src/ker/kernel.c b/FP/src/ker/kernel.c
index c595b6f..5f91473 100644
--- a/FP/src/ker/kernel.c
+++ b/FP/src/ker/kernel.c
@@ -45,25 +45,10 @@ kernel.c: FreePrince : Main Kernel
  * Main game control function
  */
 
-int control(int optionflag,int level) {
-	/*SDL_Event e;*/
-/*	tData* runningAnimation[4];
-	tData* fondo;*/
+int playgame(int optionflag,int level) {
 	tKey   key=inputCreateKey();
 	tKid   kid=kidCreate();
 
-	/* TODO: send to kid and load static */
-/*	runningAnimation[0]=resLoad(RES_ANIM_RUN);
-	runningAnimation[1]=resLoad(RES_ANIM_RUN|RES_MOD_RIGHT);
-	runningAnimation[2]=resLoad(RES_ANIM_JUMPRUN);
-	runningAnimation[3]=resLoad(RES_ANIM_JUMPRUN|RES_MOD_RIGHT);
-
-	fondo=resLoad(RES_IMG_BACKGROUND);
-	if (!fondo) {
-		printf("The resource couldn't be loaded!\n");
-		return 1;
-	}
-*/
 /* Game loop here */
 	drawScreen(4);
 /* Level loop here */
@@ -122,6 +107,7 @@ int kernel(int optionflag,int level) {
 		fprintf(stderr, "Unable to initialize screen\n");
 		exit(1);
 	}
+	inputInitTimer();
 
 	/*
 	 * Start main menu loop (story and titles)
@@ -130,23 +116,25 @@ int kernel(int optionflag,int level) {
 		if (level==-1) {
 			menuOption=showTitles();
 			switch (menuOption) {
-				case sLoad:
+				case menuLoad:
 					level=8; /* TODO: make read level function */
 					break;
-				case sStart:
+				case menuStart:
 					level=1;
 					break;
-				case sQuit:
+				case menuQuit:
 					quit=1;
 					break;
 			}
 		}
 		if (!quit) {
-			quit=control(optionflag,level);
+			quit=playgame(optionflag,level);
+			level = -1;
 		}
 	} while(!quit);
 
 	kidFree();
+	inputStopTimer();
 	outputStop();
 	return 0;
 }
diff --git a/FP/src/ker/titles.c b/FP/src/ker/titles.c
index 9ce025c..6ea83fe 100644
--- a/FP/src/ker/titles.c
+++ b/FP/src/ker/titles.c
@@ -39,11 +39,11 @@ titles.c: FreePrince : Titles, animation and presentation
 tMenuOption getAction(tKey key) {
 	switch(key.actionPerformed) {
 	case quit:
-		return sQuit;
+		return menuQuit;
 	case load:
-		return sLoad;
+		return menuLoad;
 	default:
-		return sStart;
+		return menuStart;
 	}
 }
 
@@ -62,7 +62,7 @@ tMenuOption sleep(int ticks) {
 			) 
 			return getAction(key); /* return the results of this action */ 
 	}
-	return sNone;
+	return menuNone;
 }
 
 tMenuOption showTitles() {
@@ -79,27 +79,26 @@ tMenuOption showTitles() {
 	main_title = resLoad(RES_IMG_MAIN_BACKGROUND);
 	if (! main_title) {
 		printf("The resource couldn't be loaded!\n");
-		return sQuit;
+		return menuQuit;
 	}
 	outputClearScreen();
-	inputInitTimer();
 	/* The main background */
 	outputDrawBitmap(main_title->pFrames[0], 0, 0);
 	outputUpdateScreen();
 	result=sleep(12);
-	if (result!=sNone) return result;
+	if (result!=menuNone) return result;
 	/* The presents */
 	outputDrawBitmap(main_title->pFrames[1], 100, 100);
 	outputUpdateScreen();
 	result=sleep(12);
-	if (result!=sNone) return result;
+	if (result!=menuNone) return result;
 	/* The author*/
 	outputClearScreen();
 	outputDrawBitmap(main_title->pFrames[0], 0, 0);
 	outputDrawBitmap(main_title->pFrames[2], 100, 100);
 	outputUpdateScreen();
 	result=sleep(12);
-	if (result!=sNone) return result;
+	if (result!=menuNone) return result;
 	/* The game name*/
 	outputClearScreen();
 	outputDrawBitmap(main_title->pFrames[0], 0, 0);
@@ -108,7 +107,7 @@ tMenuOption showTitles() {
 	outputUpdateScreen();
 	/*SDL_Delay(1050);*/
 	result=sleep(12);
-	if (result!=sNone) return result;
+	if (result!=menuNone) return result;
 
 	/*
 	 * The outputDraw doesn't support the text files yet
@@ -116,7 +115,7 @@ tMenuOption showTitles() {
 	main_text = resLoad(RES_IMG_TEXT_BACKGROUND);
 	if (! main_text) {
 		printf("The resource couldn't be loaded!\n");
-		return sQuit;
+		return menuQuit;
 	}
 	*/
 	/* The presents */
@@ -127,9 +126,8 @@ tMenuOption showTitles() {
 	*/
 	do {
 		result=sleep(1000);
-	} while (result==sNone);
+	} while (result==menuNone);
 	
-	inputStopTimer();
 	resFree(main_title);
 	return result;
 }	
diff --git a/FP/src/out/input.c b/FP/src/out/input.c
index ca83945..be493c0 100644
--- a/FP/src/out/input.c
+++ b/FP/src/out/input.c
@@ -52,14 +52,18 @@ int editAction(tKey* key,SDLKey k) {
 	/* Control actions */
 	if (inputGetCtrl(key->status)) {
 		switch (k) {
-			case SDLK_l:
-				key->actionPerformed=load;
-				break;
-			case SDLK_q:	
-				key->actionPerformed=quit;
-				break;
-			default:
-				break;
+		case SDLK_l:
+			key->actionPerformed=load;
+			break;
+		case SDLK_q:	
+			key->actionPerformed=quit;
+			break;
+		case SDLK_r:	
+			key->actionPerformed=gotoTitles;
+			break;
+		
+		default:
+			break;
 		}
 	}
 	/* Shift actions */
diff --git a/FP/src/res/maps.c b/FP/src/res/maps.c
index cf0ebd0..dbfaaaa 100644
--- a/FP/src/res/maps.c
+++ b/FP/src/res/maps.c
@@ -32,10 +32,12 @@ maps.c: Freeprince : Map handling library
 
 #include <string.h> /* mempcy */
 #include "maps.h"
+#include "room.h"
 
 static unsigned char* slevel;
 static int sscreen;
 
+
 /* Privates */
 
 void maps_getStartPosition(int* pantalla, int* p, int *b,tDirection *sentido,tDirection *sentido2) {
@@ -82,7 +84,128 @@ int levelUse(void* level) {
 	return level==NULL;
 }
 
-int levelGetScreenWalls(unsigned char* data,unsigned char* borders) {
+tRoom levelGetRoom(tRoomId roomId) {
+	tRoom result;
+	tRoomId roomAux;
+
+	/* SET room id*/
+	result.id=roomId;
+
+	/* SET room links */
+	memcpy(result.links,slevel+MAPS_BLOCK_OFFSET_LINK+((roomId-1)*4),4);
+	/* up corners */
+	roomAux=result.links[2];
+	if (roomAux) {
+		result.corners[0]=slevel[MAPS_BLOCK_OFFSET_LINK+((roomAux-1)*4)+0];
+		result.corners[1]=slevel[MAPS_BLOCK_OFFSET_LINK+((roomAux-1)*4)+1];
+	} else {
+		result.corners[0]=0;
+		result.corners[1]=0;
+	}
+	/* down corners */
+	roomAux=result.links[3];
+	if (roomAux) {
+		result.corners[2]=slevel[MAPS_BLOCK_OFFSET_LINK+((roomAux-1)*4)+0];
+		result.corners[3]=slevel[MAPS_BLOCK_OFFSET_LINK+((roomAux-1)*4)+1];
+	} else {
+		result.corners[2]=0;
+		result.corners[3]=0;
+	}
+	
+	/* SET corner bytes */
+	/* left+up */
+	if ((roomAux=result.corners[0])) {
+		result.fore[0]=slevel[MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+29];
+		result.back[0]=slevel[MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+29];
+	} else {
+		result.fore[0]=MAP_F_WALL;
+		result.back[0]=MAP_B_NONE;
+	}
+	/* right+up */
+	if ((roomAux=result.corners[1])) {
+		result.fore[11]=slevel[MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+20];
+		result.back[11]=slevel[MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+20];
+	} else {
+		result.fore[11]=MAP_F_FREE;
+		result.back[11]=MAP_B_NONE;
+	}
+	/* left+down */
+	if ((roomAux=result.corners[2])) {
+		result.fore[48]=slevel[MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+9];
+		result.back[48]=slevel[MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+9];
+	} else {
+		result.fore[48]=MAP_F_WALL;
+		result.back[48]=MAP_B_NONE;
+	}
+	/* right+down */
+	if ((roomAux=result.corners[3])) {
+		result.fore[59]=slevel[MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+0];
+		result.back[59]=slevel[MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+0];
+	} else {
+		result.fore[59]=MAP_F_WALL;
+		result.back[59]=MAP_B_NONE;
+	}
+
+	/* Left room */
+	if ((roomAux=result.links[0])) {
+		result.fore[12]=slevel[MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+9];
+		result.back[12]=slevel[MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+9];
+		result.fore[24]=slevel[MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+19];
+		result.back[24]=slevel[MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+19];
+		result.fore[36]=slevel[MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+29];
+		result.back[36]=slevel[MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+29];
+	} else {
+		result.fore[12]=MAP_F_WALL;
+		result.back[12]=MAP_B_NONE;
+		result.fore[24]=MAP_F_WALL;
+		result.back[24]=MAP_B_NONE;
+		result.fore[36]=MAP_F_WALL;
+		result.back[36]=MAP_B_NONE;	
+	}
+
+	/* Right room */
+	if ((roomAux=result.links[1])) {
+		result.fore[11]=slevel[MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+0];
+		result.back[11]=slevel[MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+0];
+		result.fore[23]=slevel[MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+10];
+		result.back[23]=slevel[MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+10];
+		result.fore[35]=slevel[MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+20];
+		result.back[35]=slevel[MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+20];
+	} else {
+		result.fore[11]=MAP_F_WALL;
+		result.back[11]=MAP_B_NONE;
+		result.fore[23]=MAP_F_WALL;
+		result.back[23]=MAP_B_NONE;
+		result.fore[35]=MAP_F_WALL;
+		result.back[35]=MAP_B_NONE;	
+	}
+
+	/* Top room */
+	if ((roomAux=result.links[2])) {
+		memcpy(result.fore+1,slevel+MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+20,10);
+		memcpy(result.back+1,slevel+MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+20,10);
+	} else {
+		memcpy(result.fore+1,"aaaa aaaa ",10); /* TODO: use tiles */
+		memcpy(result.back+1,"aaaa aaaa ",10); /* TODO: use tiles */
+	}
+
+	/* Bottom room */
+	if ((roomAux=result.links[3])) {
+		memcpy(result.fore+49,slevel+MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+0,10);
+		memcpy(result.back+49,slevel+MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+0,10);
+	} else {
+		memcpy(result.fore+49,"aaaa aaaa ",10); /* TODO: use tiles */
+		memcpy(result.back+49,"aaaa aaaa ",10); /* TODO: use tiles */
+	}
+
+	/* Main room */
+	memcpy(result.fore+13,slevel+MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+0,10);
+	memcpy(result.back+13,slevel+MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+0,10);
+	memcpy(result.fore+25,slevel+MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+10,10);
+	memcpy(result.back+25,slevel+MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+10,10);
+	memcpy(result.fore+37,slevel+MAPS_BLOCK_OFFSET_WALL+30*(roomAux-1)+20,10);
+	memcpy(result.back+37,slevel+MAPS_BLOCK_OFFSET_BACK+30*(roomAux-1)+20,10);
+
 /* This will save a screen map into data.
  * 
  * data is a pre-allocated array with 10x3=30 bytes with the screen map
@@ -94,33 +217,26 @@ int levelGetScreenWalls(unsigned char* data,unsigned char* borders) {
  * In case the screen doesn't exist the 0x00 (free foreground) byte will
  * be returned for the bottom and right sides, the wall foreground for
  * the left side and the simple tile byte for the top side.
- */
-
-	memcpy(data,slevel+MAPS_BLOCK_OFFSET_WALL+30*(sscreen-1),30);
-	return 0;
-}
-
-int levelGetScreenItems(unsigned char* data,unsigned char* borders) {
-/* This will save a screen map modifiers into data.
+ * int levelGetScreenItems(unsigned char* data,unsigned char* borders) {
+ * This will save a screen map modifiers into data.
  *
  * data and borders are in the same form as Walls but they contain
  * additional modifiers that must be defined in maps.h.
  * e.g. MAPS_ITEMS_DOOROPEN 0x01
  */
 
-	memcpy(data,slevel+MAPS_BLOCK_OFFSET_BACK+30*(sscreen-1),30);
-	return 0;
+	return result;
 }
 
-int levelMoveScreen(tDirection direction) {
-/* Moves the position screen that is inside the library
+/*int levelMoveScreen(tDirection direction) {
+ * Moves the position screen that is inside the library
  *
  * Returns 0 id the screen didn't exist and the screen id
  * in case the screen was moved
- */
+ *
  
 	return sscreen=slevel[MAPS_BLOCK_OFFSET_LINK+((sscreen-1)*4)+direction]; 
-}
+}*/
 
 int levelGetGuards(/* TODO: add modifiers */);
 int levelGetDoorMap(/* TODO: idem */);