author | ecalot
<ecalot> 2004-08-25 10:12:23 UTC |
committer | ecalot
<ecalot> 2004-08-25 10:12:23 UTC |
parent | d76e26dbaa09f8ad44a87244e603e762adeea7bd |
FP/src/Makefile | +0 | -3 |
FP/src/include/types.h | +5 | -2 |
FP/src/ker/room.c | +9 | -3 |
FP/src/res/maps.c | +39 | -63 |
diff --git a/FP/src/Makefile b/FP/src/Makefile index 2d61f28..df46dfb 100644 --- a/FP/src/Makefile +++ b/FP/src/Makefile @@ -64,9 +64,6 @@ $(EXEFILE): $(OBJFILES) $(MAKEDIR) bin $(CC) $(OPTIONS) -o $(EXEFILE) $(OBJFILES) $(LIBS) $(LINKEROPTIONS) $(INFO) Program successfully compiled - $(INFO) - $(INFO) Please read readme.txt for syntax information - $(INFO) ################### diff --git a/FP/src/include/types.h b/FP/src/include/types.h index 6ac73fb..f42152c 100644 --- a/FP/src/include/types.h +++ b/FP/src/include/types.h @@ -39,9 +39,11 @@ typedef unsigned char tRoomId; typedef unsigned char tTileId; typedef unsigned char tModId; +typedef enum {eOpenTimer,eOpen,eClose,eClosing,eOpening,eClosingFast}tGateAction; + typedef struct { - int status; - int action; + int frame; + tGateAction action; } tGate; typedef struct { @@ -55,6 +57,7 @@ typedef struct { unsigned char back [24*30]; tGate** screenGates[24]; tGate* gates; + int totalGates; tEvent events[256]; int time; unsigned char start[3]; diff --git a/FP/src/ker/room.c b/FP/src/ker/room.c index 480693b..9f8db9b 100644 --- a/FP/src/ker/room.c +++ b/FP/src/ker/room.c @@ -63,7 +63,8 @@ void roomFree() { tTile roomGetTile(tRoom* room,int x, int y) { tTile result; tTileId fore; - + tRoomId roomId; + fore=room->fore[x+12*y]; result.back=room->back[x+12*y]; result.code=fore&0x1F; @@ -71,13 +72,18 @@ tTile roomGetTile(tRoom* room,int x, int y) { switch (result.code) { /* TODO: use arrays and a better algorithm */ case T_GATE: case T_EXIT_LEFT: + roomId=room->id; + if (y==0) roomId=room->links[eUp]; + if (x==0) roomId=room->links[eLeft]; + if (y==4) roomId=room->links[eDown]; + if (x==11)roomId=room->links[eRight]; result.hasGateFrame=(result.code==T_GATE); result.bricks=0; result.hasPillar=0; result.hasBigPillar=0; result.isGate=(result.code==T_GATE); - printf("getting details on gate at %d,%d\n",x,y); - result.gateInfo=NULL/*room->level->screenGates[room->id][back]*/; + printf("getting details on gate at %d,%d screen %d, door number %d\n",x,y,roomId,result.back); + result.gateInfo=room->level->screenGates[roomId-1][result.back]; result.walkable=1; result.hasChopper=0; result.isExit=(result.code==T_EXIT_LEFT)?1:((result.code==T_EXIT_RIGHT)?2:0); diff --git a/FP/src/res/maps.c b/FP/src/res/maps.c index b3acb12..45ba3d7 100644 --- a/FP/src/res/maps.c +++ b/FP/src/res/maps.c @@ -39,40 +39,11 @@ maps.c: Freeprince : Map handling library #define slevel(field) (map->field) -/* Privates - -void maps_getStartPosition(int* pantalla, int* p, int *b,tDirection *sentido,tDirection *sentido2) { - int valor; - - *pantalla =slevel[MAPS_BLOCK_OFFSET_START_POSITION]; - valor =slevel[MAPS_BLOCK_OFFSET_START_POSITION+1]; - *b =(valor%10); - *p =(valor/10); - *sentido =(slevel[MAPS_BLOCK_OFFSET_START_POSITION+2])?eRight:eLeft; - *sentido2 =(slevel[MAPS_BLOCK_OFFSET_START_POSITION+6])?eRight:eLeft; -} - -void maps_getGuard(int pantalla,int *p,int *b,int *skill,int *color,tDirection *sentido,int *exists) { - Posicion - unsigned char valor=(slevel[(MAPS_BLOCK_OFFSET_GUARD_POSITION+sscreen-1)]); - *exists = (valor<30); - *b = (valor%10); - *p = (valor/10); - sentido - *sentido=slevel[MAPS_BLOCK_OFFSET_GUARD_DIRECTION+pantalla-1]?eRight:eLeft; - * skill * - *skill =slevel[MAPS_BLOCK_OFFSET_GUARD_SKILL+pantalla-1]; - * Color * - *color =slevel[MAPS_BLOCK_OFFSET_GUARD_COLOR+pantalla-1]; -} -*/ -/* Publics */ void* mapLoadLevel(tMemory level) { tMap* map=(tMap*)malloc(sizeof(tMap)); - int i; + int i,j; int gates=0; int gateInRoom=0; - int change=-1; tGate** auxGates=malloc(sizeof(tGate*)*24*30); /* copy maps, links and start position */ @@ -82,43 +53,42 @@ void* mapLoadLevel(tMemory level) { memcpy(map->links,level.array+MAPS_BLOCK_OFFSET_LINK,4*24); /* generate and load gate structures */ - for (i=0;i<30*24;i++) { /* count gates and create gate tree middle nodes */ - auxGates[i]=NULL; /* clear array */ - if ((map->fore[i]==T_GATE)||(map->fore[i]==T_EXIT_LEFT)) { - if (i/30!=change) { - printf("Screen %d has %d gates.",change,gateInRoom); - map->screenGates[change]=malloc(gateInRoom*sizeof(tGate*)); - gateInRoom=0; - } else { + for (i=0;i<24;i++) { /* count gates and create gate tree middle nodes */ + for (j=0;j<30;j++) { + if (((map->fore[i*30+j]&0x1f)==T_GATE)||((map->fore[i*30+j]&0x1f)==T_EXIT_LEFT)) { gateInRoom++; + gates++; } - gates++; } - } - if (gateInRoom) { - printf("Screen %d has %d gates.",change,gateInRoom); - map->screenGates[change]=malloc(gateInRoom*sizeof(tGate*)); + fprintf(stderr,"Screen %d has %d gates.\n",i,gateInRoom); + if (gateInRoom) { + map->screenGates[i]=malloc(gateInRoom*sizeof(tGate*)); + } else { + map->screenGates[i]=NULL; + } gateInRoom=0; } - change=-1; /* create gates sctucture */ map->gates=malloc(gates*sizeof(tGate)); + map->totalGates=gates; gates=0; - for (i=0;i<30*24;i++) { - if ((map->fore[i]==T_GATE)||(map->fore[i]==T_EXIT_LEFT)) { - tGate newGate; - if (i/30!=change) { - gateInRoom=0; - } else { + for (i=0;i<24;i++) { + for (j=0;j<30;j++) { + if (((map->fore[i*30+j]&0x1f)==T_GATE)||((map->fore[i*30+j]&0x1f)==T_EXIT_LEFT)) { + tGate newGate; + newGate.frame=map->back[i*30+j]; + newGate.action=map->back[i*30+j]?eOpen:eClose; + map->back[i*30+j]=gateInRoom; + fprintf(stderr,"mapLoadLevel: Asignando gate pointer: screen %d, gate number %d\n",i,gateInRoom); + map->screenGates[i][gateInRoom]=map->gates+gates; + auxGates[i*30+j]=map->gates+gates; + fprintf(stderr,"mapLoadLevel: Loading gate: indexed=%d gate pointer=%p\n",i,(void*)auxGates[i*30+j]); + map->gates[gates++]=newGate; gateInRoom++; } - newGate.status=map->back[i]; - newGate.action=map->back[i]; - map->back[i]=gateInRoom; - map->screenGates[i/30][gateInRoom]=map->gates+gates; - auxGates[i]=map->gates+gates; - map->gates[gates++]=newGate; } + if (!gateInRoom) map->screenGates[i]=NULL; + gateInRoom=0; } for (i=0;i<256;i++) { unsigned char byte1=level.array[MAPS_BLOCK_OFFSET_GATE_1+i]; @@ -126,10 +96,10 @@ void* mapLoadLevel(tMemory level) { int S,L,T; S=((byte1>>5)&3)|((byte2>>3)&28); L=byte1&31; - T=(byte1>>7)&1; - fprintf(stderr,"mapLoadLevel: Loading event: S=%d L=%d T=%d\n",S,L,T); + T=!((byte1>>7)&1); map->events[i].triggerNext=T; map->events[i].gate=auxGates[(S-1)*30+L]; /* in case of error null is assigned */ + fprintf(stderr,"mapLoadLevel: Loading event: S=%d L=%d T=%d gate number=%d gate pointer=%p\n",S,L,T,(S-1)*30+L,(void*)auxGates[(S-1)*30+L]); } free(auxGates); return (void*)map; @@ -291,14 +261,20 @@ void mapStart(tMap* map, tKid* kid, tRoomId *roomId, int level) { void mapMove(tMap* map) { slevel(time)++; if (slevel(time)==1000) slevel(time)=0; + } void mapPressedTile(tMap* map, tTile tile, int s, int x, int y) { - if (tile.isPressable) { - /* drop or raise button */ - fprintf(stderr,"mapPressedTile: throw event %d\n",tile.back); - } - + if (tile.isPressable) { + tGate* gate; + /* drop or raise button */ + fprintf(stderr,"mapPressedTile: throw event %d\n",tile.back); + do { + gate=map->events[tile.back].gate; + fprintf(stderr,"mapPressedTile: activating door. gate pointer=%p\n",(void*)gate); + /*fprintf(stderr,"mapPressedTile: activating door. status=%d action=%d\n",gate->status,gate->action);*/ + } while (0&&map->events[tile.back++].triggerNext); + } }