diff --git a/map_edit/font6x9.bbm b/map_edit/font6x9.bbm new file mode 100644 index 0000000..d612a5f Binary files /dev/null and b/map_edit/font6x9.bbm differ diff --git a/map_edit/font6x9.lbm b/map_edit/font6x9.lbm new file mode 100644 index 0000000..867fed7 Binary files /dev/null and b/map_edit/font6x9.lbm differ diff --git a/map_edit/iff.h b/map_edit/iff.h new file mode 100644 index 0000000..5979488 --- /dev/null +++ b/map_edit/iff.h @@ -0,0 +1,96 @@ +#ifndef NULL +#define NULL 0 +#endif + +#ifndef FALSE +#define FALSE 0 +#define TRUE 1 +#endif + +#define LONG unsigned long +#define ULONG unsigned long +#define UBYTE unsigned char +#define UWORD unsigned short +#define DWORD unsigned long + +long ByteFlipLong(long); +UCHAR *Readiff(char *); /* this returns back a bitmap with a picture in it*/ + +typedef LONG ID; /* An ID is four printable ASCII chars like FORM or DPPV */ + +#define MakeID(d,c,b,a) ((DWORD)(a)<<24 | (DWORD)(b)<<16 | (DWORD)(c)<<8 | (DWORD)(d) ) + +#define FORM MakeID('F','O','R','M') +#define PROP MakeID('P','R','O','P') +#define LIST MakeID('L','I','S','T') +#define CAT MakeID('C','A','T',' ') +#define FILLER MakeID(' ',' ',' ',' ') + +typedef struct + { + ID type; + long cksize; + ID subtype; + } form_chunk; + +typedef struct { + ID ckID; + LONG ckSize; + } ChunkHeader; + +typedef struct { + ID ckID; + LONG ckSize; + UBYTE ckData[ 1 /*REALLY: ckSize*/ ]; + } Chunk; + +#define ID_PBM MakeID('P','B','M',' ') +#define ID_ILBM MakeID('I','L','B','M') +#define ID_BMHD MakeID('B','M','H','D') +#define ID_CMAP MakeID('C','M','A','P') +#define ID_GRAB MakeID('G','R','A','B') +#define ID_DEST MakeID('D','E','S','T') +#define ID_SPRT MakeID('S','P','R','T') +#define ID_CAMG MakeID('C','A','M','G') +#define ID_BODY MakeID('B','O','D','Y') + +/* ---------- BitMapHeader ---------------------------------------------*/ + +typedef UBYTE Masking; /* Choice of masking technique.*/ +#define mskNone 0 +#define mskHasMask 1 +#define mskHasTransparentColor 2 +#define mskLasso 3 + +#define cmpNone 0 +#define cmpByteRun1 1 + +/* A BitMapHeader is stored in a BMHD chunk. */ +typedef struct { + UWORD w, h; /* raster width & height in pixels */ + UWORD x, y; /* position for this image */ + UBYTE nPlanes; /* # source bitplanes */ + UBYTE masking; /* masking technique */ + UBYTE compression; /* compression algoithm */ + UBYTE pad1; /* UNUSED. For consistency, put 0 here.*/ + UWORD transparentColor; /* transparent "color number" */ + UBYTE xAspect, yAspect; /* aspect ratio, a rational number x/y */ + UWORD pageWidth, pageHeight; /* source "page" size in pixels */ + } BitMapHeader; +/* RowBytes computes the number of bytes in a row, from the width in pixels.*/ +#define RowBytes(w) (((w) + 15) >> 4 << 1) + +/* A CMAP chunk is a packed array of ColorRegisters (3 bytes each). */ +typedef struct { + UBYTE red, green, blue; /* MUST be UBYTEs so ">> 4" won't sign extend.*/ + } ColorRegister; + +/* Use this constant instead of sizeof(ColorRegister). */ +#define sizeofColorRegister 3 + +long ByteFlipLong(long); +void ByteFlipShort(short *); +short iffswab(unsigned short); +short swab(unsigned short); + + \ No newline at end of file diff --git a/map_edit/kit.map b/map_edit/kit.map new file mode 100644 index 0000000..2f53bd2 Binary files /dev/null and b/map_edit/kit.map differ diff --git a/map_edit/kitmap.sav b/map_edit/kitmap.sav new file mode 100644 index 0000000..91ce159 Binary files /dev/null and b/map_edit/kitmap.sav differ diff --git a/map_edit/m1.bbm b/map_edit/m1.bbm new file mode 100644 index 0000000..c498f34 Binary files /dev/null and b/map_edit/m1.bbm differ diff --git a/map_edit/m1.c b/map_edit/m1.c new file mode 100644 index 0000000..6ae8fda --- /dev/null +++ b/map_edit/m1.c @@ -0,0 +1,2646 @@ +// Map Editor for Animation Construction Kit 3D +// Main program +// Author: Lary Myers +// Copyright (c) 1994 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ack3d.h" +#include "ackeng.h" +#include "m1.h" + +extern UCHAR colordat[]; +extern char *smFont; +extern char *mdFont; +extern UCHAR FontUseColor; +extern UCHAR FontTransparent; +extern UCHAR FontColor; +extern UCHAR TextBGcolor; +extern UCHAR ButtonColor; +extern UCHAR ButtonUpperColor; +extern UCHAR ButtonLowerColor; +extern UCHAR BoxColor; +extern short ReadErrorCode; + +void ShowMaskedBitmap(int x,int y,UCHAR *bm); + +//============================================================================= +// Globals +//============================================================================= + HS HotSpots[] = { + AI_UP,283,82,292,93, // Up + AI_RIGHT,292,95,304,104, // Right + AI_DOWN,283,106,292,117, // Down + AI_LEFT,271,95,283,104, // Left + AI_MINI,MINI_X,MINI_Y,MINI_X1,MINI_Y1, // Small map + AI_SELECT,270,61,306,74, // Select + AI_VIEW,5,183,44,196, // View + AI_FLOORS,52,165,81,178, // Floor + AI_SAVE,52,183,81,196, // Save + AI_MAP,88,165,118,178, // Map + AI_WALLS,88,183,118,196, // Walls + AI_CEILING,127,165,169,178, // Ceiling + AI_OBJECTS,127,183,169,196, // Objects + AI_OPTIONS,179,183,221,196, // Options + AI_EDITWIN,0,0,256,160, // Edit Window + AI_BM_UP,308,15,317,26, // Bitmap Up + AI_BM_DOWN,308,39,317,50, // Bitmap Down + AI_EXIT,5,165,44,178, // Exit + -1,0,0,0,0 // End of table + }; + + + HS SelHotSpots[] = { + 1,6,181,40,194, // Cancel + 2,115,181,140,194, // Prev + 3,178,181,204,194, // Next + 4,0,0,319,178, // Bitmap window + -1,0,0,0,0 // End of table + }; + + + short ButtonTable[] = { + AI_MAP, + AI_FLOORS, + AI_CEILING + }; + + + OPTS LeftOpts[] = { + OPT_NORMAL, 0,0,0," Normal Sq ", + OPT_SLIDING, 0,0,0," Sliding Door ", + OPT_SPLIT, 0,0,0," Split Door ", + OPT_SECRET, 0,0,0," Secret Door ", + OPT_LOCKED, 0,0,0," Locked Door ", + OPT_TRANS, 0,0,0," Transparent ", + OPT_MULTI, 0,0,0," MultiHeight ", + OPT_RAISED, 0,0,0," Raised Wall ", + OPT_CANCEL, 44,0,0," Cancel ", + -1,0,0,0,0 + }; + + OPTS RightOpts[] = { + OPT_FILL, 0,0,0," Fill Map ", + OPT_BORDER, 0,0,0," Draw Border ", + OPT_CLEAR, 0,0,0," Clear Map ", + OPT_PASSABLE, 0,0,0," Passable ", + OPT_PALETTE, 0,0,0," Bm Palette ", + OPT_MAPPAL, 0,0,0," Map Palette ", + -1,0,0,0,0 + }; + + + + OPTS MultiOpts[] = { + 0,0,0,0," Select Bitmap ", + 1,0,0,0," Accept ", + 2,0,0,0," Cancel ", + -1,0,0,0,0 + }; + + +//============================================================================= +// More globals +//============================================================================= + UCHAR **BitmapPtr; + UCHAR *Bitmaps[256]; + UCHAR *ObjBitmaps[256]; + UCHAR ObjbmNum[256]; + UINT MedxGrid[GRID_ARRAY]; + UINT MedyGrid[GRID_ARRAY]; + UINT MedGrid[GRID_MAX]; + UINT MobGrid[GRID_MAX]; + UINT MedFloorMap[GRID_MAX]; + UINT MedCeilMap[GRID_MAX]; + UCHAR *MedMultiPtrs[GRID_MAX]; + int GridRow,GridCol; + int ViewMode; + int ViewType,LastViewType; + int EditType; + UINT WallFlags; + UINT ObjFlags; + int MaxCol,MaxRow; + int LastgRow,LastgCol; + int ModifyFlag; + short LastMX,LastMY; + UINT CurrentCode; + UINT LastWallCode; + UINT LastObjCode; + UCHAR BaseColor; + UCHAR *VidBuf; + UCHAR *BgBuf; + UCHAR *BgBuf3D; + UCHAR *SelBgBuf; + UCHAR *BlankbmBuf; + char MapName[128]; + char PalName[128]; + UCHAR bmPalette[768]; + UCHAR MapPalette[768]; + +//============================================================================= +// +//============================================================================= +short GetAction(short mx,short my) +{ + int index; + +index = 0; + +while (1) + { + if (HotSpots[index].Action == -1) + break; + + if (mx >= HotSpots[index].x && + mx <= HotSpots[index].x1 && + my >= HotSpots[index].y && + my <= HotSpots[index].y1) + { + break; + } + index++; + } + +return(HotSpots[index].Action); +} + +//============================================================================= +// +//============================================================================= +short GetActionIndex(short action) +{ + short index; + +index = 0; + +while (HotSpots[index].Action != -1) + { + if (HotSpots[index].Action == action) + break; + + index++; + } + +return(index); +} + + +//============================================================================= +// +//============================================================================= +void PressButton(short ActionCode) +{ + int x,y,x1,y1; + short index; + +index = GetActionIndex(ActionCode); + +x = HotSpots[index].x; +y = HotSpots[index].y; +x1 = HotSpots[index].x1; +y1 = HotSpots[index].y1; + +HideMouse(); +DrawHorzLine(x,y,x1,ButtonLowerColor); +DrawVertLine(x,y+1,y1,ButtonLowerColor); +DrawVertLine(x1,y+1,y1,ButtonUpperColor); +DrawHorzLine(x,y1,x1,ButtonUpperColor); +ShowMouse(); +} + + +//============================================================================= +// +//============================================================================= +void ReleaseButton(short ActionCode) +{ + int x,y,x1,y1; + short index; + +index = GetActionIndex(ActionCode); + +x = HotSpots[index].x; +y = HotSpots[index].y; +x1 = HotSpots[index].x1; +y1 = HotSpots[index].y1; + +HideMouse(); +DrawHorzLine(x,y,x1,ButtonUpperColor); +DrawVertLine(x,y+1,y1,ButtonUpperColor); +DrawVertLine(x1,y+1,y1,ButtonLowerColor); +DrawHorzLine(x,y1,x1,ButtonLowerColor); +ShowMouse(); +} + + + +//============================================================================= +// +//============================================================================= +short GetSelAction(short mx,short my) +{ + int index; + +index = 0; + +while (1) + { + if (SelHotSpots[index].Action == -1) + break; + + if (mx >= SelHotSpots[index].x && + mx <= SelHotSpots[index].x1 && + my >= SelHotSpots[index].y && + my <= SelHotSpots[index].y1) + { + break; + } + index++; + } + +return(SelHotSpots[index].Action); +} + + + +//============================================================================= +// +//============================================================================= +void DrawYline(int x,int y) +{ + int i; + UCHAR *Video; + int offset; + +offset = (y*320)+x; +Video = (UCHAR *)VidBuf; +Video += offset; + +for (i = 0; i < GD_HHT; i++) + { + *Video++ = 15; + *Video++ = 15; + Video += 320; + } + +} + + +//============================================================================= +// +//============================================================================= +void DrawXline(int x,int y) +{ + UCHAR *Video; + int i,offset; + +offset = (y*320)+x; +Video = (UCHAR *)VidBuf; +Video += offset; + +for (i = 0; i < GD_HWT; i++) + { + *Video-- = 15; + *Video-- = 15; + Video += 320; + } + +} + +//============================================================================= +// +//============================================================================= +void DrawGridBlock(int x,int y) +{ + +DrawYline(x,y); +DrawXline(x+1,y); +DrawYline(x-(GD_FWT-2),y+GD_HHT-1); +DrawXline(x+GD_FWT-1,y+GD_HHT-1); + +} + +//============================================================================= +// +//============================================================================= +void DrawBitmapBlock(int x,int y,UCHAR *bm) +{ + int row,col,rFact; + UCHAR *Video,*vPos; + int offset; + +offset = (y*320)+x; +Video = (UCHAR *)VidBuf; +Video += offset; +vPos = Video; +bm = &bm[4]; + +for (row = 0; row < GD_HHT; row++) + { + Video = vPos; + for (col = 0; col < GD_HWT; col++) + { + *Video++ = *bm; + bm += 2; + *Video++ = *bm; + bm += 2; + Video += 320; + } + + bm += 66; + vPos += 320; + Video = vPos; + for (col = 1; col < GD_HWT; col++) + { + *Video++ = *bm; + bm += 2; + *Video++ = *bm; + bm += 2; + Video += 320; + } + bm += 66; + vPos -= 2; + } + +} + + + +//============================================================================= +// +//============================================================================= +void DrawYbitmap(int x,int y,UCHAR *bm,UCHAR Shade,int TransFlag) +{ + UCHAR *Video,*vPos; + UCHAR ch; + int row,col,offset,pos; + +offset = (y*320)+x; +Video = (UCHAR *)VidBuf; +Video += offset; +vPos = Video; +bm = &bm[4]; + +if (!TransFlag) + { + for (row = 0; row < GD_FHT; row++) + { + Video = vPos; + pos = 0; + for (col = 0; col < GD_HWT; col++) + { + ch = bm[pos] + Shade; + *Video++ = ch; + pos += 2; + ch = bm[pos] + Shade; + *Video++ = ch; + pos += 2; + Video += 320; + } + + bm += 128; + vPos += 320; + } + } +else + { + for (row = 0; row < GD_FHT; row++) + { + Video = vPos; + pos = 0; + for (col = 0; col < GD_HWT; col++) + { + ch = bm[pos]; + if (ch) + *Video = ch + Shade; + Video++; + pos += 2; + ch = bm[pos]; + if (ch) + *Video = ch + Shade; + pos += 2; + Video += 321; + } + + bm += 128; + vPos += 320; + } + } +} + + +//============================================================================= +// +//============================================================================= +void DrawXbitmap(int x,int y,UCHAR *bm,UCHAR Shade,int TransFlag) +{ + UCHAR *Video,*vPos; + UCHAR ch; + int row,col,offset,pos; + +offset = (y*320)+x; +Video = (UCHAR *)VidBuf; +Video += offset; +vPos = Video; +bm = &bm[4]; + +if (!TransFlag) + { + for (row = 0; row < GD_FHT; row++) + { + Video = vPos; + pos = 0; + for (col = 0; col < GD_HWT; col++) + { + ch = bm[pos] + Shade; + *Video-- = ch; + pos += 2; + ch = bm[pos] + Shade; + *Video-- = ch; + pos += 2; + Video += 320; + } + + bm += 128; + vPos += 320; + } + } +else + { + for (row = 0; row < GD_FHT; row++) + { + Video = vPos; + pos = 0; + for (col = 0; col < GD_HWT; col++) + { + ch = bm[pos]; + if (ch) + *Video = ch + Shade; + Video--; + pos += 2; + ch = bm[pos]; + if (ch) + *Video = ch + Shade; + pos += 2; + Video += 319; + } + + bm += 128; + vPos += 320; + } + } +} + +//============================================================================= +// +//============================================================================= +void ClearGridArea(UCHAR *BufPtr) +{ + int row,wt; + UCHAR *Video,*bPtr; + +Video = (UCHAR *)VidBuf; +bPtr = &BufPtr[4]; +row = ((MAP_Y*320)+MAP_X); +Video += row; +bPtr += row; +wt = (MAP_X1 - MAP_X) + 1; + +for (row = MAP_Y; row < MAP_Y1; row++) + { + memmove(Video,bPtr,wt); + Video += 320; + bPtr += 320; + } + +Video = (UCHAR *)VidBuf; +bPtr = &BgBuf[4]; +row = ((MINI_Y*320)+MINI_X); +Video += row; +bPtr += row; + +for (row = 0; row < 64; row++) + { + memmove(Video,bPtr,64); + Video += 320; + bPtr += 320; + } + +} + +//============================================================================= +// +//============================================================================= +void RefreshGrid(void) +{ + int row,wt; + UCHAR *Video,*vPtr; + +Video = VIDSEG; +vPtr = VidBuf; +row = ((MAP_Y*320)+MAP_X); +Video += row; +vPtr += row; +wt = (MAP_X1 - MAP_X) + 1; + +for (row = MAP_Y; row < MAP_Y1; row++) + { + memmove(Video,vPtr,wt); + Video += 320; + vPtr += 320; + } + +Video = VIDSEG; +vPtr = VidBuf; +row = ((MINI_Y*320)+MINI_X); +Video += row; +vPtr += row; + +for (row = 0; row < 64; row++) + { + memmove(Video,vPtr,64); + Video += 320; + vPtr += 320; + } + +} + +//============================================================================= +// +//============================================================================= +void DrawMultiBitmaps(int gPos,int x,int y) +{ + int cnt; + UCHAR *bmPtr,*mPtr; + UINT bNum; + +mPtr = MedMultiPtrs[gPos]; +if (mPtr == NULL) + return; + +cnt = 0; +y -= GD_FHT; + +while (cnt < MAX_MULTI && y >= MAP_Y) + { + bNum = mPtr[cnt]; + if (bNum) + { + bmPtr = Bitmaps[bNum & 0xFF]; + DrawYbitmap(x,y,bmPtr,0,0); + DrawXbitmap(x+1,y,bmPtr,0,0); + DrawYbitmap(x-(GD_FWT-2),y+GD_HHT,bmPtr,0,0); + DrawXbitmap(x+(GD_FWT-1),y+GD_HHT-1,bmPtr,0,0); + } + cnt++; + y -= GD_FHT; + } + +} + +//============================================================================= +// +//============================================================================= +void DrawGrid3D(void) +{ + int cnt,x,y,xOrg,yOrg; + int gPos,gOrg,row,col; + UCHAR *bmPtr; + UCHAR sValue,color,sValue1; + UINT bNum; + +xOrg = MAP_X + 128; +yOrg = MAP_Y + GD_FHT; + +gOrg = (GridRow * GRID_WIDTH) + GridCol; +ClearGridArea(BgBuf3D); + +row = GridRow; +sValue = sValue1 = 0; + +while (xOrg > MAP_X && yOrg < MAP_Y1) + { + x = xOrg; + y = yOrg; + gPos = gOrg; + col = GridCol; + cnt = 0; + while ((x+GD_FWT) <= MAP_X1 && cnt++ < 4) + { + + #if 0 + bNum = MedGrid[gPos]; + if (!bNum) + { + bNum = MedFloorMap[gPos]; + if (!bNum) + DrawGridBlock(x,y); + else + DrawBitmapBlock(x,y,Bitmaps[bNum & 0xFF]); + } + else + { + sValue1 = sValue = 1; + if (col & 1) sValue = 0; + if (row & 1) sValue1 = 0; + bmPtr = Bitmaps[bNum & 0xFF]; + bmPtr = &bmPtr[4]; + DrawYbitmap(x,y-GD_FHT,bmPtr,sValue1); + DrawXbitmap(x+1,y-GD_FHT,bmPtr,sValue); + DrawYbitmap(x-(GD_FWT-2),y-GD_HHT,bmPtr,0); + DrawXbitmap(x+(GD_FWT-1),y-GD_HHT-1,bmPtr,0); + } + #endif + + DrawBitmapBlock(x,y,Bitmaps[MedFloorMap[gPos] & 0xFF]); + sValue1 = sValue = 1; + if (col & 1) sValue = 0; + if (row & 1) sValue1 = 0; + + bNum = MedyGrid[gPos]; + if (bNum) + DrawYbitmap(x,y-GD_FHT,Bitmaps[bNum & 0xFF],sValue1,(bNum & WALL_TYPE_TRANS)); + + bNum = MedxGrid[gPos]; + if (bNum) + DrawXbitmap(x+1,y-GD_FHT,Bitmaps[bNum & 0xFF],sValue,(bNum & WALL_TYPE_TRANS)); + + bNum = MobGrid[gPos]; + if (bNum) + ShowMaskedBitmap(x-GD_HWT,y-GD_HHT,ObjBitmaps[ObjbmNum[bNum & 255]]); + + bNum = MedyGrid[gPos + GRID_WIDTH]; + if (bNum) + DrawYbitmap(x-(GD_FWT-2),y-GD_HHT,Bitmaps[bNum & 0xFF],0,(bNum & WALL_TYPE_TRANS)); + + bNum = MedxGrid[gPos + 1]; + if (bNum) + DrawXbitmap(x+(GD_FWT-1),y-GD_HHT-1,Bitmaps[bNum & 0xFF],0,(bNum & WALL_TYPE_TRANS)); + + if (ViewType == VT_CEIL) + { + bNum = MedCeilMap[gPos]; + if (bNum) + DrawBitmapBlock(x,y-GD_FHT,Bitmaps[bNum & 0xFF]); + } + + if (MedGrid[gPos] & WALL_TYPE_MULTI) + DrawMultiBitmaps(gPos,x,y); + + + col++; + gPos++; + x += (GD_FWT-2); + y += (GD_HHT-1); + } + + row++; + gOrg += GRID_WIDTH; + + xOrg -= (GD_FWT-2); + yOrg += (GD_HHT-1); + } + +gPos = 0; + +for (y = 0; y < GRID_HEIGHT; y++) + { + for (x = 0; x < GRID_WIDTH; x++) + { + sValue = MedGrid[gPos++]; + color = 255; + if (sValue) color = sValue; + VidBuf[((y+MINI_Y)*320)+(x+MINI_X)] = color; + } + } + +x = MINI_X + GridCol; +y = MINI_Y + GridRow; + +VidBuf[(y*320)+x] = 128; + +HideMouse(); +RefreshGrid(); +ShowMouse(); + +} + +//============================================================================= +// +//============================================================================= +void Draw2Dxline(int x,int y,UCHAR color) +{ + int row,offset; + UCHAR *vPtr; + +offset = (y*320)+x; +vPtr = VidBuf + offset; + +vPtr -= 638; +*vPtr = color; +vPtr += 319; +memset(vPtr,color,3); +vPtr += 319; + +for (row = 6; row < 18; row++) + { + memset(vPtr,color,5); + vPtr += 320; + } + +vPtr++; +memset(vPtr,color,3); +vPtr[321] = color; + +} + +//============================================================================= +// +//============================================================================= +void DrawxLineMulti(int x,int y,UCHAR color) +{ + int row,offset; + UCHAR *vPtr; + +offset = (y*320)+x; +vPtr = VidBuf + offset + 322; +for (row = 0; row < 12; row += 2) + { + *vPtr = color; + vPtr += 640; + } + +} + +//============================================================================= +// +//============================================================================= +void Draw2Dyline(int x,int y,UCHAR color) +{ + int offset; + UCHAR *vPtr; + +offset = (y*320)+x; +vPtr = VidBuf + offset; + +memset(vPtr,color,15); +vPtr += 319; +memset(vPtr,color,17); +vPtr += 319; +memset(vPtr,color,19); +vPtr += 321; +memset(vPtr,color,17); +vPtr += 321; +memset(vPtr,color,15); + +} + +//============================================================================= +// +//============================================================================= +void DrawyLineMulti(int x,int y,UCHAR color) +{ + int offset; + UCHAR *vPtr; + +offset = (y*320)+x; +vPtr = VidBuf + offset + 640; + +for (offset = 0; offset < 15; offset += 2) + vPtr[offset] = color; + +} + +//============================================================================= +// +//============================================================================= +void DrawGrid2D(void) +{ + int x,y,gRow,gCol; + int row,col,gOrg,gPos; + UINT mCode; + UCHAR sValue,color,sValue1; + +gOrg = (GridRow * GRID_WIDTH) + GridCol; + +gRow = GridRow; +y = 1; + +for (row = 0; row < 9; row++) + { + gCol = GridCol; + gPos = gOrg; + x = 8; + for (col = 0; col < 12; col++) + { + mCode = MedxGrid[gPos]; + if (mCode) + { + mCode += BaseColor; + Draw2Dxline(x-5,y+5,mCode); + if (mCode & WALL_TYPE_MULTI) + DrawxLineMulti(x-5,y+5,(mCode ^ 15)-14); + if (mCode & (DOOR_TYPE_SLIDE+DOOR_TYPE_SPLIT)) + DrawxLineMulti(x-5,y+5,255); + } + + mCode = MedxGrid[gPos+1]; + if (mCode) + { + mCode += BaseColor; + Draw2Dxline(x+15,y+5,mCode); + if (mCode & WALL_TYPE_MULTI) + DrawxLineMulti(x+15,y+5,(mCode ^ 15)-14); + if (mCode & (DOOR_TYPE_SLIDE+DOOR_TYPE_SPLIT)) + DrawxLineMulti(x+15,y+5,255); + } + + mCode = MedyGrid[gPos]; + if (mCode) + { + mCode += BaseColor; + Draw2Dyline(x,y,mCode); + if (mCode & WALL_TYPE_MULTI) + DrawyLineMulti(x,y,(mCode ^ 15)-14); + if (mCode & (DOOR_TYPE_SLIDE+DOOR_TYPE_SPLIT)) + DrawyLineMulti(x,y,255); + } + + mCode = MedyGrid[gPos+GRID_WIDTH]; + if (mCode) + { + mCode += BaseColor; + Draw2Dyline(x,y+17,mCode); + if (mCode & WALL_TYPE_MULTI) + DrawyLineMulti(x,y+17,(mCode ^ 15)-14); + if (mCode & (DOOR_TYPE_SLIDE+DOOR_TYPE_SPLIT)) + DrawyLineMulti(x,y+17,255); + } + + x += 20; + gPos++; + } + + gOrg += 64; + y += 17; + } + + +gPos = 0; + +for (y = 0; y < GRID_HEIGHT; y++) + { + for (x = 0; x < GRID_WIDTH; x++) + { + sValue = MedGrid[gPos++]; + color = 255; + if (sValue) color = sValue; + VidBuf[((y+MINI_Y)*320)+(x+MINI_X)] = color; + } + } + + +x = MINI_X + GridCol; +y = MINI_Y + GridRow; + +VidBuf[(y*320)+x] = 128; + +} + +//============================================================================= +// +//============================================================================= +void DrawTinyBitmap(int x,int y,UCHAR *bm) +{ + int offset,row,col,pos,pOrg; + UCHAR *Video,*bmPtr; + +offset = (y * 320) + x; +Video = VidBuf + offset; +bmPtr = &bm[4]; + +for (row = 0; row < 9; row++) + { + pos = 0; + for (col = 0; col < 12; col++) + { + *Video++ = bmPtr[pos]; + pos += 5; + } + *Video = bmPtr[63]; + Video += 308; + bmPtr += 384; + } + +bmPtr = &bm[4036]; +pos = 0; +for (col = 0; col < 12; col++) + { + *Video++ = bmPtr[pos]; + pos += 5; + } +*Video = bmPtr[63]; + +} + +//============================================================================= +// +//============================================================================= +void DrawFloorCeil(void) +{ + int row,col,x,y,pos,pOrg; + UINT bCode; + UINT *buf; + +if (ViewType == VT_FLOOR) + buf = MedFloorMap; +else + buf = MedCeilMap; + +pOrg = (GridRow * GRID_WIDTH) + GridCol; + +y = 7; + +for (row = 0; row < 9; row++) + { + x = 9; + pos = pOrg; + for (col = 0; col < 12; col++) + { + bCode = buf[pos++]; + if (bCode) + DrawTinyBitmap(x,y,Bitmaps[bCode & 255]); + + x += 20; + } + + y += 17; + pOrg += GRID_WIDTH; + } + +HideMouse(); +RefreshGrid(); +ShowMouse(); + +} + +//============================================================================= +// +//============================================================================= +void DrawObjects(void) +{ + int row,col,x,y,pos,pOrg; + UINT bCode; + UINT *buf; + UCHAR bcLow; + +buf = MobGrid; + +pOrg = (GridRow * GRID_WIDTH) + GridCol; + +y = 7; + +for (row = 0; row < 9; row++) + { + x = 9; + pos = pOrg; + for (col = 0; col < 12; col++) + { + bCode = buf[pos++]; + if (bCode) + { + bcLow = bCode & 0xFF; + DrawTinyBitmap(x,y,ObjBitmaps[ObjbmNum[bcLow]]); + } + x += 20; + } + + y += 17; + pOrg += GRID_WIDTH; + } + +HideMouse(); +RefreshGrid(); +ShowMouse(); +} + +//============================================================================= +// +//============================================================================= +void DrawGrid(void) +{ + +if (ViewMode == VM_3D) + DrawGrid3D(); +else + { + ClearGridArea(BgBuf); + DrawGrid2D(); + if (ViewType != VT_MAP) + DrawFloorCeil(); + else + DrawObjects(); + } +} + +//============================================================================= +// +//============================================================================= +void ShowScreen(char *Name) +{ + +BgBuf = AckReadiff(Name); +if (BgBuf == NULL) + return; + +memmove(VIDSEG,&BgBuf[4],64000); +AckSetPalette(colordat); +memmove(MapPalette,colordat,768); +} + +//============================================================================= +// +//============================================================================= +void ShowMaskedBitmap(int x,int y,UCHAR *bm) +{ + int row,pos; + UCHAR ch; + UCHAR *Video; + +row = ((y * 320) + x); +Video = VidBuf; +Video += row; +bm += 4; + +for (row = 0; row < 32; row++) + { + for (pos = 0; pos < 64; pos += 2) + { + ch = bm[pos]; + if (ch) + *Video = ch; + Video++; + } + Video += (320-32); + bm += 128; + } + +} + + +//============================================================================= +// +//============================================================================= +void ShowBitmap(int x,int y,UCHAR *bm) +{ + int row,pos; + UCHAR *Video; + +row = ((y * 320) + x); +Video = VIDSEG; +Video += row; +bm += 4; + +HideMouse(); + +for (row = 0; row < 32; row++) + { + for (pos = 0; pos < 64; pos += 2) + *Video++ = bm[pos]; + + Video += (320-32); + bm += 128; + } + +ShowMouse(); +} + +//============================================================================= +// +//============================================================================= +short LoadGridMap(char *Name) +{ + short handle,count,i,pos; + int mLen,aLen; + UCHAR *mPtr; + +handle = open(Name,O_RDONLY|O_BINARY); +if (handle < 1) + return(-1); + +aLen = GRID_ARRAY * 2; +mLen = GRID_MAX * 2; + +if (read(handle,MedGrid,mLen) != mLen) + { + close(handle); + return(-2); + } + +if (read(handle,MobGrid,mLen) != mLen) + { + close(handle); + return(-2); + } + +if (read(handle,MedxGrid,aLen) != aLen) + { + close(handle); + return(-2); + } + +if (read(handle,MedyGrid,aLen) != aLen) + { + close(handle); + return(-2); + } + +if (read(handle,MedFloorMap,mLen) != mLen) + { + close(handle); + return(-2); + } + +if (read(handle,MedCeilMap,mLen) != mLen) + { + close(handle); + return(-2); + } + + +read(handle,&count,2); + +if (count) + { + for (i = 0; i < count;i++) + { + read(handle,&pos,2); + mPtr = (UCHAR *)malloc(MAX_MULTI); + if (mPtr == NULL) + { + close(handle); + return(-3); + } + + MedMultiPtrs[pos] = mPtr; + read(handle,mPtr,MAX_MULTI); + } + } + +close(handle); +return(0); +} + +//============================================================================= +// +//============================================================================= +short SaveGridMap(char *Name) +{ + short handle,count,i; + long rba; + int mLen,aLen; + UCHAR *mPtr; + +handle = open(Name,O_RDWR|O_BINARY|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE); +if (handle < 1) + return(-1); + + +// Write the map grids below, keeping track of the Relative Byte Address + +aLen = GRID_ARRAY * 2; +mLen = GRID_MAX * 2; +rba = 0; + +if (write(handle,MedGrid,mLen) != mLen) + { + close(handle); + return(-2); + } + +rba += mLen; + +if (write(handle,MobGrid,mLen) != mLen) + { + close(handle); + return(-2); + } + +rba += mLen; + +if (write(handle,MedxGrid,aLen) != aLen) + { + close(handle); + return(-2); + } + +rba += aLen; +if (write(handle,MedyGrid,aLen) != aLen) + { + close(handle); + return(-2); + } + +rba += aLen; + +if (write(handle,MedFloorMap,mLen) != mLen) + { + close(handle); + return(-2); + } + +rba += mLen; + +if (write(handle,MedCeilMap,mLen) != mLen) + { + close(handle); + return(-2); + } + +rba += mLen; +count = 0; + +// Write the initial count of multi-height walls + +write(handle,&count,2); + +for (i = 0; i < GRID_MAX; i++) + { + mPtr = MedMultiPtrs[i]; + if (mPtr) + { + count++; + write(handle,&i,2); // Write the position of this wall + write(handle,mPtr,MAX_MULTI); // Write the bitmap numbers for this wall + } + } + +if (count) + { + lseek(handle,rba,SEEK_SET); // Seek back to the count + write(handle,&count,2); // And write the new count + } + +close(handle); +ModifyFlag = 0; +return(0); +} + +//============================================================================= +// +//============================================================================= +void ShowCurrentBitmap(void) +{ + char buf[10]; + UCHAR cCode; + +cCode = CurrentCode & 0xFF; +if (EditType == ED_OBJECTS) + cCode = ObjbmNum[cCode]; + +HideMouse(); +ShowBitmap(BM_X,BM_Y,BitmapPtr[cCode]); +DrawFillBox(BM_COLOR_X,BM_COLOR_Y,BM_COLOR_X1,BM_COLOR_Y1,cCode+BaseColor); +sprintf(buf,"%02X",CurrentCode & 0xFF); +smWriteString(BM_NUM_X,BM_NUM_Y,buf); +ShowMouse(); +} + +//============================================================================= +// +//============================================================================= +void UpdateScreen(void) +{ + UCHAR *Buf; + +LastViewType = -1; +LastgRow = -1; + +Buf = &BgBuf[4]; +if (ViewMode == VM_3D) + Buf = &BgBuf3D[4]; + +HideMouse(); +memmove(VIDSEG,Buf,64000); +ShowCurrentBitmap(); + +if (EditType == ED_WALLS) + PressButton(AI_WALLS); +else + PressButton(AI_OBJECTS); + +ShowMouse(); +} + +//============================================================================= +// +//============================================================================= +int GetGridPos(short mx,short my) +{ + int row,col,x,y,pos; + +mx -= 2; +row = my / 17; +col = mx / 20; +if (row > 9 || col > 12) + return(-1); + +row += GridRow; +col += GridCol; +pos = (row*GRID_WIDTH)+col; +return(pos); +} + +//============================================================================= +// +//============================================================================= +short ObjectInMap(UINT oCode) +{ + int i; + +oCode &= 0xFF; + +for (i = 0; i < GRID_MAX; i++) + { + if (oCode == (MobGrid[i] & 0xFF)) + return(1); + } + +return(0); +} + + +//============================================================================= +// +//============================================================================= +void PutCode(short mx,short my) +{ + int x,y,pos; + UINT wFlags,cCode; + +if ((pos = GetGridPos(mx,my)) == -1) + { + SoundBeep(); + return; + } + +mx -= 2; +x = mx % 20; +y = my % 17; + +ModifyFlag = 1; + +if (ViewType == VT_MAP && EditType == ED_OBJECTS) + { + if (CurrentCode > 0 && ObjectInMap(CurrentCode)) + { + SoundBeep(); + return; + } + + if (CurrentCode) + MobGrid[pos] = ObjFlags | CurrentCode; + else + MobGrid[pos] = 0; + return; + } + +switch (ViewType) + { + case VT_MAP: + if (!CurrentCode && (MedGrid[pos] & WALL_TYPE_MULTI)) + { + if (MedMultiPtrs[pos] != NULL) + { + free(MedMultiPtrs[pos]); + MedMultiPtrs[pos] = NULL; + } + x = y = y; // Fake it out to clear entire block + } + + wFlags = WallFlags; + if (!CurrentCode) wFlags = 0; + // if (CurrentCode == DOOR_XCODE || CurrentCode == DOOR_YCODE) + // wFlags = DoorFlags; + + cCode = wFlags | CurrentCode; + + MedGrid[pos] &= wFlags; + MedGrid[pos] |= cCode; + + if (x > 6 && x < 20 && y < 6) + { + MedyGrid[pos] &= wFlags; + MedyGrid[pos] |= cCode; + } + else + if (x > 6 && x < 20 && y > 12) + { + MedyGrid[pos+GRID_WIDTH] &= wFlags; + MedyGrid[pos+GRID_WIDTH] |= cCode; + } + else + if (x < 7 && y > 5 && y < 13) + { + MedxGrid[pos] &= wFlags; + MedxGrid[pos] |= cCode; + } + else + if (x > 19 && y > 5 && y < 13) + { + MedxGrid[pos+1] &= wFlags; + MedxGrid[pos+1] |= cCode; + } + else + if (x > 6 && x < 20 && y > 6 && y < 13) + { + MedxGrid[pos] &= wFlags; + MedxGrid[pos+1] &= wFlags; + MedyGrid[pos] &= wFlags; + MedyGrid[pos+GRID_WIDTH] &= wFlags; + MedxGrid[pos] |= cCode; + MedxGrid[pos+1] |= cCode; + MedyGrid[pos] |= cCode; + MedyGrid[pos+GRID_WIDTH] |= cCode; + } + break; + + case VT_FLOOR: + MedFloorMap[pos] = CurrentCode; + break; + + case VT_CEIL: + MedCeilMap[pos] = CurrentCode; + break; + + default: + break; + } +} + +//============================================================================= +// +//============================================================================= +void GetCode(short mx,short my) +{ + int x,y,pos; + UINT wFlags,cCode; + +if ((pos = GetGridPos(mx,my)) == -1) + { + SoundBeep(); + return; + } + +mx -= 2; +x = mx % 20; +y = my % 17; + +if (ViewType == VT_MAP && EditType == ED_OBJECTS) + { + CurrentCode = MobGrid[pos] & 255; + return; + } + +switch (ViewType) + { + case VT_MAP: + if (x > 6 && x < 20 && y < 6) + { + CurrentCode = MedyGrid[pos] & 0xFF; + } + else + if (x > 6 && x < 20 && y > 12) + { + CurrentCode = MedyGrid[pos+GRID_WIDTH] & 0xFF; + } + else + if (x < 7 && y > 5 && y < 13) + { + CurrentCode = MedxGrid[pos] & 0xFF; + } + else + if (x > 19 && y > 5 && y < 13) + { + CurrentCode = MedxGrid[pos+1] & 0xFF; + } + else + if (x > 6 && x < 20 && y > 6 && y < 13) + { + CurrentCode = MedGrid[pos] & 0xFF; + } + break; + + case VT_FLOOR: + CurrentCode = MedFloorMap[pos] & 0xFF; + break; + + case VT_CEIL: + CurrentCode = MedCeilMap[pos] & 0xFF; + break; + + default: + break; + } +} + + + + +//============================================================================= +// +//============================================================================= +void UpdatePosn(short mx,short my) +{ + short row,col; + char buf[20]; + +if (ViewType != LastViewType) + { + if (LastViewType != -1) + ReleaseButton(ButtonTable[LastViewType]); + LastViewType = ViewType; + PressButton(ButtonTable[LastViewType]); + } + +FontColor = 0; + +if (GridRow != LastgRow || GridCol != LastgCol) + { + LastgRow = GridRow; + LastgCol = GridCol; + sprintf(buf,"%02d,%02d",GridCol,GridRow); + smWriteString(MAPXY_X,MAPXY_Y,buf); + } + +if (mx > MAP_X1 || my > MAP_Y1) + return; + +if (mx == LastMX && my == LastMY) + return; + +LastMX = mx; +LastMY = my; + +mx -= 2; +row = (my / 17) + GridRow; +col = (mx / 20) + GridCol; +sprintf(buf,"%02d,%02d",col,row); +smWriteString(CURXY_X,CURXY_Y,buf); +} + + +//============================================================================= +// +//============================================================================= +void ShowSelBitmaps(UCHAR bCode) +{ + int row,col,x,y; + UCHAR color; + +y = 0; + +HideMouse(); +for (row = 0; row < 5; row++) + { + x = 3; + for (col = 0; col < 9; col++) + { + color = 255; + if (bCode == CurrentCode) color = 32; + DrawBox(x,y,x+33,y+33,color); + if (EditType == ED_WALLS) + ShowBitmap(x+1,y+1,BitmapPtr[bCode++]); + else + ShowBitmap(x+1,y+1,BitmapPtr[ObjbmNum[bCode++]]); + x += 35; + } + + y += 35; + } +ShowMouse(); +} + +//============================================================================= +// +//============================================================================= +int SelectScreen(void) +{ + int row,col,x,y; + int done; + short mx,my,button,action; + UCHAR bCode; + + +bCode = 0; + +HideMouse(); +memmove(VIDSEG,&SelBgBuf[4],64000); +ShowSelBitmaps(bCode); +MouseReleased(); +ShowMouse(); + +done = 0; + +while (!done) + { + button = ReadMouseCursor(&my,&mx); + + if (button & 1) + { + action = GetSelAction(mx,my); + + switch (action) + { + case 1: // Cancel + done = -1; + break; + + case 2: // Prev + bCode -= 9; + ShowSelBitmaps(bCode); + delay(50); + break; + + case 3: // Next + bCode += 9; + ShowSelBitmaps(bCode); + delay(50); + break; + + case 4: // Bitmap window + mx -= 3; + row = my / 35; + col = mx / 35; + if (col > 8 || row > 8) + break; + + bCode = bCode + ((row*9)+col); + CurrentCode = bCode; + done = 1; + break; + + default: + break; + } + } + } + +return(done); +} + +//============================================================================= +// +//============================================================================= +UCHAR GetIndexColor(short index) +{ +return(GetColor(HotSpots[index].x,HotSpots[index].y)); +} + +//============================================================================= +// +//============================================================================= +UCHAR GetIndexColor2(short index) +{ +return(GetColor(HotSpots[index].x1,HotSpots[index].y1)); +} + +//============================================================================= +// +//============================================================================= +void DrawBackBox(int x,int y,int x1,int y1) +{ +DrawFillBox(x,y,x1,y1,BoxColor); +DrawBox(x,y,x1,y1,ButtonUpperColor); +DrawBox(x+1,y+1,x1-1,y1-1,ButtonLowerColor); +DrawBox(x+2,y+2,x1-2,y1-2,ButtonUpperColor); +} + +//============================================================================= +// +//============================================================================= +void ShowButtons(OPTS *op,HS *hs,int x,int y,int xAmt,int yAmt) +{ + +while (op->id != -1) + { + CreateButton(x+op->xBias,y+op->yBias,&hs[op->id],op->Text); + if (op->Flags & OPTF_CHECKED) + mdWriteChar(x+3,y+2,'^'); // Using the hat as a checkmark + x += xAmt; + y += yAmt; + op++; + } + +} + +//============================================================================= +// +//============================================================================= +int ShowOptions(void) +{ + int x,y,done,i; + short mx,my,mbutton; + HS hs[OPT_MAX]; + +LeftOpts[OPT_NORMAL].Flags &= ~OPTF_CHECKED; +if (!WallFlags) + LeftOpts[OPT_NORMAL].Flags |= OPTF_CHECKED; + +LeftOpts[OPT_TRANS].Flags &= ~OPTF_CHECKED; +if (WallFlags & WALL_TYPE_TRANS) + LeftOpts[OPT_TRANS].Flags |= OPTF_CHECKED; + +LeftOpts[OPT_RAISED].Flags &= ~OPTF_CHECKED; +if (WallFlags & WALL_TYPE_UPPER) + LeftOpts[OPT_RAISED].Flags |= OPTF_CHECKED; + + +RightOpts[OPT_PASSABLE-OPT_FILL].Flags &= ~OPTF_CHECKED; + +if (EditType == ED_WALLS && (WallFlags & WALL_TYPE_PASS)) + RightOpts[OPT_PASSABLE-OPT_FILL].Flags |= OPTF_CHECKED; + +//if (EditType == ED_OBJECTS && (ObjFlags & OF_PASSABLE)) +// RightOpts[OPT_PASSABLE-OPT_FILL].Flags |= OPTF_CHECKED; + + +LeftOpts[OPT_SLIDING].Flags &= ~OPTF_CHECKED; +if (WallFlags & DOOR_TYPE_SLIDE) + LeftOpts[OPT_SLIDING].Flags |= OPTF_CHECKED; + +LeftOpts[OPT_SPLIT].Flags &= ~OPTF_CHECKED; +if (WallFlags & DOOR_TYPE_SPLIT) + LeftOpts[OPT_SPLIT].Flags |= OPTF_CHECKED; + +LeftOpts[OPT_SECRET].Flags &= ~OPTF_CHECKED; +if (WallFlags & DOOR_TYPE_SECRET) + LeftOpts[OPT_SECRET].Flags |= OPTF_CHECKED; + +LeftOpts[OPT_LOCKED].Flags &= ~OPTF_CHECKED; +if (WallFlags & DOOR_LOCKED) + LeftOpts[OPT_LOCKED].Flags |= OPTF_CHECKED; + +HideMouse(); +DrawBackBox(18,14,234,144); +ShowButtons(LeftOpts,hs,30,22,0,13); +ShowButtons(RightOpts,hs,132,22,0,13); +ShowMouse(); + +done = 0; +while (!done) + { + mbutton = ReadMouseCursor(&my,&mx); + + if (mbutton & 1) + { + for (x = 0; x < OPT_MAX; x++) + { + if (mx >= hs[x].x && mx <= hs[x].x1 && my >= hs[x].y && my <= hs[x].y1) + { + done = 1; + break; + } + } + } + } + +return(x); +} + +//============================================================================= +// +//============================================================================= +void FillMap(UCHAR bCode) +{ + int i; + +ModifyFlag = 1; +switch (ViewType) + { + case VT_MAP: + if (EditType == ED_WALLS) + { + for (i = 0; i < GRID_MAX; i++) + MedGrid[i] = bCode; + + for (i = 0; i < GRID_ARRAY; i++) + { + MedxGrid[i] = bCode; + MedyGrid[i] = bCode; + } + } + else + { + for (i = 0; i < GRID_MAX; i++) + MobGrid[i] = bCode; + } + break; + + case VT_FLOOR: + for (i = 0; i < GRID_MAX; i++) + MedFloorMap[i] = bCode; + break; + + case VT_CEIL: + for (i = 0; i < GRID_MAX; i++) + MedCeilMap[i] = bCode; + break; + + default: + break; + } +} + +//============================================================================= +// +//============================================================================= +void DrawBorder(UINT bCode) +{ + short row,col; + UINT offset; + +if (ViewType != VT_MAP) + { + SoundBeep(); + return; + } + +ModifyFlag = 1; + +offset = 0; +for (col = 0; col < 64; col++) + { + MedGrid[col] = bCode; + MedyGrid[col] = bCode; + } +for (row = 0; row < 64; row++) + { + MedGrid[offset] = bCode; + MedGrid[offset+63] = bCode; + MedxGrid[offset] = bCode; + MedxGrid[offset+63] = bCode; + offset += 64; + } + +offset = 64 * 63; +for (col = 0; col < 64; col++) + { + MedyGrid[offset] = bCode; + MedGrid[offset++] = bCode; + } + +} + + +//============================================================================= +// +//============================================================================= +void DrawArrow(int x,int y,UCHAR color) +{ + int offset; + UCHAR *Video; + +offset = (y * 320) + x; +Video = VIDSEG + offset; +HideMouse(); +DrawHorzLine(x,y,x+10,color); +Video[-319] = color; +Video[321] = color; +Video[-638] = color; +Video[642] = color; + +ShowMouse(); +} + +//============================================================================= +// +//============================================================================= +int SelectGridBox(void) +{ + int pos; + short mx,my,mbutton; + +if (QueryBox(40,40,"Select a grid square")) + return(-1); + +MouseReleased(); +DrawGrid(); +pos = 0; + +while (1) + { + mbutton = ReadMouseCursor(&my,&mx); + if (mbutton & 2) + return(-1); + + if (mbutton & 1) + { + if ((pos = GetGridPos(mx,my)) == -1) + continue; + break; + } + } + +MouseReleased(); +return(pos); +} + + +//============================================================================= +// +//============================================================================= +void EditMulti(int mode,short gx,short gy) +{ + int i,x,y,x1,y1,pos,done,num; + short mx,my,mbuttons; + UINT OldCurrent; + UCHAR bCode; + UCHAR *mPtr; + HS hs[4]; + UCHAR mBuf[8]; + +if (!mode) // User must pick a grid square + { + pos = SelectGridBox(); + if (pos == -1) + return; + } +else // Otherwise mouse coordinates are used + { + if ((pos = GetGridPos(gx,gy)) == -1) + return; + } + +OldCurrent = CurrentCode; + +memset(mBuf,0,8); +mPtr = MedMultiPtrs[pos]; +if (mPtr) + memmove(mBuf,mPtr,MAX_MULTI); + +HideMouse(); +DrawFillBox(MAP_X,MAP_Y,MAP_X1-3,MAP_Y1,0); +x = y = 0; +for (i = 2; i >= 0; i--) + { + DrawBox(x,y,x+34,y+34,ButtonUpperColor); + if (mPtr != NULL) + { + bCode = mPtr[i]; + if (bCode) + { + ShowBitmap(x+1,y+1,Bitmaps[bCode]); + } + } + y += 36; + } + +DrawBox(x,y,x+34,y+34,ButtonUpperColor); +ShowBitmap(x+1,y+1,Bitmaps[MedGrid[pos] & 0xFF]); +ShowButtons(MultiOpts,hs,80,40,0,20); +ShowMouse(); + +num = 0; +done = 0; +y = 2 * 36; +DrawArrow(38,y+16,ButtonUpperColor); + +while (!done) + { + mbuttons = ReadMouseCursor(&my,&mx); + + if (mbuttons & 2) + { + if (mx < 34 && my < 110) + { + DrawArrow(38,y+16,0); + num = 2 - (my / 36); + y = (2 - num) * 36; + DrawArrow(38,y+16,ButtonUpperColor); + mBuf[num] = 0; + HideMouse(); + ShowBitmap(1,y+1,Bitmaps[0]); + ShowMouse(); + } + MouseReleased(); + continue; + } + + if (mbuttons & 1) + { + if (mx < 34 && my < 110) + { + DrawArrow(38,y+16,0); + num = 2 - (my / 36); + y = (2 - num) * 36; + DrawArrow(38,y+16,ButtonUpperColor); + MouseReleased(); + continue; + } + + for (i = 0; i < 3; i++) + { + if (mx >= hs[i].x && mx <= hs[i].x1 && + my >= hs[i].y && my <= hs[i].y1) + { + if (i) + done = 1; + else + { + HideMouse(); + SaveVideo(VidBuf); + ShowMouse(); + x1 = SelectScreen(); + HideMouse(); + RestoreVideo(VidBuf); + ShowMouse(); + if (x1 == -1) + continue; + + ShowBitmap(1,y+1,Bitmaps[CurrentCode & 0xFF]); + mBuf[num] = CurrentCode; + MouseReleased(); + if (num < 2) + { + DrawArrow(38,y+16,0); + num++; + y = (2 - num) * 36; + DrawArrow(38,y+16,ButtonUpperColor); + } + } + break; + } + } + } + } + + +if (i == 1) + { + if (mPtr == NULL) + mPtr = (UCHAR *)malloc(MAX_MULTI); + + MedMultiPtrs[pos] = mPtr; + if (mPtr != NULL) + { + memmove(mPtr,mBuf,MAX_MULTI); + ModifyFlag = 1; + MedGrid[pos] |= WALL_TYPE_MULTI; + MedxGrid[pos] |= WALL_TYPE_MULTI; + MedxGrid[pos+1] |= WALL_TYPE_MULTI; + MedyGrid[pos] |= WALL_TYPE_MULTI; + MedyGrid[pos+GRID_WIDTH] |= WALL_TYPE_MULTI; + } + } + +CurrentCode = OldCurrent; +HideMouse(); +ShowCurrentBitmap(); +ShowMouse(); +} + + +//============================================================================= +// +//============================================================================= +void ProcessOptions(int OptNum) +{ + +switch (OptNum) + { + case OPT_NORMAL: + WallFlags = 0; + break; + + case OPT_SLIDING: + WallFlags &= ~(DOOR_TYPE_SPLIT+DOOR_TYPE_SECRET); + WallFlags |= DOOR_TYPE_SLIDE; + break; + + case OPT_SPLIT: + WallFlags &= ~(DOOR_TYPE_SLIDE+DOOR_TYPE_SECRET); + WallFlags |= DOOR_TYPE_SPLIT; + break; + + case OPT_SECRET: + WallFlags &= ~(DOOR_TYPE_SLIDE+DOOR_TYPE_SPLIT); + WallFlags |= DOOR_TYPE_SECRET; + break; + + case OPT_LOCKED: + WallFlags ^= DOOR_LOCKED; + break; + + case OPT_TRANS: + WallFlags ^= WALL_TYPE_TRANS; + break; + + case OPT_MULTI: + EditMulti(0,0,0); + break; + + case OPT_RAISED: + WallFlags ^= WALL_TYPE_UPPER; + break; + + case OPT_FILL: + if (!QueryBox(70,20,"Fill entire map?")) + FillMap(CurrentCode); + break; + + case OPT_BORDER: + if (!QueryBox(30,20,"Draw Border with current bitmap?")) + DrawBorder(CurrentCode); + break; + + case OPT_CLEAR: + if (!QueryBox(70,20,"Clear entire map?")) + FillMap(0); + break; + + case OPT_PASSABLE: + if (EditType == ED_WALLS) + WallFlags ^= WALL_TYPE_PASS; +// else +// ObjFlags ^= OF_PASSABLE; + break; + + case OPT_PALETTE: + AckSetPalette(bmPalette); + break; + + case OPT_MAPPAL: + AckSetPalette(MapPalette); + break; + + default: + break; + } + +} + +//============================================================================= +// +//============================================================================= +void main(short argc,char **argv) +{ + short mx,my,mButtons; + short Action,done,rFlag; + int result; + UINT OldCode,key; + +if (MouseInstalled() != -1) + { + printf("Mouse required.\n"); + return; + } + +VidBuf = (UCHAR *)malloc(64000); +BlankbmBuf = (UCHAR *)malloc(4100); +if (VidBuf == NULL || BlankbmBuf == NULL) + { + printf("Not enough memory\n"); + return; + } + +memset(BlankbmBuf,0,4100); + +for (mx = 0; mx < 256; mx++) + { + Bitmaps[mx] = BlankbmBuf; + ObjBitmaps[mx] = BlankbmBuf; + } + + +if (LoadDescFile(argv[1])) + { + printf("\nError reading ASCII file - ErrorCode = %d\n",ReadErrorCode); + return; + } + +memmove(bmPalette,colordat,768); + +if (LoadGridMap(MapName)) + { +// printf("\nError loading map file - ErrorCode = %d\n",ReadErrorCode); +// return; + memset(MedGrid,0,(GRID_MAX * 2)); + memset(MobGrid,0,(GRID_MAX * 2)); + memset(MedFloorMap,0,(GRID_MAX * 2)); + memset(MedCeilMap,0,(GRID_MAX * 2)); + printf("\nNew map file %s will be created.\n",MapName); + } + +if (AckOpenResource("MEDIT.DTF")) + { + printf("Unable to locate MEDIT.DTF\n"); + return; + } + + +if (LoadSmallFont()) + { + printf("Error loading SPFONT.BBM\n"); + return; + } + +if (LoadMedFont()) + { + printf("Error loading FONT6X9.BBM\n"); + return; + } + + +#if 0 +Bitmaps[1] = AckReadiff("m1.bbm"); +if (Bitmaps[1] == NULL) + { + printf("Error loading m1.bbm"); + return; + } + +Bitmaps[2] = AckReadiff("m12.bbm"); +if (Bitmaps[2] == NULL) + { + printf("Error loading m12.bbm"); + return; + } + +ObjBitmaps[1] = AckReadiff("slime1a.bbm"); + + +strcpy(MapName,"kit.map"); +if (LoadGridMap(MapName)) + { + memset(MedGrid,0,(GRID_MAX * 2)); + memset(MobGrid,0,(GRID_MAX * 2)); + } + +memset(MedFloorMap,0,(GRID_MAX * 2)); +memset(MedCeilMap,0,(GRID_MAX * 2)); +#endif + +ViewMode = VM_2D; +ViewType = VT_MAP; +MaxCol = GRID_WIDTH-12; +MaxRow = GRID_HEIGHT-9; +BaseColor = 99; + +AckSetVGAmode(); +ShowScreen((char *)RES_2DSCREEN); // "m12d.lbm"); +TextBGcolor = GetColor(MAPXY_X,MAPXY_Y); +BoxColor = TextBGcolor; +Action = GetActionIndex(AI_MAP); +ButtonColor = GetColor(HotSpots[Action].x+1,HotSpots[Action].y+1); +ButtonUpperColor = GetIndexColor(AI_MAP); +ButtonLowerColor = GetIndexColor2(AI_MAP); +LastgRow = -1; +LastViewType = -1; +WallFlags = ObjFlags = 0; +EditType = ED_WALLS; +BitmapPtr = Bitmaps; +ShowMouse(); +DrawGrid(); +LastObjCode = LastWallCode = CurrentCode = 1; +ShowCurrentBitmap(); +PressButton(AI_WALLS); + +BgBuf3D = AckReadiff((char *)RES_3DSCREEN); // "m13d.lbm"); +SelBgBuf = AckReadiff((char *)RES_SELSCREEN); //"m1sel.lbm"); + +AckCloseResource(); + +done = 0; +rFlag = 0; + +while (!done) + { + key = inkey(); + if (key == KEY_ESC) + { + PressButton(AI_EXIT); + if (ModifyFlag) + { + if (QueryBox(20,40,"Map has Changed.\nExit Anyway?")) + { + ReleaseButton(AI_EXIT); + continue; + } + } + break; + } + if (key == KEY_SPACE) + { + PressButton(AI_OPTIONS); + result = ShowOptions(); + ReleaseButton(AI_OPTIONS); + rFlag = 2; + } + + mButtons = ReadMouseCursor(&my,&mx); + + if (key == KEY_F2) + { + EditMulti(1,mx,my); + MouseReleased(); + rFlag = 1; + } + + if (key == KEY_F3) + { + GetCode(mx,my); + ShowCurrentBitmap(); + } + + if (mButtons & 2) + { + if (GetAction(mx,my) == 15) + { + OldCode = CurrentCode; + CurrentCode = 0; + PutCode(mx,my); + CurrentCode = OldCode; + rFlag = 1; + } + } + + UpdatePosn(mx,my); + + if (key == KEY_UP) + { + if (GridRow > 0) + { + GridRow--; + rFlag = 1; + } + } + + if (key == KEY_RIGHT) + { + if (GridCol < MaxCol) + { + GridCol++; + rFlag = 1; + } + } + + if (key == KEY_DOWN) + { + if (GridRow < MaxRow) + { + GridRow++; + rFlag = 1; + } + } + + if (key == KEY_LEFT) + { + if (GridCol > 0) + { + GridCol--; + rFlag = 1; + } + } + + if (key == KEY_PGUP && BaseColor > 0) + { + BaseColor--; + HideMouse(); + ShowCurrentBitmap(); + ShowMouse(); + rFlag = 1; + } + + if (key == KEY_PGDN && BaseColor < 255) + { + BaseColor++; + HideMouse(); + ShowCurrentBitmap(); + ShowMouse(); + rFlag = 1; + } + + if (mButtons & 1) + { + Action = GetAction(mx,my); + + switch (Action) + { + case AI_UP: + if (GridRow > 0) + { + GridRow--; + rFlag = 1; + delay(50); + } + break; + + case AI_RIGHT: + if (GridCol < MaxCol) + { + GridCol++; + rFlag = 1; + delay(50); + + } + break; + + case AI_DOWN: + if (GridRow < MaxRow) + { + GridRow++; + rFlag = 1; + delay(50); + } + break; + + case AI_LEFT: + if (GridCol > 0) + { + GridCol--; + rFlag = 1; + delay(50); + } + break; + + case AI_MINI: + GridRow = my - MINI_Y; + GridCol = mx - MINI_X; + if (GridCol > MaxCol) + GridCol = MaxCol; + if (GridRow > MaxRow) + GridRow = MaxRow; + rFlag = 1; + delay(20); + break; + + case AI_SELECT: + PressButton(Action); + SelectScreen(); + UpdateScreen(); + rFlag = 2; + break; + + case AI_VIEW: + ViewMode ^= VM_3D; + if (ViewMode == VM_2D) + { + MaxCol = GRID_WIDTH-12; + MaxRow = GRID_HEIGHT-9; + } + else + { + MaxCol = GRID_WIDTH-4; + MaxRow = GRID_HEIGHT-4; + } + + if (GridRow > MaxRow) GridRow = MaxRow; + if (GridCol > MaxCol) GridCol = MaxCol; + + UpdateScreen(); + rFlag = 2; + break; + + case AI_FLOORS: // Floor + ViewType = VT_FLOOR; + rFlag = 2; + break; + + case AI_SAVE: // Save + PressButton(AI_SAVE); + + if (access(MapName,0) == 0) + { + if (QueryBox(40,40,"Overwrite existing map?")) + { + ReleaseButton(AI_SAVE); + rFlag = 2; + break; + } + DrawGrid(); + } + + if (SaveGridMap(MapName) < 0) + QueryBox(40,40,"Error saving map file"); + else + QueryBox(40,40,"Map file saved"); + + ReleaseButton(AI_SAVE); + rFlag = 2; + break; + + case AI_MAP: // Map + ViewType = VT_MAP; + rFlag = 2; + break; + + case AI_CEILING: // Ceiling + ViewType = VT_CEIL; + rFlag = 2; + break; + + case AI_WALLS: + if (EditType != ED_WALLS) + { + ReleaseButton(AI_OBJECTS); + EditType = ED_WALLS; + PressButton(AI_WALLS); + BitmapPtr = Bitmaps; + LastObjCode = CurrentCode; + CurrentCode = LastWallCode; + ShowCurrentBitmap(); + MouseReleased(); + } + break; + + case AI_OBJECTS: + if (EditType != ED_OBJECTS) + { + ReleaseButton(AI_WALLS); + EditType = ED_OBJECTS; + PressButton(AI_OBJECTS); + BitmapPtr = ObjBitmaps; + LastWallCode = CurrentCode; + CurrentCode = LastObjCode; + ShowCurrentBitmap(); + MouseReleased(); + } + break; + + case AI_OPTIONS: // Options + PressButton(AI_OPTIONS); + result = ShowOptions(); + ReleaseButton(AI_OPTIONS); + DrawGrid(); + MouseReleased(); + ProcessOptions(result); + rFlag = 2; + break; + + case AI_EDITWIN: + PutCode(mx,my); + rFlag = 1; + if (EditType == ED_OBJECTS) + rFlag = 2; + break; + + case AI_BM_UP: + CurrentCode--; + if (CurrentCode > 255) CurrentCode = 255; + ShowCurrentBitmap(); + delay(150); + break; + + case AI_BM_DOWN: + CurrentCode++; + if (CurrentCode > 255) CurrentCode = 0; + ShowCurrentBitmap(); + delay(150); + break; + + case AI_EXIT: + PressButton(Action); + if (ModifyFlag) + { + if (QueryBox(20,40," Map has Changed, Exit Anyway? ")) + { + ReleaseButton(Action); + break; + } + } + done = 1; + break; + + default: + break; + + } + + + } + + if (rFlag) + { + DrawGrid(); + if (rFlag == 2) + MouseReleased(); + + rFlag = 0; + } + } + +AckSetTextmode(); + +} + diff --git a/map_edit/m1.h b/map_edit/m1.h new file mode 100644 index 0000000..d987ee1 --- /dev/null +++ b/map_edit/m1.h @@ -0,0 +1,222 @@ +// Header file for ACK-3D Map Editor +// Author: Lary Myers +// Copyright (c) 1994 + + +#define RES_SMFONT 0 // Resource ID's +#define RES_MDFONT 1 +#define RES_2DSCREEN 2 +#define RES_3DSCREEN 3 +#define RES_SELSCREEN 4 + + +#define BM_X 272 +#define BM_Y 17 + +#define BM_NUM_X 308 +#define BM_NUM_Y 30 + +#define MAP_X 0 +#define MAP_Y 0 +#define MAP_X1 256 +#define MAP_Y1 160 + +#define MINI_X 255 +#define MINI_Y 135 +#define MINI_X1 (MINI_X+63) +#define MINI_Y1 (MINI_Y+63) + +#define MAPXY_X 217 +#define MAPXY_Y 165 +#define MAPXY_X1 231 +#define MAPXY_Y1 165 + +#define CURXY_X 217 +#define CURXY_Y 173 +#define CURXY_X1 231 +#define CURXY_Y1 173 + +#define GD_FWT 32 +#define GD_FHT 32 +#define GD_HWT 16 +#define GD_HHT 16 + +#define VM_2D 0 // View mode is 2D +#define VM_3D 1 // View mode is 3D + +#define VT_MAP 0 // Viewing map +#define VT_FLOOR 1 // Viewing floor +#define VT_CEIL 2 // Viewing ceiling + + +#define ED_WALLS 0 // Editing walls +#define ED_OBJECTS 1 // Editing objects + +#define AI_UP 1 // Action index's +#define AI_RIGHT 2 +#define AI_DOWN 3 +#define AI_LEFT 4 +#define AI_MINI 5 +#define AI_SELECT 6 +#define AI_VIEW 7 +#define AI_FLOORS 8 +#define AI_SAVE 9 +#define AI_MAP 10 +#define AI_WALLS 11 +#define AI_CEILING 12 +#define AI_OBJECTS 13 +#define AI_OPTIONS 14 +#define AI_EDITWIN 15 +#define AI_BM_UP 16 +#define AI_BM_DOWN 17 +#define AI_EXIT 99 + +#define OPT_NORMAL 0 // Selectable option ID's +#define OPT_SLIDING 1 +#define OPT_SPLIT 2 +#define OPT_SECRET 3 +#define OPT_LOCKED 4 +#define OPT_TRANS 5 +#define OPT_MULTI 6 +#define OPT_RAISED 7 +#define OPT_CANCEL 8 +#define OPT_FILL 9 +#define OPT_BORDER 10 +#define OPT_CLEAR 11 +#define OPT_PASSABLE 12 +#define OPT_PALETTE 13 +#define OPT_MAPPAL 14 + +#define OPT_MAX 15 // Total number of options above + + +#define BM_COLOR_X 261 // Current bitmap color coordinates +#define BM_COLOR_Y 17 +#define BM_COLOR_X1 267 +#define BM_COLOR_Y1 48 + +typedef struct { + short Action; + short x; + short y; + short x1; + short y1; + } HS; + +typedef struct { + short id; + int xBias; + int yBias; + UCHAR Flags; + char *Text; + } OPTS; + +#define OPTF_CHECKED 0x80 // Button will have a checkmark + + +#define VIDSEG (UCHAR *)0xA0000 + +#define MAX_MULTI 3 + +#define KEY_ESC 0x011B +#define KEY_SPACE 0x3920 +#define KEY_F2 0x3C00 +#define KEY_F3 0x3D00 +#define KEY_UP 0x4800 +#define KEY_RIGHT 0x4D00 +#define KEY_DOWN 0x5000 +#define KEY_LEFT 0x4B00 +#define KEY_PGUP 0x4900 +#define KEY_PGDN 0x5100 + +//============================================================================= +// Prototypes; +//============================================================================= + +//----------------------------------------------------------------------------- +// Functions in mouse.c +//----------------------------------------------------------------------------- +short MouseInstalled(void); +void ShowMouse(void); +void HideMouse(void); +short ReadMouseCursor(short *mrow,short *mcol); +short ReadMouseButtons(void); +void SetMouseCursor(short mrow,short mcol); +void SetMouseMinMaxColumns(short mincol,short maxcol); +void SetMouseMinMaxRows(short minrow,short maxrow); +void SetMouseShape(short hsrow,short hscol,char far *mask); +void MouseReleased(void); + +//----------------------------------------------------------------------------- +// Functions in m1.c +//----------------------------------------------------------------------------- +short GetAction(short mx,short my); +short GetSelAction(short mx,short my); +void DrawYline(int x,int y); +void DrawXline(int x,int y); +void DrawGridBlock(int x,int y); +void DrawYbitmap(int x,int y,UCHAR *bm,UCHAR Shade,int TransFlag); +void DrawXbitmap(int x,int y,UCHAR *bm,UCHAR Shade,int TransFlag); +void ClearGridArea(UCHAR *BufPtr); +void RefreshGrid(void); +void DrawGrid3D(void); +void Draw2Dxline(int x,int y,UCHAR color); +void DrawxLineMulti(int x,int y,UCHAR color); +void Draw2Dyline(int x,int y,UCHAR color); +void DrawyLineMulti(int x,int y,UCHAR color); +void DrawGrid2D(void); +void DrawTinyBitmap(int x,int y,UCHAR *bm); +void DrawFloorCeil(void); +void DrawObjects(void); +void DrawGrid(void); +void ShowScreen(char *Name); +void ShowBitmap(int x,int y,UCHAR *bm); +short LoadGridMap(char *Name); +short SaveGridMap(char *Name); +void ShowCurrentBitmap(void); +short GetActionIndex(short action); +void PressButton(short ActionCode); +void ReleaseButton(short ActionCode); +void UpdateScreen(void); +int GetGridPos(short mx,short my); +void PutCode(short mx,short my); +void UpdatePosn(short mx,short my); +void ShowSelBitmaps(UCHAR bCode); +int SelectScreen(void); +UCHAR GetIndexColor(short index); +UCHAR GetIndexColor2(short index); +void DrawBackBox(int x,int y,int x1,int y1); +void ShowButtons(OPTS *op,HS *hs,int x,int y,int xAmt,int yAmt); +int ShowOptions(void); +void FillMap(UCHAR bCode); +void DrawArrow(int x,int y,UCHAR color); +int SelectGridBox(void); +void EditMulti(int mode,short mx,short my); + +//----------------------------------------------------------------------------- +// Functions in m1util.c +//----------------------------------------------------------------------------- +void SoundBeep(void); +short LoadSmallFont(void); +short LoadMedFont(void); +void mdWriteChar(short x,short y,unsigned char ch); +short mdWriteString(short x,short y,char *s); +void smWriteChar(short x,short y,unsigned char ch); +short smWriteString(short x,short y,char *s); +void smWriteHUD(short x,short y,UCHAR color,char *s); +void BlitBlock(int x,int y,int x1,int y1,UCHAR *buf); +void DrawFillBox(int x,int y,int x1,int y1,UCHAR color); +void DrawHorzLine(int x,int y,int x1,UCHAR color); +void DrawVertLine(int x,int y,int y1,UCHAR color); +void DrawBox(int x,int y,int x1,int y1,UCHAR color); +UCHAR GetColor(int x,int y); +void SaveVideo(UCHAR *buf); +void RestoreVideo(UCHAR *buf); +void CreateButton(int x,int y,HS *hs,char *s); +int QueryBox(int x,int y,char *Msg); + +//----------------------------------------------------------------------------- +// Functions in m1read.c +//----------------------------------------------------------------------------- +short LoadDescFile(char *fName); + diff --git a/map_edit/m1.lbm b/map_edit/m1.lbm new file mode 100644 index 0000000..8bf65f7 Binary files /dev/null and b/map_edit/m1.lbm differ diff --git a/map_edit/m12.bbm b/map_edit/m12.bbm new file mode 100644 index 0000000..c564e93 Binary files /dev/null and b/map_edit/m12.bbm differ diff --git a/map_edit/m12d.bmp b/map_edit/m12d.bmp new file mode 100644 index 0000000..38b08ce Binary files /dev/null and b/map_edit/m12d.bmp differ diff --git a/map_edit/m12d.lbm b/map_edit/m12d.lbm new file mode 100644 index 0000000..0a8b79f Binary files /dev/null and b/map_edit/m12d.lbm differ diff --git a/map_edit/m12d.pcx b/map_edit/m12d.pcx new file mode 100644 index 0000000..fbccda1 Binary files /dev/null and b/map_edit/m12d.pcx differ diff --git a/map_edit/m13d.lbm b/map_edit/m13d.lbm new file mode 100644 index 0000000..bc27b8f Binary files /dev/null and b/map_edit/m13d.lbm differ diff --git a/map_edit/m1files.dat b/map_edit/m1files.dat new file mode 100644 index 0000000..c01a54f --- /dev/null +++ b/map_edit/m1files.dat @@ -0,0 +1,8 @@ +; Resource files for ACK3D Map Editor +SPFONT.BBM +FONT6X9.BBM +M12D.LBM +M13D.LBM +M1SEL.LBM + + \ No newline at end of file diff --git a/map_edit/m1read.c b/map_edit/m1read.c new file mode 100644 index 0000000..292e967 --- /dev/null +++ b/map_edit/m1read.c @@ -0,0 +1,354 @@ +// Map Editor for Animation Construction Kit 3D +// ASCII Reader program +// Author: Lary Myers +// Copyright (c) 1994 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ack3d.h" +#include "ackeng.h" + + +extern UCHAR *Bitmaps[]; +extern UCHAR *ObjBitmaps[]; +extern UCHAR ObjbmNum[]; +extern char MapName[]; +extern char PalName[]; + + short ReadErrorCode; + +/**************************************************************************** +** ** +****************************************************************************/ +char *GetExtent(char *s) +{ + char *e; + +e = strchr(s,'.'); +if (e == NULL) + return(s); +e++; + +return(e); +} + +/**************************************************************************** +** ** +****************************************************************************/ +short LoadBitmap(short BitmapNumber,char *BitmapName,short BitmapType) +{ + short LoadType; + short handle; + short x,y; + short sPos,dPos; + unsigned char ch; + unsigned char *bmp; + +LoadType = 0; +if (!(stricmp(GetExtent(BitmapName),"BBM"))) + LoadType = 1; + +if (!(stricmp(GetExtent(BitmapName),"GIF"))) + LoadType = 2; + + +if (LoadType) + { + if (LoadType == 1) + bmp = AckReadiff(BitmapName); + else + bmp = AckReadgif(BitmapName); + + if (bmp == NULL) + { + ReadErrorCode = ERR_NOMEMORY; + return(-1); + } + + if (BitmapType == TYPE_WALL) + Bitmaps[BitmapNumber] = bmp; + + if (BitmapType == TYPE_OBJECT) + ObjBitmaps[BitmapNumber] = bmp; + + return(0); + } + + +bmp = malloc(4096); +if (bmp == NULL) + { + ReadErrorCode = ERR_NOMEMORY; + return(-1); + } + +if (BitmapType == TYPE_WALL) + Bitmaps[BitmapNumber] = bmp; + +if (BitmapType == TYPE_OBJECT) + ObjBitmaps[BitmapNumber] = bmp; + + +handle = open(BitmapName,O_RDWR|O_BINARY); +if (handle < 1) + { + free(bmp); + ReadErrorCode = ERR_BADFILE; + return(-1); + } + +read(handle,bmp,4); /* Skip width and height for now */ +read(handle,bmp,4096); +close(handle); + +return(0); +} + +/**************************************************************************** +** ** +****************************************************************************/ +char *StripEndOfLine(char *s) +{ + short len; + char ch; + +len = strlen(s); + +while (--len >= 0) + { + ch = s[len]; + if (ch != ' ' && ch != ';' && ch != '\t' && ch != 13 && ch != 10) + break; + + s[len] = '\0'; + } + +return(s); +} + +/**************************************************************************** +** ** +****************************************************************************/ +char *SkipSpaces(char *s) +{ + +while (*s == ' ' || *s == '\t' || *s == ',') + strcpy(s,&s[1]); + +return(s); +} + +/**************************************************************************** +** ** +****************************************************************************/ +char *AddExtent(char *s,char *ext) +{ +if (strchr(s,'.') == NULL) + strcat(s,ext); + +return(s); +} + +/**************************************************************************** +** ** +****************************************************************************/ +char *CopyToComma(char *dest,char *src) +{ + char ch; + +while (*src) + { + ch = *src++; + if (ch == ' ' || ch == '\t' || ch == ',') + break; + + *dest++ = ch; + } + +*dest = '\0'; + +return(src); +} + + + +/**************************************************************************** +** ** +****************************************************************************/ +short LoadDescFile(char *fName) +{ + FILE *fp; + short Mode,fMode,result; + short bType,value,bNum,ObjIndex; + char LineBuf[128]; + char fBuf[128]; + char *s; + +fp = fopen(fName,"rt"); +if (fp == NULL) + { + printf("Unable to open description file: %s\n",fName); + return(-1); + } + +printf("Processing description file %s ",fName); + + +ObjIndex = 0; +Mode = 0; +result = 0; +*MapName = '\0'; + +while (1) + { + if (feof(fp)) + break; + + *LineBuf = '\0'; + fgets(LineBuf,127,fp); + + if (*LineBuf == ';') + continue; + + StripEndOfLine(LineBuf); + SkipSpaces(LineBuf); + + if (!strlen(LineBuf)) + continue; + + printf("."); + + if (!stricmp(LineBuf,"WALLS:")) + { + bType = TYPE_WALL; + Mode = 1; + continue; + } + + if (!stricmp(LineBuf,"ENDWALLS:")) + { + if (Mode != 1) + { + printf("Invalid place for command: %s.\n",LineBuf); + result = -1; + } + + Mode = 0; + continue; + } + + if (!stricmp(LineBuf,"OBJECTS:")) + { + bType = TYPE_OBJECT; + Mode = 2; + continue; + } + + if (!stricmp(LineBuf,"FILES:")) + { + fMode = 1; + continue; + } + + if (!stricmp(LineBuf,"ENDFILES:")) + { + fMode = 0; + continue; + } + + if (!strnicmp(LineBuf,"PALFILE:",8)) + { + strcpy(PalName,SkipSpaces(&LineBuf[8])); + continue; + } + + if (!strnicmp(LineBuf,"MAPFILE:",8)) + { + strcpy(MapName,SkipSpaces(&LineBuf[8])); + continue; + } + + if (Mode == 2) + { + if (!strnicmp(LineBuf,"NUMBER:",7)) + { + value = atoi(&LineBuf[7]); + + if (value < 1 || value >= 255) + { + printf("Invalid object number:\n%s\n",LineBuf); + result = -1; + break; + } + ObjIndex = value; + continue; + } + + if (!strnicmp(LineBuf,"BITMAPS:",8)) + { + strcpy(LineBuf,SkipSpaces(&LineBuf[8])); + value = 0; + strcpy(LineBuf,CopyToComma(fBuf,LineBuf)); + SkipSpaces(fBuf); + bNum = atoi(fBuf); + + if (bNum < 1 || bNum > 255) + { + printf("Invalid bitmap number for object: %d\n",ObjIndex); + result = -1; + break; + } + + ObjbmNum[ObjIndex] = bNum; + continue; + } + } + + if (fMode) + { + value = atoi(LineBuf); + if (value < 1 || value > 255) + { + printf("Invalid number for object: %s.\n",LineBuf); + result = -1; + continue; + } + + s = strpbrk(LineBuf,", \t"); + if (s == NULL) + { + printf("Unable to locate bitmap name for object: %s.\n",LineBuf); + result = -1; + continue; + } + + strcpy(fBuf,SkipSpaces(s)); + AddExtent(fBuf,".img"); + + if (LoadBitmap(value,fBuf,bType)) + { + printf("Error loading bitmap \"%s\".\n",fBuf); + result = -1; + } + continue; + } + + } + +fclose(fp); + +printf("done\n"); + +return(result); +} + diff --git a/map_edit/m1sel.lbm b/map_edit/m1sel.lbm new file mode 100644 index 0000000..cea8b44 Binary files /dev/null and b/map_edit/m1sel.lbm differ diff --git a/map_edit/m1util.c b/map_edit/m1util.c new file mode 100644 index 0000000..e764cc1 --- /dev/null +++ b/map_edit/m1util.c @@ -0,0 +1,564 @@ +// Map Editor for Animation Construction Kit 3D +// Utilities +// Author: Lary Myers +// Copyright (c) 1994 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ack3d.h" +#include "ackeng.h" +#include "m1.h" + + char *smFont; + char *mdFont; + UCHAR FontUseColor; + UCHAR FontTransparent; + UCHAR FontColor; + UCHAR TextBGcolor; + UCHAR ButtonColor; + UCHAR ButtonUpperColor; + UCHAR ButtonLowerColor; + UCHAR BoxColor; + +//============================================================================= +// +//============================================================================= +void SoundBeep(void) +{ +sound(440); +delay(50); +nosound(); +} + + +//============================================================================= +// +//============================================================================= +short LoadSmallFont(void) +{ + short ht,wt; + int len; + +ht = 2; +smFont = AckReadiff((char *)RES_SMFONT); // "spfont.bbm"); +if (smFont == NULL) + return(-1); + +ht = (*(short *)smFont); +wt = (*(short *)&smFont[2]); +len = ht * wt; +memmove(smFont,&smFont[4],len); + +return(0); +} + +//============================================================================= +// +//============================================================================= +short LoadMedFont(void) +{ + short ht,wt; + int len; + +ht = 2; +mdFont = AckReadiff((char *)RES_MDFONT); // "font6x9.bbm"); +if (mdFont == NULL) + return(-1); + +ht = (*(short *)mdFont); +wt = (*(short *)&mdFont[2]); +len = ht * wt; +memmove(mdFont,&mdFont[4],len); + +return(0); +} + +//============================================================================= +// +//============================================================================= +void mdWriteChar(short x,short y,unsigned char ch) +{ + int FontOffset,VidOffset; + int row,col; + UCHAR *Video; + +VidOffset = (y * 320) + x; +Video = VIDSEG; +Video += VidOffset; +FontOffset = ((ch-32) * 6); + +if (ch >= 'A') + FontOffset += 1386; + +for (row = 0; row < 8; row++) + { + if (FontUseColor) + { + ch = mdFont[FontOffset]; + if (ch == ButtonColor) ch = TextBGcolor; + Video[0] = ch; + ch = mdFont[FontOffset+1]; + if (ch == ButtonColor) ch = TextBGcolor; + Video[1] = ch; + ch = mdFont[FontOffset+2]; + if (ch == ButtonColor) ch = TextBGcolor; + Video[2] = ch; + ch = mdFont[FontOffset+3]; + if (ch == ButtonColor) ch = TextBGcolor; + Video[3] = ch; + ch = mdFont[FontOffset+4]; + if (ch == ButtonColor) ch = TextBGcolor; + Video[4] = ch; + ch = mdFont[FontOffset+5]; + if (ch == ButtonColor) ch = TextBGcolor; + Video[5] = ch; + } + else + { + Video[0] = mdFont[FontOffset]; + Video[1] = mdFont[FontOffset+1]; + Video[2] = mdFont[FontOffset+2]; + Video[3] = mdFont[FontOffset+3]; + Video[4] = mdFont[FontOffset+4]; + Video[5] = mdFont[FontOffset+5]; + } + Video += 320; + FontOffset += 198; + } + +} + +//============================================================================= +// +//============================================================================= +short mdWriteString(short x,short y,char *s) +{ + short OrgX; + char ch; + +OrgX = x; + +while (*s) + { + ch = *s++; + + if (ch == 10) + { + x = OrgX; + y += 10; + continue; + } + + if (ch < ' ') + continue; + + ch = toupper(ch); + mdWriteChar(x,y,ch); + x += 6; + } + +return(y); +} + + +//============================================================================= +// +//============================================================================= +void smWriteChar(short x,short y,unsigned char ch) +{ + int FontOffset,VidOffset; + int row,col; + UCHAR *Video; + +VidOffset = (y * 320) + x; +Video = VIDSEG; +Video += VidOffset; +FontOffset = ((ch-32) * 5); + +for (row = 0; row < 5; row++) + { + if (!FontTransparent) + { + Video[0] = TextBGcolor; + Video[1] = TextBGcolor; + Video[2] = TextBGcolor; + Video[3] = TextBGcolor; + } + + if (smFont[FontOffset]) + Video[0] = FontColor; + if (smFont[FontOffset+1]) + Video[1] = FontColor; + if (smFont[FontOffset+2]) + Video[2] = FontColor; + if (smFont[FontOffset+3]) + Video[3] = FontColor; + + Video += 320; + FontOffset += 294; + } + + +} + +//============================================================================= +// +//============================================================================= +short smWriteString(short x,short y,char *s) +{ + short OrgX; + char ch; + +OrgX = x; + +while (*s) + { + ch = *s++; + + if (ch == 10) + { + x = OrgX; + y += 8; + continue; + } + + if (ch < ' ') + continue; + + ch = toupper(ch); + smWriteChar(x,y,ch); + x += 5; + } + +return(y); +} + +//============================================================================= +// +//============================================================================= +void smWriteHUD(short x,short y,UCHAR color,char *s) +{ +FontTransparent = 1; +FontColor = color; +smWriteString(x,y,s); +FontTransparent = 0; +FontColor = 15; +} + +//============================================================================= +// +//============================================================================= +void BlitBlock(int x,int y,int x1,int y1,UCHAR *buf) +{ + int offset,wt; + UCHAR *Video; + +offset = (y * 320) + x; +Video = VIDSEG + offset; +buf += offset; +wt = (x1 - x) + 1; + +HideMouse(); +while (y++ <= y1) + { + memmove(Video,buf,wt); + Video += 320; + buf += 320; + } +ShowMouse(); + +} + +//============================================================================= +// +//============================================================================= +void DrawFillBox(int x,int y,int x1,int y1,UCHAR color) +{ + int wt; + UCHAR *Video; + +wt = (y * 320) + x; +Video = VIDSEG + wt; + +wt = (x1-x)+1; + +while (y++ <= y1) + { + memset(Video,color,wt); + Video += 320; + } + +} + + +//============================================================================= +// +//============================================================================= +void DrawHorzLine(int x,int y,int x1,UCHAR color) +{ + UCHAR *Video; + int offset; + +offset = (y * 320) + x; +Video = VIDSEG + offset; + +memset(Video,color,(x1-x)+1); + +} + +//============================================================================= +// +//============================================================================= +void DrawVertLine(int x,int y,int y1,UCHAR color) +{ + UCHAR *Video; + int offset; + +offset = (y * 320) + x; +Video = VIDSEG + offset; + +while (y++ <= y1) + { + *Video = color; + Video += 320; + } + +} + +//============================================================================= +// +//============================================================================= +void DrawBox(int x,int y,int x1,int y1,UCHAR color) +{ + +DrawHorzLine(x,y,x1,color); +DrawHorzLine(x,y1,x1,color); +DrawVertLine(x,y,y1,color); +DrawVertLine(x1,y,y1,color); + +} + + +//============================================================================= +// +//============================================================================= +UCHAR GetColor(int x,int y) +{ + int offset; + UCHAR *Video; + +offset = (y * 320) + x; +Video = VIDSEG + offset; +return(*Video); +} + + +//============================================================================= +// +//============================================================================= +void SaveVideo(UCHAR *buf) +{ +memmove(buf,VIDSEG,64000); +} + +//============================================================================= +// +//============================================================================= +void RestoreVideo(UCHAR *buf) +{ +memmove(VIDSEG,buf,64000); +} + + +//============================================================================= +// +//============================================================================= +void CreateButton(int x,int y,HS *hs,char *s) +{ + int len,plen,x1,y1; + +hs->x = x; +hs->y = y; + +len = strlen(s); +plen = len * 6; +hs->x1 = x1 = x + plen + 5; +hs->y1 = y1 = y + 11; + +DrawFillBox(x,y,x1,y1,ButtonColor); +DrawHorzLine(x,y,x1,ButtonUpperColor); +DrawVertLine(x,y,y1,ButtonUpperColor); +DrawVertLine(x1,y+1,y1,ButtonLowerColor); +DrawHorzLine(x,y1,x1,ButtonLowerColor); + +x1 = x + 3; +y1 = y + 2; +while (*s) + { + mdWriteChar(x1,y1,toupper(*s++)); + x1 += 6; + } + +} + +//============================================================================= +// +//============================================================================= +UCHAR *SaveBlock(int x,int y,int x1,int y1) +{ + int ht,wt,size,offset; + UCHAR *buf,*bPtr,*vPtr; + +ht = (y1 - y) + 1; +wt = (x1 - x) + 1; +size = (ht * wt) + 4; +buf = (UCHAR *)malloc(size); +if (buf == NULL) + return(buf); + +bPtr = buf; +(*(short *)bPtr) = ht; +bPtr += 2; +(*(short *)bPtr) = wt; +bPtr += 2; + +offset = (y * 320) + x; +vPtr = VIDSEG + offset; + +HideMouse(); + +while (ht-- > 0) + { + memmove(bPtr,vPtr,wt); + vPtr += 320; + bPtr += wt; + } + +ShowMouse(); + +return(buf); +} + +//============================================================================= +// +//============================================================================= +void RestoreBlock(int x,int y,UCHAR *buf) +{ + int ht,wt,offset; + UCHAR *vPtr; + +if (buf == NULL) + return; + +offset = (y * 320) + x; +vPtr = VIDSEG + offset; + +ht = (*(short *)buf); +buf += 2; +wt = (*(short *)buf); +buf += 2; +HideMouse(); +while (ht-- > 0) + { + memmove(vPtr,buf,wt); + vPtr += 320; + buf += wt; + } +ShowMouse(); +} + + +//============================================================================= +// +//============================================================================= +int QueryBox(int x,int y,char *Msg) +{ + int done,plen; + int x1,y1; + UCHAR SaveColor,SaveBGcolor; + short mx,my,mbutton; + char *s; + UCHAR *vBuf; + HS hs[2]; + + +SaveColor = BoxColor; +SaveBGcolor = TextBGcolor; +BoxColor = TextBGcolor = ButtonColor; +y1 = y + 42; +s = Msg; +plen = 0; +x1 = 0; + +while (*s) + { + if (*s++ == 10) + { + y1 += 10; + x1 = 0; + } + else + { + x1 += 6; + if (x1 > plen) plen = x1; + } + } + +x1 = x + plen + 10; + +if ((x1-x) < 100) + x1 = x + 100; + +HideMouse(); +vBuf = SaveBlock(x,y,x1,y1); +DrawBackBox(x,y,x1,y1); +FontUseColor = 1; +mdWriteString(x+5,y+6,Msg); +BoxColor = SaveColor; +TextBGcolor = SaveBGcolor; +FontUseColor = 0; +CreateButton(x+5,y1-15,&hs[0]," Ok "); +CreateButton(x1-46,y1-15,&hs[1],"CANCEL"); +ShowMouse(); + +done = 0; +while (!done) + { + mbutton = ReadMouseCursor(&my,&mx); + + if (mbutton & 1) + { + for (x1 = 0; x1 < 2; x1++) + { + if (mx >= hs[x1].x && mx <= hs[x1].x1 && my >= hs[x1].y && my <= hs[x1].y1) + { + done = 1; + break; + } + + } + + } + + } + +if (vBuf != NULL) + { + RestoreBlock(x,y,vBuf); + free(vBuf); + } +return(x1); +} + + + diff --git a/map_edit/mapedit.h b/map_edit/mapedit.h new file mode 100644 index 0000000..765642e --- /dev/null +++ b/map_edit/mapedit.h @@ -0,0 +1,52 @@ +/* Header file for ACK-3D Map Editor */ + +#define CURRENT_SQUAREX 161 +#define CURRENT_SQUAREY 4 + +#define PASS_X 243 +#define PASS_Y 2 + +#define SCREEN_COLOR 20 + +#define BLACK 0 +#define LIGHTBLUE 64 +#define BLUE 69 +#define LIGHTMAGENTA 112 +#define MAGENTA 119 +#define RED 40 +#define LIGHTRED 32 +#define GREEN 88 +#define LIGHTGREEN 80 +#define YELLOW 120 + +typedef struct { + short x; + short y; + short x1; + short y1; +} RECT; + +typedef struct { + short BoxX; + short BoxY; + char *FileName; + char DoBeep; + short NumButtons; + RECT ButtonCoords[4]; +} BOXES; + +#define BOX_ALREADY_1_OBJECT 0 +#define BOX_NEW_WARNING 1 +#define BOX_MODIFIED_WARNING 2 +#define BOX_SAVED 3 +#define BOX_ALREADY_START_CODE 4 +#define BOX_MAX_SPECIAL_CODE 5 + +/* Prototypes */ +void SetVmode(short); +void SetPalette(unsigned char *); +char *AddExtent(char *,char *); +unsigned short inkey(void); +void SetVGAmode(void); +void SetTextMode(void); + diff --git a/map_edit/measm.asm b/map_edit/measm.asm new file mode 100644 index 0000000..ac6747f --- /dev/null +++ b/map_edit/measm.asm @@ -0,0 +1,123 @@ + + IDEAL + JUMPS + include "prologue.mac" + P386 ; 386 specific opcodes and shit allowed. + P387 ; Allow 386 processor + + + MASM + .MODEL FLAT ;32-bit OS/2 model + .CODE + IDEAL + + PUBLIC SetPalette2_ + PUBLIC SetVGAmode_ + PUBLIC SetTextMode_ + PUBLIC inkey_ + PUBLIC PutHex_ + +;============================================================================== +; void SetPalette2(unsigned char *PalBuf,short count); +;============================================================================== + +Proc SetPalette2_ near + push esi + + mov esi,eax + mov cx,dx + mov bx,0 + cld + mov dx,3C8H +sp210: + mov al,bl + out dx,al + inc dx + lodsb + out dx,al + lodsb + out dx,al + lodsb + out dx,al + dec dx + inc bx + loop sp210 + + pop esi + ret + endp + + +;============================================================================== +; void SetVGAmode(void); +;============================================================================== +Proc SetVGAmode_ near + push ebp + mov ax,13h + int 10h ; Set 320x200x256 + pop ebp + ret + endp + +;============================================================================== +; +;============================================================================== +Proc SetTextMode_ near + push ebp + mov ax,3 + int 10h + pop ebp + ret + endp + +;============================================================================== +; +;============================================================================== +Proc inkey_ near + xor eax,eax + mov ah,1 ;see if key available + int 16h + jz ink080 ;nope + xor ax,ax + int 16h + jmp short ink090 + +ink080: + xor ax,ax +ink090: + ret + endp + +;============================================================================== +; +;============================================================================== +Proc HexOut_ near + and al,15 + cmp al,10 + jb short hex010 + add al,7 + +hex010: + add al,'0' + stosb + ret + endp + +;============================================================================== +; void PutHex(char *buf,UINT mCode); +;============================================================================== +Proc PutHex_ near + push edi + mov edi,eax + mov eax,edx + shr al,4 + call HexOut_ + mov eax,edx + call HexOut_ + xor al,al + stosb + pop edi + ret + endp + end + diff --git a/map_edit/medit.c b/map_edit/medit.c new file mode 100644 index 0000000..7716c56 --- /dev/null +++ b/map_edit/medit.c @@ -0,0 +1,1981 @@ +/* Map Editor for Animation Construction Kit 3D */ +/* Author: Lary Myers */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ack3d.h" +#include "ackeng.h" +#include "mapedit.h" + + +#define GRID_FLOOR_FLAGS (WALL_TYPE_UPPER+DOOR_TYPE_SECRET+DOOR_TYPE_SPLIT+DOOR_TYPE_SLIDE) + +extern unsigned char colordat[]; + + +void smWriteString(short x,short y,char *s); +unsigned char * Readiff(char *picname); + short rsHandle; + unsigned char *BkBuffer; + unsigned char *smFont; + short ErrorCode; + short BigBitmap; + short GridX; + short GridY; + short LastObjCode; + short LastWallCode; + short CurrentType; + short CurrentCode; + short ModifiedFlag; + short GridFlag; + short PalSetFlag; + UINT WallFlags; + + unsigned short MapGrid[GRID_MAX+1]; + unsigned short ObjGrid[GRID_MAX+1]; + unsigned short FloorGrid[GRID_MAX+1]; + unsigned short CeilGrid[GRID_MAX+1]; + unsigned short *CurrentGrid; + + unsigned char *WallBitmaps[256]; + unsigned char *ObjBitmaps[256]; + + unsigned char ObjbmNum[256]; + unsigned char Palette[768]; + + char GridFile[64]; + char PalFile[64]; + +typedef struct { + short x; + short y; + short MapType; +unsigned short MapCode; + char *Text; +} SELECTBOX; + + + + SELECTBOX Squares[] = { + 40,6,-1,0,"Choose one of the following", + 60,20,TYPE_WALL,0 ,"Normal square", + 60,30,TYPE_WALL,DOOR_TYPE_SLIDE ,"Sliding door ", + 60,40,TYPE_WALL,DOOR_TYPE_SPLIT ,"Split door ", + 60,50,TYPE_WALL,DOOR_TYPE_SECRET ,"Secret door ", + 60,60,TYPE_WALL,DOOR_LOCKED ,"Locked door ", + 60,70,TYPE_WALL,MAP_STARTCODE ,"Start square ", + 60,80,TYPE_WALL,MAP_UPCODE ,"Up square ", + 60,90,TYPE_WALL,MAP_DOWNCODE ,"Down square ", + 60,100,TYPE_WALL,MAP_GOALCODE ,"Goal square ", + 60,110,TYPE_WALL,WALL_TYPE_TRANS ,"Transparent ", + 60,120,TYPE_WALL,WALL_TYPE_MULTI ,"Multi-Height ", + 60,130,TYPE_WALL,WALL_TYPE_UPPER ,"Raised Wall ", + 70,140,-2,0 ,"Cancel", + -1,-1,-1,0,0 + }; + + SELECTBOX FillBox[] = { + 30,20,-1,0,"Fill will place the current", + 30,30,-1,0,"bitmap in all locations of", + 30,40,-1,0,"the map. Do you wish to do this?", + 60,60,-2,1," Yes ", + 110,60,-2,2," No ", + -1,-1,-1,0,0 + }; + + SELECTBOX ClsBox[] = { + 40,20,-1,0,"Clear will erase the entire", + 40,30,-1,0,"map. Do you wish to do this?", + 60,50,-2,1," Yes ", + 110,50,-2,2," No ", + -1,-1,-1,0,0 + }; + + SELECTBOX SaveBox[] = { + 40,20,-1,0,"Map has been modified.", + 40,30,-1,0,"Do you wish to save it.", + 60,50,-2,1," Yes ", + 110,50,-2,2," No ", + -1,-1,-1,0,0 + }; + + SELECTBOX MapSavedBox[] = { + 55,50,-1,0,"Map has been saved.", + 80,70,-2,0," Okay ", + -1,-1,-1,0,0 + }; + + + SELECTBOX OverwriteBox[] = { + 40,30,-1,0,"File exist. Do you wish", + 40,40,-1,0,"overwrite it?", + 60,60,-2,1," Yes ", + 110,60,-2,2," No ", + -1,-1,-1,0,0 + }; + + SELECTBOX LoadBox[] = { + 40,20,-1,0,"Load map will reload the", + 40,30,-1,0,"original map and erase", + 40,40,-1,0,"any changes. Do you wish", + 40,50,-1,0,"to do this?", + 60,70,-2,1," Yes ", + 110,70,-2,2," No ", + -1,-1,-1,0,0 + }; + + SELECTBOX BorderBox[] = { + 40,20,-1,0,"Border draw will fill", + 40,30,-1,0,"the border with the", + 40,40,-1,0,"current bitmap. Do you", + 40,50,-1,0,"wish to do this?", + 60,70,-2,1," Yes ", + 110,70,-2,2," No ", + -1,-1,-1,0,0 + }; + + + RECT HotSpots[] = { + 2,2, 178,143, /* 0 - Main grid */ + + 183,3, 196,14, /* 1 - Map Up arrow */ + 186,134, 196,145, /* 2 - Map Dn arrow */ + 165,150, 181,160, /* 3 - Map Rt arrow */ + 3,150, 19,160, /* 4 - Map Lt arrow */ + + 241,0, 251,11, /* 5 - Box Up arrow */ + 241,56, 251,67, /* 6 - Box Dn arrow */ + + 209,22, 231,40, /* 7 - Show multiple boxes */ + + 252,70, 283,94, /* 8 - Wall button */ + 287,70, 318,94, /* 9 - Object button */ + 252,97, 283,121, /* 10 - Fill */ + 287,97, 318,121, /* 11 - Clear */ + 252,124, 283,148, /* 12 - Save */ + 287,124, 318,148, /* 13 - Load */ + 287,151, 318,175, /* 14 - Exit */ + + 217,70, 248,94, /* 15 - Horizontal door */ + 217,97, 248,121, /* 16 - Vertical door */ + + 193,48, 199,54, /* 17 - Transparent toggle */ + 193,58, 199,64, /* 18 - MultiHeight toggle */ + + 217,151, 248,175, /* 19 - Floor toggle */ + 253,151, 283,175, /* 20 - Ceiling toggle */ + 217,124, 248,148, /* 21 - Map toggle */ + -1,-1, -1,-1 /* End of table */ + }; + + +short MouseInstalled(void); +void ShowMouse(void); +void HideMouse(void); +short ReadMouseCursor(short *mrow,short *mcol); +short ReadMouseButtons(void); +void SetMouseCursor(short mrow,short mcol); +void SetMouseMinMaxColumns(short mincol,short maxcol); +void SetMouseMinMaxRows(short minrow,short maxrow); +void SetMouseShape(short hsrow,short hscol,char far *mask); +void MouseReleased(void); +void PutHex(char *buf,UINT mCode); + + +/**************************************************************************** +** ** +****************************************************************************/ +void ShowCheck(short x,short y,short x1,short y1,UCHAR color) +{ + UINT offset; + short xp,yp; + UCHAR *Video; + +xp = x; +yp = y; +Video = (char *)0xA0000; + +while (xp <= x1) + { + offset = (yp * 320) + xp; + Video[offset] = color; + xp++; + yp++; + } + +xp = x1; +yp = y; + +while (xp >= x) + { + offset = (yp * 320) + xp; + Video[offset] = color; + xp--; + yp++; + } + +} + +/**************************************************************************** +** ** +****************************************************************************/ +void ShowHotspotCheck(short index,UCHAR color) +{ + short x,y,x1,y1; + + +x = HotSpots[index].x + 1; +y = HotSpots[index].y + 1; +x1 = HotSpots[index].x1 - 1; +y1 = HotSpots[index].y1 - 1; + +HideMouse(); +ShowCheck(x,y,x1,y1,color); +ShowMouse(); +} + + +/**************************************************************************** +** ** +****************************************************************************/ +void SoundBeep(void) +{ +sound(440); +delay(50); +nosound(); +} + + +/**************************************************************************** +** ** +****************************************************************************/ +short GetAction(short mx,short my) +{ + short i = 0; + +while (1) + { + if (HotSpots[i].x < 0) + return(-1); + + if (mx >= HotSpots[i].x && + mx <= HotSpots[i].x1 && + my >= HotSpots[i].y && + my <= HotSpots[i].y1) + break; + + i++; + } + +return(i); +} + + +/**************************************************************************** +** ** +****************************************************************************/ +short LoadAndShowScreen(void) +{ + unsigned char *Video; + +BkBuffer = Readiff("medit.lbm"); + +if (BkBuffer == NULL) + return(-1); + +Video = (char *)0xA0000; + +HideMouse(); +memmove(Video,&BkBuffer[4],64000); +ShowMouse(); + +return(0); +} + +/**************************************************************************** +** ** +****************************************************************************/ +short LoadSmallFont(void) +{ + short ht,wt,len; + +smFont = Readiff("smfont.bbm"); +if (smFont == NULL) + return(-1); + +ht = (*(short *)smFont); +wt = (*(short *)&smFont[2]); +len = ht * wt; +memmove(smFont,&smFont[4],len); + +return(0); +} + +/**************************************************************************** +** ** +****************************************************************************/ +void ClearMapArea(void) +{ + short row; + unsigned char *Video; + +Video = (char *)0xA0000; +Video += 642; + +HideMouse(); +for (row = 2; row < 146; row++) + { + memset(Video,SCREEN_COLOR,180); + Video += 320; + } +ShowMouse(); +} + +/**************************************************************************** +** ** +****************************************************************************/ +void DrawBox(short x,short y,short x1,short y1,UCHAR color) +{ + UINT offset,wt; + unsigned char *Video; + +offset = (y * 320) + x; +Video = (char *)0xA0000; +Video += offset; +wt = x1 - x; +memset(Video,color,wt+1); +Video += 320; + +while (++y < y1) + { + *Video = color; + Video[wt] = color; + Video += 320; + } + +memset(Video,color,wt+1); + +} + +/**************************************************************************** +** ** +****************************************************************************/ +void ShowBitmap(short x,short y,unsigned char *bmp) +{ + short row,col,brow,bcol; + unsigned char *Video; + +Video = (char *)0xA0000; +Video += ((y * 320) + x); +HideMouse(); + +if (BigBitmap) + { + brow = 0; + for (row = 0; row < 64; row++) + { + bcol = brow * 128; + for (col = 0; col < 64; col++) + { + Video[col] = bmp[bcol]; + bcol += 2; + } + Video += 320; + brow += 2; + } + + } +else + { + for (row = 0; row < 64; row++) + { + memmove(Video,bmp,64); + bmp += 64; + Video += 320; + } + } +ShowMouse(); +} + + +/**************************************************************************** +** ** +****************************************************************************/ +void ShowSelectBox(SELECTBOX *sb) +{ + short x1,y1; + +HideMouse(); +ClearMapArea(); + +while (sb->x != -1) + { + smWriteString(sb->x,sb->y,sb->Text); + + if (sb->MapType == -2) /* A button */ + { + x1 = sb->x + (strlen(sb->Text) * 4); + y1 = sb->y + 5; + DrawBox(sb->x - 2,sb->y - 2,x1+1,y1+1,BLACK); + } + sb++; + } +ShowMouse(); + +} + +/**************************************************************************** +** ** +****************************************************************************/ +UCHAR DetermineMapColor(short offset) +{ + UCHAR color; + unsigned short Mcode; + +if (GridFlag && MapGrid[offset]) + return(LIGHTBLUE); + + +color = SCREEN_COLOR; +Mcode = CurrentGrid[offset]; +if (!Mcode) + { + Mcode = ObjGrid[offset]; + if (Mcode & 0xFF) + color = LIGHTBLUE; + + } +else + { + if (Mcode & DOOR_TYPE_SECRET) + color = GREEN; + + if (Mcode & DOOR_TYPE_SLIDE) + color = RED; + + if (Mcode & DOOR_TYPE_SPLIT) + color = LIGHTRED; + + if (Mcode & WALL_TYPE_TRANS) + color = LIGHTGREEN; + + if (Mcode & WALL_TYPE_MULTI) + color = LIGHTMAGENTA; + + if (Mcode & DOOR_LOCKED) + color++; + } + + +return(color); +} + +/**************************************************************************** +** ** +****************************************************************************/ +void ShowGrid(void) +{ + int row,col,offset; + int x,y; + char buf[8]; + char blank[3]; + UCHAR color; +unsigned short Mcode; + +offset = (GridY * GRID_WIDTH) + GridX; +*blank = ' '; +blank[1] = ' '; +blank[2] = '\0'; +y = 2; +HideMouse(); +for (row = 0; row < 18; row++) + { + x = 2; + for (col = 0; col < 18; col++) + { + DrawBox(x,y,x+10,y+8,BLACK); + color = DetermineMapColor(offset); + Mcode = CurrentGrid[offset]; + if (!Mcode) + Mcode = ObjGrid[offset]; + + if (Mcode & 0xFF) + { + // sprintf(buf,"%02X",Mcode & 0xFF); + PutHex(buf,Mcode & 0xFF); + smWriteString(x+2,y+2,buf); + } + else + smWriteString(x+2,y+2,blank); + + DrawBox(x+1,y+1,x+9,y+7,color); + x += 10; + offset++; + } + + y += 8; + offset += GRID_WIDTH - 18; + } + +ShowMouse(); +} + +/**************************************************************************** +** ** +****************************************************************************/ +void smWriteChar(short x,short y,unsigned char ch) +{ + UINT FontOffset,VidOffset; + UINT row,col; + unsigned char *Video; + +VidOffset = (y * 320) + x; +Video = (char *)0xA0000; +Video += VidOffset; +row = ch / 32; +col = ch - (row * 32); + +FontOffset = ((row * 1344) + 192) + ((col * 6) + 1); + +for (row = 0; row < 5; row++) + { + Video[0] = smFont[FontOffset]; + Video[1] = smFont[FontOffset + 1]; + Video[2] = smFont[FontOffset + 2]; + Video[3] = smFont[FontOffset + 3]; + Video += 320; + FontOffset += 192; + } + +} + +/**************************************************************************** +** ** +****************************************************************************/ +void smWriteString(short x,short y,char *s) +{ + char ch; + +HideMouse(); +while (*s) + { + ch = toupper(*s++); + smWriteChar(x,y,ch); + x += 4; + if (ch == 'M' || ch == 'N' || ch == 'W') + x++; + + } +ShowMouse(); + +} + +/**************************************************************************** +** ** +****************************************************************************/ +void ShowCoords(short x,short y) +{ + short row,col; + char buf[12]; + +if (x < 2 || y < 2 || x > 182 || y > 146) + return; + +x -= 2; +y -= 2; + +row = (y / 8) + GridY; +col = (x / 10) + GridX; + +sprintf(buf,"%02d,%02d",col,row); +smWriteString(108,154,buf); + +} + +/**************************************************************************** +** ** +****************************************************************************/ +void ShowGridCoords(void) +{ + char buf[10]; + +sprintf(buf,"%02d,%02d",GridX,GridY); +smWriteString(82,154,buf); + +} + + +/**************************************************************************** +** ** +****************************************************************************/ +short FindSelectHit(SELECTBOX *sb,short mx,short my) +{ + short index,x1,y1; + +index = 0; + +while (sb->x != -1) + { + if (sb->MapType != -1) + { + x1 = sb->x + (strlen(sb->Text) * 4); + y1 = sb->y + 5; + if (mx >= sb->x && my >= sb->y && mx <= x1 && my <= y1) + return(index); + + } + + sb++; + index++; + } + +return(-1); +} + +/**************************************************************************** +** ** +****************************************************************************/ +void GetSpecialCode(short x,short y) +{ + short GridOffset; + short mx,my,mbutton; + short index,done; + UINT MapCode; + +x -= 2; +y -= 2; +GridOffset = (((y / 8) + GridY) * GRID_WIDTH) + (x / 10) + GridX; + +ShowSelectBox(Squares); +done = 0; +MouseReleased(); + +while (!done) + { + mbutton = ReadMouseCursor(&my,&mx); + + if (mbutton & 1) + { + index = FindSelectHit(Squares,mx,my); + + if (index != -1) + { + if (Squares[index].MapType == -2) /* Cancel */ + { + done = 1; + break; + } + + MapCode = Squares[index].MapCode; + + if (Squares[index].MapType == TYPE_WALL) + { + if (!MapCode) + CurrentGrid[GridOffset] &= 0x00FF; + + if (MapCode & 0xFF00) + CurrentGrid[GridOffset] |= MapCode; + else + if (MapCode & 0xFF) + { + CurrentGrid[GridOffset] &= 0xFF00; + CurrentGrid[GridOffset] |= MapCode; + } + } + + done = 1; + } + + } + } + +MouseReleased(); +ClearMapArea(); +ShowGrid(); +} + +/**************************************************************************** +** ** +****************************************************************************/ +short GeneralSelectBox(SELECTBOX *sb,short DoBeep) +{ + short done,index; + short result,mx,my,mbutton; + +ShowSelectBox(sb); + +if (DoBeep) + SoundBeep(); + +result = done = 0; + +while (!done) + { + mbutton = ReadMouseCursor(&my,&mx); + if (mbutton & 1) + { + index = FindSelectHit(sb,mx,my); + if (index != -1) + { + sb += index; + result = sb->MapCode; + done = 1; + } + } + } + +MouseReleased(); +ClearMapArea(); +ShowGrid(); + +return(result); +} + +/**************************************************************************** +** ** +****************************************************************************/ +short DupObject(UINT Mcode) +{ + short i; + +Mcode &= 0xFF; + +for (i = 0; i < GRID_MAX; i++) + { + if ((ObjGrid[i] & 0xFF) == Mcode) + return(1); + + } + +return(0); +} + +/**************************************************************************** +** ** +****************************************************************************/ +void PutCode(short x,short y,UINT Mcode) +{ + short row,col; + short GridOffset; + UINT mCode; + UCHAR color; + char buf[4]; + +if (CurrentType == TYPE_OBJECT && Mcode > 0 && DupObject(Mcode)) + { + SoundBeep(); + return; + } + +x -= 2; +y -= 2; + +if (x >= HotSpots[0].x1 || + x <= HotSpots[0].x || + y >= HotSpots[0].y1 || + y <= HotSpots[0].y) + { + return; + } + +row = (y / 8) + GridY; +col = (x / 10) + GridX; +if (row > 63 || col > 63 || row < 0 || col < 0) + return; + +GridOffset = (row * GRID_WIDTH) + col; + +#if 0 +if (GridFlag) + { + mCode = MapGrid[GridOffset]; + if (mCode > 0 && (!(mCode & GRID_FLOOR_FLAGS))) + { + SoundBeep(); + return; + } + } +#endif + +if (CurrentType == TYPE_WALL) + { + CurrentGrid[GridOffset] &= 0xFF00; + CurrentGrid[GridOffset] |= Mcode; + if (Mcode && !GridFlag) + CurrentGrid[GridOffset] |= WallFlags; + } +else + { + if (!GridFlag) + { + ObjGrid[GridOffset] &= 0xFF00; + ObjGrid[GridOffset] |= Mcode; + } + } + +if (!Mcode) + { + CurrentGrid[GridOffset] = 0; + if (!GridFlag) + ObjGrid[GridOffset] = 0; + } + + +color = DetermineMapColor(GridOffset); + +row = ((y / 8) * 8); +col = ((x / 10) * 10); + +if (Mcode & 0xFF) +// sprintf(buf,"%02X",Mcode & 0xFF); + PutHex(buf,Mcode & 0xFF); +else + strcpy(buf," "); + +col += 2; +row += 2; +HideMouse(); +smWriteString(col + 2,row + 2,buf); +DrawBox(col+1,row+1,col+9,row+7,color); +ShowMouse(); +ModifiedFlag = 1; +} + +/**************************************************************************** +** ** +****************************************************************************/ +void ShowCurrentCode(void) +{ + short row; + UCHAR color; + char buf[4]; + unsigned char *Video,*bmp; + +//sprintf(buf,"%02X",CurrentCode & 0xFF); +PutHex(buf,CurrentCode & 0xFF); +HideMouse(); +DrawBox(241,27,251,35,BLACK); +smWriteString(243,29,buf); +if (CurrentType == TYPE_WALL) + { + color = SCREEN_COLOR; + bmp = WallBitmaps[CurrentCode & 0xFF]; + } +else + { + color = LIGHTBLUE; + bmp = ObjBitmaps[ObjbmNum[CurrentCode & 0xFF]]; + } + +DrawBox(242,28,250,34,color); + +if (bmp != NULL) + ShowBitmap(254,2,bmp); +else + { +// Video = MK_FP(0xA000,(2 * 320) + 254); + Video = (char *)0xA0000; + Video += 894; + for (row = 0; row < 64; row++) + { + memset(Video,SCREEN_COLOR,64); + Video += 320; + } + SoundBeep(); + } + +ShowMouse(); +} + +/**************************************************************************** +** ** +****************************************************************************/ +void ShowButton(short x,short y,char *Text) +{ + +smWriteString(x,y,Text); +DrawBox(x-2,y-2,x + (strlen(Text) * 4) + 1,y + 6,BLACK); + +} + +/**************************************************************************** +** ** +****************************************************************************/ +void ShowNextGroup(short StartCode) +{ + short i,x,y; +unsigned char cCode; +unsigned char *bmp,*Video; + char buf[10]; + +x = 0; +cCode = StartCode & 0xFF; + +HideMouse(); +for (i = 0; i < 5; i++) + { + if (CurrentType == TYPE_WALL) + bmp = WallBitmaps[cCode]; + else + bmp = ObjBitmaps[ObjbmNum[cCode]]; + + if (bmp != NULL) + ShowBitmap(x,0,bmp); + else + { +// Video = MK_FP(0xA000,x); + Video = (char *)0xA0000; + Video += x; + for (y = 0; y < 64; y++) + { + memset(Video,SCREEN_COLOR,64); + Video += 320; + } + DrawBox(x,0,x+63,63,BLACK); + } + +// sprintf(buf,"%02X",cCode); + PutHex(buf,cCode); + ShowButton(x+30,70,buf); + + if (CurrentType == TYPE_WALL) + { + smWriteString(x,80," "); + + if (cCode == DOOR_XCODE) + smWriteString(x,80,"Vertical door"); + if (cCode == DOOR_YCODE) + smWriteString(x,80,"Horizontal door"); + if (cCode == DOOR_SIDECODE) + smWriteString(x,80,"Door side"); + } + + cCode++; + if (CurrentType == TYPE_OBJECT && cCode >= MAX_OBJECTS) + cCode = 0; + + x += 64; + } +ShowMouse(); + +} + + +/**************************************************************************** +** ** +****************************************************************************/ +void ShowBitmapGroup(void) +{ + short i,x,y; + short mbutton,mx,my; + short StartCode; + unsigned char *Video,*bmp; + +Video = (char *)0xA0000; + +MouseReleased(); +HideMouse(); +memmove(BkBuffer,Video,64000); +memset(Video,SCREEN_COLOR,64000); + +StartCode = CurrentCode; +ShowNextGroup(StartCode); + +ShowButton(6,100,"<- Previous"); +ShowButton(150,100,"Cancel"); +ShowButton(280,100,"Next ->"); + +ShowMouse(); + + +while (1) + { + mbutton = ReadMouseCursor(&my,&mx); + if (mbutton & 1) + { + if (mx > 5 && mx < 50 && my > 99 && my < 109) + { + StartCode -= 1; + if (CurrentType == TYPE_WALL) + StartCode &= 0xFF; + else + { + if (StartCode < 0) + StartCode = MAX_OBJECTS - 1; + } + ShowNextGroup(StartCode); + delay(90); + continue; + } + + if (mx > 149 && mx < 174 && my > 99 && my < 109) + break; + + + if (mx > 279 && mx < 309 && my > 99 && my < 109) + { + StartCode += 1; + if (CurrentType == TYPE_WALL) + StartCode &= 0xFF; + else + { + if (StartCode >= MAX_OBJECTS) + StartCode = 0; + } + ShowNextGroup(StartCode); + delay(90); + continue; + } + + if (my < 64) + { + mx /= 64; + StartCode += mx; + if (CurrentType == TYPE_WALL) + StartCode &= 0xFF; + else + { + if (StartCode >= MAX_OBJECTS) + StartCode -= MAX_OBJECTS; + } + CurrentCode = StartCode; + break; + } + + } + + } + +HideMouse(); +memmove(Video,BkBuffer,64000); +ShowCurrentCode(); +ShowMouse(); +MouseReleased(); + +} + +/**************************************************************************** +** ** +****************************************************************************/ +char *GetExtent(char *s) +{ + char *e; + +e = strchr(s,'.'); +if (e == NULL) + return(s); +e++; + +return(e); +} + +/**************************************************************************** +** ** +****************************************************************************/ +short LoadBitmap(short BitmapNumber,char *BitmapName,short BitmapType) +{ + short LoadType; + short handle; + short x,y; + short sPos,dPos; + unsigned char ch; + unsigned char *bmp; + +LoadType = 0; +if (!(stricmp(GetExtent(BitmapName),"BBM"))) + LoadType = 1; + +if (!(stricmp(GetExtent(BitmapName),"GIF"))) + LoadType = 2; + + +if (LoadType) + { + if (LoadType == 1) + bmp = Readiff(BitmapName); + else + bmp = AckReadgif(BitmapName); + + if (bmp == NULL) + { + ErrorCode = ERR_NOMEMORY; + return(-1); + } + + if (BitmapType == TYPE_WALL) + WallBitmaps[BitmapNumber] = bmp; + + if (BitmapType == TYPE_OBJECT) + ObjBitmaps[BitmapNumber] = bmp; + + if ((*(short *)bmp) == 128) + { + BigBitmap = 1; + memmove(bmp,&bmp[4],16384); + } + else + memmove(bmp,&bmp[4],4096); + + return(0); + } + + +bmp = malloc(4096); +if (bmp == NULL) + { + ErrorCode = ERR_NOMEMORY; + return(-1); + } + +if (BitmapType == TYPE_WALL) + WallBitmaps[BitmapNumber] = bmp; + +if (BitmapType == TYPE_OBJECT) + ObjBitmaps[BitmapNumber] = bmp; + + +handle = open(BitmapName,O_RDWR|O_BINARY); +if (handle < 1) + { + free(bmp); + ErrorCode = ERR_BADFILE; + return(-1); + } + +read(handle,bmp,4); /* Skip width and height for now */ +read(handle,bmp,4096); +close(handle); + +return(0); +} + +/**************************************************************************** +** ** +****************************************************************************/ +char *StripEndOfLine(char *s) +{ + short len; + char ch; + +len = strlen(s); + +while (--len >= 0) + { + ch = s[len]; + if (ch != ' ' && ch != ';' && ch != '\t' && ch != 13 && ch != 10) + break; + + s[len] = '\0'; + } + +return(s); +} + +/**************************************************************************** +** ** +****************************************************************************/ +char *SkipSpaces(char *s) +{ + +while (*s == ' ' || *s == '\t' || *s == ',') + strcpy(s,&s[1]); + +return(s); +} + +/**************************************************************************** +** ** +****************************************************************************/ +char *AddExtent(char *s,char *ext) +{ +if (strchr(s,'.') == NULL) + strcat(s,ext); + +return(s); +} + +/**************************************************************************** +** ** +****************************************************************************/ +char *CopyToComma(char *dest,char *src) +{ + char ch; + +while (*src) + { + ch = *src++; + if (ch == ' ' || ch == '\t' || ch == ',') + break; + + *dest++ = ch; + } + +*dest = '\0'; + +return(src); +} + + + +/**************************************************************************** +** ** +****************************************************************************/ +short LoadDescFile(char *fName) +{ + FILE *fp; + short Mode,fMode,result; + short bType,value,bNum,ObjIndex; + char LineBuf[128]; + char fBuf[128]; + char *s; + +fp = fopen(fName,"rt"); +if (fp == NULL) + { + printf("Unable to open description file: %s\n",fName); + return(-1); + } + +printf("Processing description file %s ",fName); + + +ObjIndex = 0; +Mode = 0; +result = 0; +*GridFile = '\0'; + +while (1) + { + if (feof(fp)) + break; + + *LineBuf = '\0'; + fgets(LineBuf,127,fp); + + if (*LineBuf == ';') + continue; + + StripEndOfLine(LineBuf); + SkipSpaces(LineBuf); + + if (!strlen(LineBuf)) + continue; + + printf("."); + + if (!stricmp(LineBuf,"WALLS:")) + { + bType = TYPE_WALL; + Mode = 1; + continue; + } + + if (!stricmp(LineBuf,"ENDWALLS:")) + { + if (Mode != 1) + { + printf("Invalid place for command: %s.\n",LineBuf); + result = -1; + } + + Mode = 0; + continue; + } + + if (!stricmp(LineBuf,"OBJECTS:")) + { + bType = TYPE_OBJECT; + Mode = 2; + continue; + } + + if (!stricmp(LineBuf,"FILES:")) + { + fMode = 1; + continue; + } + + if (!stricmp(LineBuf,"ENDFILES:")) + { + fMode = 0; + continue; + } + + if (!strnicmp(LineBuf,"PALFILE:",8)) + { + strcpy(PalFile,SkipSpaces(&LineBuf[8])); + continue; + } + + if (!strnicmp(LineBuf,"MAPFILE:",8)) + { + strcpy(GridFile,SkipSpaces(&LineBuf[8])); + continue; + } + + if (Mode == 2) + { + if (!strnicmp(LineBuf,"NUMBER:",7)) + { + value = atoi(&LineBuf[7]); + + if (value < 1 || value >= 255) + { + printf("Invalid object number:\n%s\n",LineBuf); + result = -1; + break; + } + ObjIndex = value; + continue; + } + + if (!strnicmp(LineBuf,"BITMAPS:",8)) + { + strcpy(LineBuf,SkipSpaces(&LineBuf[8])); + value = 0; + strcpy(LineBuf,CopyToComma(fBuf,LineBuf)); + SkipSpaces(fBuf); + bNum = atoi(fBuf); + + if (bNum < 1 || bNum > 255) + { + printf("Invalid bitmap number for object: %d\n",ObjIndex); + result = -1; + break; + } + + ObjbmNum[ObjIndex] = bNum; + continue; + } + } + + if (fMode) + { + value = atoi(LineBuf); + if (value < 1 || value > 255) + { + printf("Invalid number for object: %s.\n",LineBuf); + result = -1; + continue; + } + + s = strpbrk(LineBuf,", \t"); + if (s == NULL) + { + printf("Unable to locate bitmap name for object: %s.\n",LineBuf); + result = -1; + continue; + } + + strcpy(fBuf,SkipSpaces(s)); + AddExtent(fBuf,".img"); + + if (LoadBitmap(value,fBuf,bType)) + { + printf("Error loading bitmap \"%s\".\n",fBuf); + result = -1; + } + continue; + } + + } + +fclose(fp); + +printf("done\n"); + +return(result); +} + +/**************************************************************************** +** ** +****************************************************************************/ +short LoadGrid(void) +{ + short handle; + +handle = open(GridFile,O_RDWR|O_BINARY); +if (handle < 1) + { + printf("Unable to open MapFile: %s\n",GridFile); + return(-1); + } + +if (read(handle,MapGrid,8192) != 8192) + { + close(handle); + printf("Error reading MapFile: %s\n",GridFile); + return(-1); + } + +if (read(handle,ObjGrid,8192) != 8192) + { + close(handle); + printf("Error reading MapFile: %s\n",GridFile); + return(-1); + } + +read(handle,FloorGrid,8192); +read(handle,CeilGrid,8192); + +close(handle); +return(0); +} + + +/**************************************************************************** +** ** +****************************************************************************/ +short SaveGrid(void) +{ + short handle; + +handle = open(GridFile,O_RDWR|O_BINARY|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE); +if (handle < 1) + { + return(-1); + } + +if (write(handle,MapGrid,8192) != 8192) + { + close(handle); + return(-2); + } + +if (write(handle,ObjGrid,8192) != 8192) + { + close(handle); + return(-2); + } + +write(handle,FloorGrid,8192); +write(handle,CeilGrid,8192); + +close(handle); +ModifiedFlag = 0; +GeneralSelectBox(MapSavedBox,0); +return(0); +} + + + +/**************************************************************************** +** ** +****************************************************************************/ +short LoadPalette(char *pName) +{ + short handle; + +handle = open(pName,O_RDWR|O_BINARY); +if (handle < 1) + { + printf("Unable to open PalFile: %s\n",pName); + ErrorCode = ERR_BADPALFILE; + return(-1); + } + +if (read(handle,Palette,768) != 768) + { + close(handle); + printf("Error reading PalFile: %s\n",pName); + ErrorCode = ERR_BADPALFILE; + return(-1); + } + +close(handle); +return(0); +} + +/**************************************************************************** +** ** +****************************************************************************/ +void FillBorder(void) +{ + short row,col; + UINT offset; + +offset = 0; +for (col = 0; col < 64; col++) + MapGrid[col] = CurrentCode; + +for (row = 0; row < 64; row++) + { + MapGrid[offset] = CurrentCode; + MapGrid[offset+63] = CurrentCode; + offset += 64; + } + +offset = 64 * 63; +for (col = 0; col < 64; col++) + MapGrid[offset++] = CurrentCode; + +ShowGrid(); + +} + + +/**************************************************************************** +** ** +****************************************************************************/ +short main(short argc,char *argv[]) +{ + short done,mx,my,mbutton,lastx,lasty,index; + short i; + unsigned short key; + UCHAR color; + char *s; + +if (MouseInstalled() != -1) + { + puts("Mouse required"); + exit(1); + } + +if (LoadSmallFont()) + { + puts("Unable to load font file"); + exit(1); + } + +if (argc < 2) + { + printf("ACK-3D Map Editor Version 1.0\n"); + printf("Usage:\n"); + printf(" medit ascfile.ext\n"); + printf(" where:\n"); + printf(" ascfile.ext is the name of the ASCII file that contains\n"); + printf(" wall and object bitmap filenames.\n"); + exit(1); + } + +if (LoadDescFile(argv[1])) + { + printf("\nError reading ASCII file - ErrorCode = %d\n",ErrorCode); + exit(1); + } + +if (LoadGrid()) + { + printf("\nError loading map file - ErrorCode = %d\n",ErrorCode); + exit(1); + } + +if (LoadPalette(PalFile)) + { + printf("\nError loading palette file - ErrorCode = %d\n",ErrorCode); + exit(1); + } + +SetVGAmode(); + +CurrentGrid = &MapGrid[0]; +GridFlag = 0; + +LoadAndShowScreen(); + +//SetPalette2(&Palette[16 * 3]); +SetPalette2(Palette,256); + +WallFlags = 0; +ShowHotspotCheck(17,SCREEN_COLOR); +ShowHotspotCheck(18,SCREEN_COLOR); + +GridX = GridY = 0; +CurrentType = TYPE_WALL; +LastWallCode = LastObjCode = CurrentCode = 1; + +ShowMouse(); +mbutton = ReadMouseCursor(&my,&mx); +lastx = mx; +lasty = my; + +ShowCoords(lastx,lasty); + +ShowGrid(); +ShowCurrentCode(); + +//smWriteString(4,194,"Press spacebar to select square options"); +s = GetExtent(argv[1]); +smWriteString(82,166,&s[1]); + +smWriteString(82,178,"Map "); +done = 0; + +while (!done) + { + key = inkey(); + if (key == 0x11B) + break; + + if (key == 0x3200) + { + CurrentGrid = &MapGrid[0]; + GridFlag = 0; + ShowGrid(); + smWriteString(82,178,"Map "); + } + + if (key == 0x2100) + { + CurrentGrid = &FloorGrid[0]; + GridFlag = 1; + ShowGrid(); + smWriteString(82,178,"Floor "); + } + + if (key == 0x2E00) + { + CurrentGrid = &CeilGrid[0]; + GridFlag = 2; + ShowGrid(); + smWriteString(82,178,"Ceiling"); + } + + mbutton = ReadMouseCursor(&my,&mx); + + if (lastx != mx || lasty != my) + { + lastx = mx; + lasty = my; + ShowCoords(lastx,lasty); + } + + if (key == 0x3920 && !GridFlag) + { + if (mx > 1 && mx < 183 && my > 1 && my < 147) + { + GetSpecialCode(mx,my); + SetMouseCursor(my,mx); + } + else + SoundBeep(); + } + + + if (key == 0x3000 && !GridFlag) + { + if (GeneralSelectBox(BorderBox,1) == 1) + FillBorder(); + } + + if (mbutton & 2) + PutCode(mx,my,0); + + + if (mbutton & 1) + { + index = GetAction(mx,my); + + switch (index) + { + + case 0: + PutCode(mx,my,CurrentCode); + if (CurrentType == TYPE_OBJECT) + MouseReleased(); + + if (CurrentCode == DOOR_YCODE || CurrentCode == DOOR_XCODE) + { + GetSpecialCode(mx,my); + SetMouseCursor(my,mx); + } + + break; + + case 1: /* Map Up arrow */ + if (GridY) + { + GridY--; + ShowGrid(); + ShowGridCoords(); + ShowCoords(mx,my); + } + break; + + case 2: /* Map Dn arrow */ + if (GridY < (GRID_HEIGHT - 18)) + { + GridY++; + ShowGrid(); + ShowGridCoords(); + ShowCoords(mx,my); + } + break; + + + case 3: /* Map Rt arrow */ + if (GridX < (GRID_WIDTH - 18)) + { + GridX++; + ShowGrid(); + ShowGridCoords(); + ShowCoords(mx,my); + } + break; + + case 4: /* Map Lt arrow */ + if (GridX) + { + GridX--; + ShowGrid(); + ShowGridCoords(); + ShowCoords(mx,my); + } + break; + + case 5: /* Bitmap Up arrow */ + CurrentCode -= 1; + if (CurrentType == TYPE_WALL) + { + CurrentCode &= 0xFF; + LastWallCode = CurrentCode; + } + else + { + if (CurrentCode < 0) + CurrentCode = MAX_OBJECTS - 1; + LastObjCode = CurrentCode; + } + + ShowCurrentCode(); + delay(200); + break; + + case 6: /* Bitmap Dn arrow */ + CurrentCode += 1; + if (CurrentType == TYPE_WALL) + { + CurrentCode &= 0xFF; + LastWallCode = CurrentCode; + } + else + { + if (CurrentCode >= MAX_OBJECTS) + CurrentCode = 0; + LastObjCode = CurrentCode; + } + ShowCurrentCode(); + delay(200); + break; + + case 7: /* Show Bitmap Group */ + ShowBitmapGroup(); + if (CurrentType == TYPE_WALL) + LastWallCode = CurrentCode; + else + LastObjCode = CurrentCode; + + break; + + case 8: /* Wall button */ + CurrentType = TYPE_WALL; + CurrentCode = LastWallCode; + ShowCurrentCode(); + MouseReleased(); + break; + + case 9: /* Object button */ + CurrentType = TYPE_OBJECT; + CurrentCode = LastObjCode; + ShowCurrentCode(); + MouseReleased(); + break; + + + case 10: /* Fill */ + if (GeneralSelectBox(FillBox,1) == 2) + break; + + switch (GridFlag) + { + case 0: + for (i = 0; i < GRID_MAX; i++) + { + CurrentGrid[i] = CurrentCode; + ObjGrid[i] = 0; + } + break; + + case 1: + for (i = 0; i < GRID_MAX; i++) + { + if (!MapGrid[i] || (MapGrid[i] & GRID_FLOOR_FLAGS)) + FloorGrid[i] = CurrentCode; + else + FloorGrid[i] = MapGrid[i] & 0xFF; + } + break; + + case 2: + for (i = 0; i < GRID_MAX; i++) + { + if (!MapGrid[i] || (MapGrid[i] & GRID_FLOOR_FLAGS)) + CeilGrid[i] = CurrentCode; + else + CeilGrid[i] = MapGrid[i] & 0xFF; + } + break; + + default: + break; + } + + ModifiedFlag = 1; + GridX = GridY = 0; + ShowGrid(); + ShowGridCoords(); + ShowCoords(mx,my); + break; + + case 11: /* Clear */ + if (GeneralSelectBox(ClsBox,1) == 2) + break; + + if (!GridFlag) + { + for (i = 0; i < GRID_MAX; i++) + { + CurrentGrid[i] = 0; + ObjGrid[i] = 0; + } + } + else + { + if (GridFlag == 1) + { + for (i = 0; i < GRID_MAX; i++) + FloorGrid[i] = 0; + } + if (GridFlag == 2) + { + for (i = 0; i < GRID_MAX; i++) + CeilGrid[i] = 0; + } + } + + ModifiedFlag = 1; + GridX = GridY = 0; + ShowGrid(); + ShowGridCoords(); + ShowCoords(mx,my); + break; + + case 12: /* Save */ + + if (!access(GridFile,0)) + { + if (GeneralSelectBox(OverwriteBox,1) == 2) + break; + } + + SaveGrid(); + break; + + case 13: /* Load */ + if (ModifiedFlag) + { + if (GeneralSelectBox(LoadBox,1) == 2) + break; + } + + if (!LoadGrid()) + { + ModifiedFlag = 0; + GridX = GridY = 0; + CurrentType = TYPE_WALL; + CurrentCode = 1; + ShowGrid(); + ShowCurrentCode(); + } + else + SoundBeep(); + break; + + case 14: /* Exit */ + done = 1; + break; + + case 15: /* Horiz door */ + CurrentCode = DOOR_YCODE; + ShowCurrentCode(); + MouseReleased(); + break; + + case 16: + CurrentCode = DOOR_XCODE; + ShowCurrentCode(); + MouseReleased(); + break; + + case 17: /* Trans toggle */ + WallFlags ^= WALL_TYPE_TRANS; + color = SCREEN_COLOR; + if (WallFlags & WALL_TYPE_TRANS) + color = BLACK; + ShowHotspotCheck(17,color); + MouseReleased(); + break; + + case 18: /* Multi toggle */ + WallFlags ^= WALL_TYPE_MULTI; + color = SCREEN_COLOR; + if (WallFlags & WALL_TYPE_MULTI) + color = BLACK; + ShowHotspotCheck(18,color); + MouseReleased(); + break; + + case 19: /* Show Floors */ + CurrentGrid = &FloorGrid[0]; + GridFlag = 1; + ShowGrid(); + smWriteString(82,178,"Floor "); + MouseReleased(); + break; + + case 20: /* Show Ceiling */ + CurrentGrid = &CeilGrid[0]; + GridFlag = 2; + ShowGrid(); + smWriteString(82,178,"Ceiling"); + MouseReleased(); + break; + + case 21: /* Show Map */ + CurrentGrid = &MapGrid[0]; + GridFlag = 0; + ShowGrid(); + smWriteString(82,178,"Map "); + MouseReleased(); + break; + + + default: + break; + } + } + + } + + +if (ModifiedFlag) + { + if (GeneralSelectBox(SaveBox,1) == 1) + SaveGrid(); + } + +SetTextMode(); + +return(0); +} + diff --git a/map_edit/medit.dtf b/map_edit/medit.dtf new file mode 100644 index 0000000..126e21b Binary files /dev/null and b/map_edit/medit.dtf differ diff --git a/map_edit/mgif.c b/map_edit/mgif.c new file mode 100644 index 0000000..5cfb18e --- /dev/null +++ b/map_edit/mgif.c @@ -0,0 +1,296 @@ +/***************************************************************************** +MGIF.C + + +#include + + Routine to load a 256 color .GIF file into a memory buffer. *Only* 256 + color images are supported here! Sorry, no routines to SAVE .GIFs... + Memory required is allocated on the fly. + + Mark Morley + morley@camosun.bc.ca + + Modified for use in the ACK environment by Lary Myers + +*****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "ack3d.h" +#include "ackeng.h" + +#define MAX_CODES 4096 + +extern unsigned char colordat[]; // Palette buffer in AckReadiff module +extern short rsHandle; +extern short ErrorCode; + +static FILE* fp; +static short curr_size; +static short clear; +static short ending; +static short newcodes; +static short top_slot; +static short slot; +static short navail_bytes = 0; +static short nbits_left = 0; +static unsigned char b1; +static unsigned char byte_buff[257]; +static unsigned char* pbytes; +static unsigned char* stack; +static unsigned char* suffix; +static unsigned short* prefix; + +static unsigned long rbaTable[10]; + +static unsigned long code_mask[13] = +{ + 0L, + 0x0001L, 0x0003L, + 0x0007L, 0x000FL, + 0x001FL, 0x003FL, + 0x007FL, 0x00FFL, + 0x01FFL, 0x03FFL, + 0x07FFL, 0x0FFFL +}; + +//============================================================================= +// +//============================================================================= +static short get_next_code(void) +{ + short i; + static unsigned long ret; + +if (!nbits_left) + { + if (navail_bytes <= 0) + { + pbytes = byte_buff; + navail_bytes = getc(fp); + + if (navail_bytes) + { + for (i = 0; i < navail_bytes; ++i ) + *(byte_buff + i) = getc( fp ); + } + } + b1 = *pbytes++; + nbits_left = 8; + --navail_bytes; + } + +ret = b1 >> (8 - nbits_left); +while (curr_size > nbits_left) + { + if (navail_bytes <= 0) + { + pbytes = byte_buff; + navail_bytes = getc(fp); + if (navail_bytes) + { + for( i = 0; i < navail_bytes; ++i ) + *(byte_buff + i) = getc( fp ); + } + } + b1 = *pbytes++; + ret |= b1 << nbits_left; + nbits_left += 8; + --navail_bytes; + } + +nbits_left -= curr_size; + +return((short)(ret & *(code_mask + curr_size))); +} + + +//============================================================================= +// +//============================================================================= +unsigned char *AckReadgif(char *picname) +{ + unsigned char *sp; + unsigned char *buffer,*OrgBuffer; + short code, fc, oc; + short i; + unsigned char size; + short c; + unsigned short wt,ht; + int bSize; + unsigned char buf[1028]; + unsigned char red; + unsigned char grn; + unsigned char blu; + + +if (!rsHandle) + { + fp = fopen(picname,"rb"); + if( !fp ) + { + ErrorCode = ERR_BADFILE; + return(NULL); + } + } +else + { + fp = fdopen(rsHandle,"rb"); + if (fp == NULL) + { + ErrorCode = ERR_BADPICNAME; + return(0L); + } + + fseek(fp,rbaTable[(ULONG)picname],SEEK_SET); + } + +fread(buf,1,6,fp); +if( strncmp( buf, "GIF", 3 ) ) + { + if (!rsHandle) + fclose(fp); + + ErrorCode = ERR_INVALIDFORM; + return(NULL); + } + +fread(buf,1,7,fp); +for (i = 0; i < 768;) + { + red = getc(fp); + grn = getc(fp); + blu = getc(fp); + colordat[i++] = red >> 2; + colordat[i++] = grn >> 2; + colordat[i++] = blu >> 2; + } + +fread(buf,1,5,fp); +fread(buf,1,2,fp); +wt = (*(short *)buf); +fread(buf,1,2,fp); +ht = (*(short *)buf); +//wt = getw(fp); +//ht = getw(fp); +bSize = (ht * wt) + (sizeof(short) * 2); +buffer = (UCHAR *)malloc(bSize); +if (buffer == NULL) + { + if (!rsHandle) + fclose(fp); + + ErrorCode = ERR_NOMEMORY; + return(NULL); + } + +OrgBuffer = buffer; + +(*(short *)buffer) = wt; +buffer += sizeof(short); +(*(short *)buffer) = ht; +buffer += sizeof(short); + +fread(buf,1,1,fp); +size = getc(fp); + +if (size < 2 || 9 < size) + { + if (!rsHandle) + fclose(fp); + free(OrgBuffer); + ErrorCode = ERR_INVALIDFORM; + return(NULL); + } + +stack = (unsigned char *) malloc(MAX_CODES + 1); +suffix = (unsigned char *) malloc(MAX_CODES + 1); +prefix = (unsigned short *) malloc(sizeof(short) * (MAX_CODES + 1)); + +if (stack == NULL || suffix == NULL || prefix == NULL) + { + if (!rsHandle) + fclose(fp); + free(OrgBuffer); + ErrorCode = ERR_NOMEMORY; + return(NULL); + } + +curr_size = size + 1; +top_slot = 1 << curr_size; +clear = 1 << size; +ending = clear + 1; +slot = newcodes = ending + 1; +navail_bytes = nbits_left = 0; +oc = fc = 0; +sp = stack; + +while ( (c = get_next_code()) != ending ) + { + if (c == clear) + { + curr_size = size + 1; + slot = newcodes; + top_slot = 1 << curr_size; + while ( (c = get_next_code()) == clear ); + + if( c == ending ) + break; + + if( c >= slot ) + c = 0; + + oc = fc = c; + *buffer++ = c; + } + else + { + code = c; + if (code >= slot) + { + code = oc; + *sp++ = fc; + } + + while (code >= newcodes) + { + *sp++ = *(suffix + code); + code = *(prefix + code); + } + + *sp++ = code; + if (slot < top_slot) + { + *(suffix + slot) = fc = code; + *(prefix + slot++) = oc; + oc = c; + } + + if (slot >= top_slot && curr_size < 12) + { + top_slot <<= 1; + ++curr_size; + } + + while (sp > stack) + { + --sp; + *buffer++ = *sp; + } + } + } + +free(stack); +free(suffix); +free(prefix); + +if (!rsHandle) + fclose(fp); + +return(OrgBuffer); +} diff --git a/map_edit/miff.c b/map_edit/miff.c new file mode 100644 index 0000000..eb845de --- /dev/null +++ b/map_edit/miff.c @@ -0,0 +1,250 @@ +/******************* ( Animation Construction Kit 3D ) ***********************/ +/* Deluxe Paint file reader */ +/* CopyRight (c) 1993 Authors: Jaimi McEntire, Lary Myers */ +/*****************************************************************************/ +// +// This function will return a pointer to a buffer that holds the raw image. +// just free the pointer to delete this buffer. After returning, the array +// colordat will hold the adjusted palette of this pic. +// +// Also, this has been modified to only read in form PBM brushes. form ILBM's +// (the "old" type) are not supported. use the "new" deluxe paint .lbm type +// and do not choose "old". + +#include +#include +#include +#include +#include +#include +#include +#include "ack3d.h" +#include "ackeng.h" +#include "iff.h" + + extern int ErrorCode; + +unsigned char colordat[768]; /* maximum it can be...256 colors */ + +unsigned char cplanes[8][80]; /* setting max at 640 pixels width */ + /* thats 8 pixels per byte per plane */ +unsigned char *pplanes= (char far *) &cplanes[0][0]; /* for a form pbm */ + +#define MAX_BUF_POS 4096 + + int rdbufpos; + int rdSize; + UCHAR rdBuffer[MAX_BUF_POS+2]; + +//============================================================================= +// +//============================================================================= +short ReadNxtBlock(short handle) +{ + short retlen; + +retlen = read(handle,rdBuffer,MAX_BUF_POS); +rdbufpos = 0; + +return(retlen); +} + +//============================================================================= +// +//============================================================================= +int aRead(short handle,void *dest,int size) +{ + int count = 0; + UCHAR *d = (UCHAR *)dest; + +while (size--) + { + if (rdbufpos >= MAX_BUF_POS) + { + if (rdSize != MAX_BUF_POS) + { + return(count); + } + + rdSize = read(handle,rdBuffer,MAX_BUF_POS); + rdbufpos = 0; + } + + d[count++] = rdBuffer[rdbufpos++]; + } + +return(count); +} + + +//============================================================================= +// +//============================================================================= +unsigned char *Readiff(char *picname) + { + FILE *pic; + short handle; + form_chunk fchunk; + ChunkHeader chunk; + BitMapHeader bmhd; + long length; + char value; // must remain signed, no matter what. ignore any warnings. + short sofar; + short width,height,planes; + short pixw; + unsigned char *destx, *savedestx; + + rdbufpos = MAX_BUF_POS + 1; + rdSize = MAX_BUF_POS; + + if ((pic = fopen(picname,"rb")) == NULL) + { + ErrorCode = ERR_BADPICNAME; + return(0L); + } + fread(&fchunk,1,sizeof(form_chunk),pic); /* read in the first 12 bytes*/ +// aRead(pic,&fchunk,sizeof(form_chunk)); + + if (fchunk.type != FORM) + { + fclose(pic); + ErrorCode = ERR_INVALIDFORM; + return(0L); + } + + if (fchunk.subtype != ID_PBM) + { + printf("Error: Not form PBM!"); + fclose(pic); + ErrorCode = ERR_NOPBM; + return(0L); + } + // now lets loop...Because the Chunks can be in any order! + while(1) + { + fread(&chunk,1,sizeof(ChunkHeader),pic); +// aRead(pic,&chunk,sizeof(ChunkHeader)); + chunk.ckSize = ByteFlipLong(chunk.ckSize); + if (chunk.ckSize & 1) chunk.ckSize ++; // must be word aligned + if(chunk.ckID == ID_BMHD) + { + fread(&bmhd,1,sizeof(BitMapHeader),pic); +// aRead(pic,&bmhd,sizeof(BitMapHeader)); + bmhd.w=iffswab(bmhd.w); // the only things we need. + bmhd.h=iffswab(bmhd.h); + destx = (unsigned char *)malloc((bmhd.w * bmhd.h)+4); + if ( !destx ) + { + fclose(pic); + ErrorCode = ERR_NOMEMORY; + return(0L); + } + + savedestx = destx; + + destx[0] = bmhd.w%256; + destx[1] = bmhd.w/256; + destx[2] = bmhd.h%256; + destx[3] = bmhd.h/256; + destx += 4; + continue; + } + if(chunk.ckID == ID_CMAP) + { + short i; + unsigned char r,g; + + fread(colordat,1,chunk.ckSize,pic); +// aRead(pic,colordat,chunk.ckSize); + for (i=0;i<768;i++) + { + r = colordat[i]; // r,g do not stand for red and green + g = r >> 2; + colordat[i] = g; + } + continue; + } + if(chunk.ckID == ID_BODY) + { + for(height = 0; height 0) + { + short len; + len = value +1; + sofar -= len; + if(!(fread(dest,len,1,pic))) + // if(!(aRead(pic,dest,len))) + { + fclose(pic); + ErrorCode = ERR_BADPICFILE; + free(savedestx); + return(0L); + } + dest +=len; + } + else + { + short count; + count = -value; /* get amount to dup */ + count ++; + sofar -= count; + value=fgetc(pic); + // aRead(pic,&value,1); + while (--count >= 0) *dest++ = value; + } + } + else + { + fread(dest,sofar,1,pic); /* just throw on plane */ +// aRead(pic,dest,sofar); /* just throw on plane */ + sofar = 0; + } + } + if (sofar < 0) + { + fclose(pic); + } + _fmemcpy(destx,pplanes,bmhd.w); + destx += bmhd.w; + } + break; /* leave if we've unpacked the BODY*/ + } + + fseek(pic,chunk.ckSize,SEEK_CUR); + } + + fclose(pic); + return((char *)savedestx); + } + +long ByteFlipLong(long NUMBER) + { + // Hey, I didn;t write this function!!! + long Y, T; + short I; + + T = NUMBER; + Y=0;for (I=0;I<4;I++){Y = Y | (T & 0xFF);if (I<3) {Y = Y << 8;T = T >> 8;}} + return(Y); + } + +short iffswab(unsigned short number) + { + unsigned short xx1,xx2; + unsigned short result; + + xx1 = number <<8; xx2 = number >>8; result = xx1|xx2; + return(result); + } diff --git a/map_edit/mkdtf.bat b/map_edit/mkdtf.bat new file mode 100644 index 0000000..ed97840 --- /dev/null +++ b/map_edit/mkdtf.bat @@ -0,0 +1 @@ +bpic m1files.dat medit.dtf diff --git a/map_edit/mouse.c b/map_edit/mouse.c new file mode 100644 index 0000000..6460ace --- /dev/null +++ b/map_edit/mouse.c @@ -0,0 +1,160 @@ +// 3D Construction Kit +// Started: 01/02/94 +// Author: Lary Myers +// Module: MOUSE.C +// (c) CopyRight 1994 All Rights Reserved + +#include +#include +#include + + int MouseModifier = 2; + +//============================================================================= +// Check if mouse is installed, returns -1 if it IS installed +//============================================================================= +int MouseInstalled(void) +{ + int yesno; + union REGPACK regs; + +memset(®s,0,sizeof(union REGPACK)); +intr(0x33,®s); +yesno = regs.w.ax; + +return(yesno); +} + +//============================================================================= +// Show the mouse cursor +//============================================================================= +void ShowMouse(void) +{ + union REGPACK regs; + +memset(®s,0,sizeof(union REGPACK)); +regs.w.ax = 1; +intr(0x33,®s); + +} + +//============================================================================= +// Hide the mouse cursor +//============================================================================= +void HideMouse(void) +{ + union REGPACK regs; + +memset(®s,0,sizeof(union REGPACK)); +regs.w.ax = 2; +intr(0x33,®s); + +} + +//============================================================================= +// Returns button status, mouse row and column +//============================================================================= +int ReadMouseCursor(int *mrow,int *mcol) +{ + int bstatus; + union REGPACK regs; + +memset(®s,0,sizeof(union REGPACK)); +regs.w.ax = 3; +intr(0x33,®s); +bstatus = regs.w.bx; +*mrow = regs.w.dx; +*mcol = regs.w.cx / MouseModifier; + +return(bstatus); +} + +//============================================================================= +// Returns just the mouse button status +//============================================================================= +int ReadMouseButtons(void) +{ + int bstatus; + union REGPACK regs; + +memset(®s,0,sizeof(union REGPACK)); +regs.w.ax = 3; +intr(0x33,®s); +bstatus = regs.w.bx; + +return(bstatus); +} + +//============================================================================= +// Set mouse cursor to desired row and column +//============================================================================= +void SetMouseCursor(int mrow,int mcol) +{ + union REGPACK regs; + +memset(®s,0,sizeof(union REGPACK)); +regs.w.ax = 4; +regs.w.dx = mrow; +regs.w.cx = mcol * MouseModifier; +intr(0x33,®s); + +} + +//============================================================================= +// Defines left and right columns for mouse travel +//============================================================================= +void SetMouseMinMaxColumns(int mincol,int maxcol) +{ + union REGPACK regs; + +memset(®s,0,sizeof(union REGPACK)); +regs.w.ax = 7; +regs.w.cx = mincol * MouseModifier; +regs.w.dx = maxcol * MouseModifier; +intr(0x33,®s); + +} + + +//============================================================================= +// Defines top and bottom rows for mouse travel +//============================================================================= +void SetMouseMinMaxRows(int minrow,int maxrow) +{ + union REGPACK regs; + +memset(®s,0,sizeof(union REGPACK)); +regs.w.ax = 8; +regs.w.cx = minrow; +regs.w.dx = maxrow; +intr(0x33,®s); + +} + +//============================================================================= +// Set shape of mouse cursor. 8 byte mask, hotspot row,col +//============================================================================= +void SetMouseShape(int hsrow,int hscol,char far *mask) +{ + union REGPACK regs; + +memset(®s,0,sizeof(union REGPACK)); +regs.w.ax = 9; +regs.w.dx = FP_OFF(mask); +regs.w.es = FP_SEG(mask); +regs.w.bx = hscol; +regs.w.cx = hsrow; +intr(0x33,®s); + +} + +//============================================================================= +// Wait for the mouse button to be released +//============================================================================= +void MouseReleased(void) +{ + +while (ReadMouseButtons()); + +} + diff --git a/map_edit/prologue.mac b/map_edit/prologue.mac new file mode 100644 index 0000000..9b94a7f --- /dev/null +++ b/map_edit/prologue.mac @@ -0,0 +1,44 @@ +P386 + + +Macro SETUPSEGMENT + +SEGMENT _TEXT PARA PUBLIC 'CODE' + ASSUME CS:_TEXT + + Endm + +macro PENTER STORAGE +;; 17 - Enter a procedue with storage space +;; Procedure enter, uses the 286/386 ENTER opcode + push ebp + mov ebp,esp + IF STORAGE + sub esp,STORAGE + ENDIF +ENDIF + endm + +macro PLEAVE +;; 18 - Exit a procedure with stack correction. + mov esp,ebp + pop ebp + endm + +macro PushCREGS +;; 19 - Save registers for C + push es + push ds ;The Kernel is responsible for maintaining DS + push esi + push edi + cld + endm + +macro PopCREGS +;; 20 - Restore registers for C + pop edi + pop esi + pop ds ;The Kernel is responsible for maintaining DS + pop es + endm + diff --git a/map_edit/slime1a.bbm b/map_edit/slime1a.bbm new file mode 100644 index 0000000..ac2e477 Binary files /dev/null and b/map_edit/slime1a.bbm differ diff --git a/map_edit/spfont.bbm b/map_edit/spfont.bbm new file mode 100644 index 0000000..8c85e0f Binary files /dev/null and b/map_edit/spfont.bbm differ