home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 1
/
GoldFishApril1994_CD2.img
/
d4xx
/
d488
/
lordofhosts
/
lohsrc.lzh
/
openclose.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-05-10
|
10KB
|
282 lines
/* LORD OF HOSTS - openclose.c --- Öffnen und Schließen von Libs - Fenster... */
#include "Lord.h"
struct MsgPort *MPort;
struct IOStdReq *IOReq;
ULONG JoyMouseData;
struct Screen *MyScreen;
struct Window *MyWindow;
struct RastPort *RP;
struct ViewPort *VP;
struct BitMap *BM,PiecesBM;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct ReqLib *ReqBase;
struct TextFont *MyFont;
struct Process *MyProcess;
APTR OldErrorWindow;
extern struct FileRequester MyFileReqStruct;
UWORD MyColorMap[16] = {
0x006,0xFFF,0xE00,0x800,0xF77,0xFCA,0xD61,0xFFF,
0xF91,0x46F,0xFC0,0x0F0,0x333,0x222,0x555,0x000
};
struct TextAttr TheFont =
{
(UBYTE *)"topaz.font",
TOPAZ_EIGHTY,
FS_NORMAL,
FPF_ROMFONT
};
struct NewScreen TheScreen =
{
0, 0, 320, 200, 4,
0, 1, NULL,
CUSTOMSCREEN|SCREENBEHIND,
&TheFont,
(UBYTE *)"LORD OF HOSTS © 1991 Tim Pietzcker",
NULL,NULL
};
struct NewWindow TheWindow =
{
0, 0, 320, 200, 0, 1,
MOUSEBUTTONS|MENUPICK,
ACTIVATE|SMART_REFRESH|BACKDROP|BORDERLESS,
NULL, NULL, NULL, NULL, NULL,
0, 0, 0, 0,
CUSTOMSCREEN
};
/* Menü Special */
#define M_SUBW1 (8*4 + LOWCHECKWIDTH)
#define M_SUBW2 (8*18 + LOWCHECKWIDTH)
#define M_WIDTH3 (8*23 + LOWCOMMWIDTH)
struct IntuiText on_t =
{ 0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"On", NULL};
struct IntuiText off_t =
{ 0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Off", NULL};
struct IntuiText nohelp_t =
{ 0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"No Help", NULL};
struct IntuiText showknown_t =
{ 0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Show Known Values", NULL};
struct IntuiText showall_t =
{ 0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Show All Values", NULL};
struct IntuiText explain_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Explain Invalid Move", NULL};
struct IntuiText switch_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Switch Sides", NULL};
struct IntuiText setspeed_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Set JoyMouse Speed...", NULL};
struct IntuiText joymouse_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"JoyMouse", NULL};
struct IntuiText mode2_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Player 2 Help Mode", NULL};
struct IntuiText mode1_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Player 1 Help Mode", NULL};
struct IntuiText redo_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Redo", NULL};
struct IntuiText undo_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Undo", NULL};
/* MenuSubItems */
struct MenuItem off_m =
{ NULL, 69, 10, M_SUBW1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
0x0001, (APTR)&off_t, NULL, NULL, NULL, NULL };
struct MenuItem on_m =
{ &off_m, 69, 0, M_SUBW1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT|CHECKED,
0x0002, (APTR)&on_t, NULL, NULL, NULL, NULL };
struct MenuItem showall1_m =
{ NULL, 69, 20, M_SUBW2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
0x0003, (APTR)&showall_t, NULL, NULL, NULL, NULL };
struct MenuItem showknown1_m =
{ &showall1_m, 69, 10, M_SUBW2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
0x0005, (APTR)&showknown_t, NULL, NULL, NULL, NULL };
struct MenuItem nohelp1_m =
{ &showknown1_m, 69, 0, M_SUBW2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT|
CHECKED, 0x0006, (APTR)&nohelp_t, NULL, NULL, NULL, NULL };
struct MenuItem showall2_m =
{ NULL, 69, 20, M_SUBW2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
0x0003, (APTR)&showall_t, NULL, NULL, NULL, NULL };
struct MenuItem showknown2_m =
{ &showall2_m, 69, 10, M_SUBW2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
0x0005, (APTR)&showknown_t, NULL, NULL, NULL, NULL };
struct MenuItem nohelp2_m =
{ &showknown2_m, 69, 0, M_SUBW2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT|
CHECKED, 0x0006, (APTR)&nohelp_t, NULL, NULL, NULL, NULL };
/* MenuItems */
struct MenuItem explain_m =
{ NULL, 0, 70, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
(APTR)&explain_t, NULL, (BYTE)'E', NULL, NULL };
struct MenuItem switch_m =
{ &explain_m, 0, 60, M_WIDTH3, 10, ITEMTEXT|HIGHCOMP, NULL,
(APTR)&switch_t, NULL, NULL, NULL, NULL };
struct MenuItem setspeed_m =
{ &switch_m, 0, 50, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
(APTR)&setspeed_t, NULL, (BYTE)'J', NULL, NULL };
struct MenuItem joymouse_m =
{ &setspeed_m, 0, 40, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHBOX, NULL,
(APTR)&joymouse_t, NULL, NULL, &on_m, NULL };
struct MenuItem mode2_m =
{ &joymouse_m, 0, 30, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHBOX, NULL,
(APTR)&mode2_t, NULL, NULL, &nohelp2_m, NULL };
struct MenuItem mode1_m =
{ &mode2_m, 0, 20, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHBOX, NULL,
(APTR)&mode1_t, NULL, NULL, &nohelp1_m, NULL };
struct MenuItem redo_m =
{ &mode1_m, 0, 10, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
(APTR)&redo_t, NULL, (BYTE)'R', NULL, NULL };
struct MenuItem undo_m =
{ &redo_m, 0, 0, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
(APTR)&undo_t, NULL, (BYTE)'U', NULL, NULL };
/* Menü Board */
#define M_WIDTH2 (8*21 + LOWCHECKWIDTH)
struct IntuiText rnd2_t =
{ 0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Unbalanced Random", NULL};
struct IntuiText rnd1_t =
{ 0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Balanced Random", NULL};
struct IntuiText std2_t =
{ 0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Standard Rotated 90°", NULL};
struct IntuiText std1_t =
{ 0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Standard", NULL};
/* MenuItems */
struct MenuItem rnd2_m =
{ NULL, 0, 30, M_WIDTH2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
0x0007, (APTR)&rnd2_t, NULL, NULL, NULL, NULL };
struct MenuItem rnd1_m =
{ &rnd2_m, 0, 20, M_WIDTH2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
0x000B, (APTR)&rnd1_t, NULL, NULL, NULL, NULL };
struct MenuItem std2_m =
{ &rnd1_m, 0, 10, M_WIDTH2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
0x000D, (APTR)&std2_t, NULL, NULL, NULL, NULL };
struct MenuItem std1_m =
{ &std2_m, 0, 0, M_WIDTH2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKED|CHECKIT,
0x000E, (APTR)&std1_t, NULL, NULL, NULL, NULL };
/* Menü Game */
#define M_WIDTH1 (8*14 + LOWCOMMWIDTH)
struct IntuiText quit_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Quit", NULL};
struct IntuiText about_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"About", NULL};
struct IntuiText rules_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Rules...", NULL};
struct IntuiText save_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Save Game...", NULL};
struct IntuiText load_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Load Game...", NULL};
struct IntuiText begin_t =
{ 0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Begin Game", NULL};
/* MenuItems */
struct MenuItem quit_m =
{ NULL, 0, 50, M_WIDTH1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
(APTR)&quit_t, NULL, (BYTE)'Q', NULL, NULL };
struct MenuItem about_m =
{ &quit_m, 0, 40, M_WIDTH1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
(APTR)&about_t, NULL, (BYTE)'A', NULL, NULL };
struct MenuItem rules_m =
{ &about_m, 0, 30, M_WIDTH1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
(APTR)&rules_t, NULL, (BYTE)'?', NULL, NULL };
struct MenuItem save_m =
{ &rules_m, 0, 20, M_WIDTH1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
(APTR)&save_t, NULL, (BYTE)'S', NULL, NULL };
struct MenuItem load_m =
{ &save_m, 0, 10, M_WIDTH1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
(APTR)&load_t, NULL, (BYTE)'L', NULL, NULL };
struct MenuItem begin_m =
{ &load_m, 0, 0, M_WIDTH1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
(APTR)&begin_t, NULL, (BYTE)'B', NULL, NULL };
/* Gesamt (Haupt-) Menü */
struct Menu special_m =
{ NULL, 4*21, 0, 4*16, 10, MENUENABLED, (BYTE *)"Special", &undo_m };
struct Menu board_m =
{ &special_m, 4*10-1, 0, 4*11+1, 10, MENUENABLED, (BYTE *)"Board", &std1_m };
struct Menu game_m =
{ &board_m, 2, 0, 4*9+1, 10, MENUENABLED, (BYTE *)"Game", &begin_m };
void errorstop(char *message)
{
puts(message);
Delay(100);
close_all();
}
void open_all(void)
{
int i,j; long sec,mic;
if (!(IntuitionBase = OpenLibrary("intuition.library",0)))
errorstop("No intuition.library!");
if (!(GfxBase = OpenLibrary("graphics.library",0)))
errorstop("No graphics.library!");
if (!(ReqBase = OpenLibrary("req.library",0)))
errorstop("No req.library!\n Either copy the supplied req.library to"
" your LIBS: directory or\n Assign LIBS: \"\" before running"
" Lord Of Hosts!");
if (!(MPort = CreatePort("Shogun Port",0))) errorstop("No Message Port!");
if (!(IOReq = CreateStdIO(MPort))) errorstop("No StdIORequest!");
if (OpenDevice("input.device",0,(struct IORequest *)IOReq,0))
errorstop("No input.device!");
JoyMouseData=SPEED;
if (!(MyScreen = OpenScreen(&TheScreen))) errorstop("No Screen!");
VP = &(MyScreen->ViewPort);
TheWindow.Screen = MyScreen;
if (!(MyWindow = OpenWindow(&TheWindow))) errorstop("No Window!");
RP = MyWindow->RPort;
BM = RP->BitMap; /* BitMap, in der die Spielsteine bewegt werden */
InitBitMap(&PiecesBM,4,21,21); /* 4 Planes, 21*21 Pixel */
for (i=0;i<4;++i)
if (!(PiecesBM.Planes[i]=AllocRaster(21,21)))
errorstop("No BitMap Memory!");
LoadRGB4(VP,MyColorMap,16);
if (!(MyFont = OpenFont(&TheFont))) errorstop("No font topaz.8!");
SetFont(RP,MyFont);
CurrentTime(&sec,&mic); /* Zufallsgenerator setzen */
srand((unsigned int)sec);
SetMenuStrip(MyWindow, &game_m);
MyProcess = (struct Process *)FindTask(NULL);
OldErrorWindow = MyProcess->pr_WindowPtr;
MyProcess->pr_WindowPtr = (APTR)MyWindow;
}
void close_all(void)
{
int i;
if (ReqBase) PurgeFiles(&MyFileReqStruct); /* Speicher vom Filerequester */
if (MyFont) CloseFont(MyFont);
for (i=0;i<4;++i)
if (PiecesBM.Planes[i])
FreeRaster(PiecesBM.Planes[i],21,21);
if (MyWindow)
{
MyProcess->pr_WindowPtr = OldErrorWindow;
ClearMenuStrip(MyWindow);
CloseWindow(MyWindow);
}
if (MyScreen) CloseScreen(MyScreen);
if (IOReq)
{
CloseDevice((struct IORequest *)IOReq);
DeleteStdIO(IOReq);
}
if (MPort) DeletePort(MPort);
if (ReqBase) CloseLibrary(ReqBase);
if (GfxBase) CloseLibrary(GfxBase);
if (IntuitionBase) CloseLibrary(IntuitionBase);
exit(0);
}