| 1 |
(* Copyright (C) 2003 |
| 2 |
Free Software Foundation, Inc. *) |
| 3 |
(* This file is part of GNU Modula-2. |
| 4 |
|
| 5 |
GNU Modula-2 is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License as published by the Free |
| 7 |
Software Foundation; either version 2, or (at your option) any later |
| 8 |
version. |
| 9 |
|
| 10 |
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 |
for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License along |
| 16 |
with gm2; see the file COPYING. If not, write to the Free Software |
| 17 |
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) |
| 18 |
|
| 19 |
IMPLEMENTATION MODULE AdvIntroduction ; |
| 20 |
|
| 21 |
FROM SYSTEM IMPORT ADR, SIZE ; |
| 22 |
FROM ASCII IMPORT lf, cr, nul ; |
| 23 |
FROM StrLib IMPORT StrLen ; |
| 24 |
FROM SocketControl IMPORT nonBlocking, ignoreSignals ; |
| 25 |
|
| 26 |
FROM Executive IMPORT WaitForIO, InitProcess, InitSemaphore, Wait, Signal, Resume, |
| 27 |
Suspend, DESCRIPTOR, SEMAPHORE, KillProcess ; |
| 28 |
|
| 29 |
FROM RTint IMPORT InitInputVector ; |
| 30 |
FROM COROUTINES IMPORT PROTECTION ; |
| 31 |
FROM sckt IMPORT tcpServerState, tcpServerEstablish, tcpServerAccept, tcpServerSocketFd ; |
| 32 |
FROM libc IMPORT printf, read, write ; |
| 33 |
FROM AdvUtil IMPORT Positioning, TestIfLastLivePlayer ; |
| 34 |
|
| 35 |
FROM AdvSystem IMPORT Player, TypeOfDeath, StartPlayer, PlayerNo, |
| 36 |
ClientRead, DefaultWrite, UnAssign, |
| 37 |
ReadString, GetReadAccessToPlayer, |
| 38 |
ReleaseReadAccessToPlayer, |
| 39 |
GetAccessToScreen, ReleaseAccessToScreen ; |
| 40 |
|
| 41 |
FROM AdvTreasure IMPORT DisplayEnemy, Grenade ; |
| 42 |
FROM AdvUtil IMPORT InitialDisplay ; |
| 43 |
FROM AdvCmd IMPORT ExecuteCommand ; |
| 44 |
FROM Screen IMPORT WriteCommand, ClearScreen, WriteString, PromptString, Pause, Quit ; |
| 45 |
FROM AdvSound IMPORT EnterGame ; |
| 46 |
FROM StdIO IMPORT PushOutput ; |
| 47 |
|
| 48 |
|
| 49 |
CONST |
| 50 |
Meg = 1024*1024 ; |
| 51 |
StackSize = 30 * Meg ; |
| 52 |
|
| 53 |
VAR |
| 54 |
ToBeTaken: SEMAPHORE ; |
| 55 |
NextFd : INTEGER ; |
| 56 |
|
| 57 |
|
| 58 |
PROCEDURE theServer ; |
| 59 |
VAR |
| 60 |
fd: INTEGER ; |
| 61 |
v : CARDINAL ; |
| 62 |
ch: CHAR ; |
| 63 |
r : INTEGER ; |
| 64 |
BEGIN |
| 65 |
fd := NextFd ; |
| 66 |
Signal(ToBeTaken) ; |
| 67 |
v := InitInputVector(fd, MAX(PROTECTION)) ; |
| 68 |
r := printf("inside `theServer' using fd=%d\n", fd); |
| 69 |
StartPlayer(fd) ; |
| 70 |
Copyleft ; |
| 71 |
Title ; |
| 72 |
Knight ; |
| 73 |
WITH Player[PlayerNo()] DO |
| 74 |
fd := -1 ; |
| 75 |
PlayerProcess := NIL ; |
| 76 |
END ; |
| 77 |
UnAssign ; |
| 78 |
KillProcess |
| 79 |
END theServer ; |
| 80 |
|
| 81 |
|
| 82 |
PROCEDURE StartGame ; |
| 83 |
VAR |
| 84 |
r : INTEGER ; |
| 85 |
v : CARDINAL ; |
| 86 |
fd : INTEGER ; |
| 87 |
s : tcpServerState ; |
| 88 |
g, p: DESCRIPTOR ; |
| 89 |
BEGIN |
| 90 |
ignoreSignals ; |
| 91 |
PushOutput(DefaultWrite) ; |
| 92 |
g := Resume(InitProcess(Grenade, StackSize, 'grenade')) ; |
| 93 |
s := tcpServerEstablish() ; |
| 94 |
ToBeTaken := InitSemaphore(1, 'ToBeTaken') ; |
| 95 |
v := InitInputVector(tcpServerSocketFd(s), MAX(PROTECTION)) ; |
| 96 |
LOOP |
| 97 |
r := printf("before WaitForIO\n"); |
| 98 |
WaitForIO(v) ; |
| 99 |
fd := tcpServerAccept(s) ; |
| 100 |
r := nonBlocking(fd) ; |
| 101 |
r := printf("before InitProcess\n"); |
| 102 |
p := InitProcess(theServer, StackSize, 'theServer') ; |
| 103 |
NextFd := fd ; |
| 104 |
r := printf("before Resume\n"); |
| 105 |
p := Resume(p) ; |
| 106 |
Wait(ToBeTaken) |
| 107 |
END |
| 108 |
END StartGame ; |
| 109 |
|
| 110 |
|
| 111 |
PROCEDURE Knight ; |
| 112 |
VAR |
| 113 |
Dead: BOOLEAN ; |
| 114 |
ch : CHAR ; |
| 115 |
p : CARDINAL ; |
| 116 |
BEGIN |
| 117 |
EquipKnight ; |
| 118 |
SetUpKnight ; |
| 119 |
InitialDisplay ; |
| 120 |
p := PlayerNo() ; |
| 121 |
EnterGame(p) ; |
| 122 |
Dead := FALSE ; |
| 123 |
REPEAT |
| 124 |
IF ClientRead(ch) |
| 125 |
THEN |
| 126 |
WriteCommand(p, ch) ; |
| 127 |
ExecuteCommand(ch, Dead) |
| 128 |
ELSE |
| 129 |
Dead := TRUE |
| 130 |
END |
| 131 |
UNTIL Dead ; |
| 132 |
GiveResults |
| 133 |
END Knight ; |
| 134 |
|
| 135 |
|
| 136 |
PROCEDURE Copyleft ; |
| 137 |
VAR |
| 138 |
p: CARDINAL ; |
| 139 |
BEGIN |
| 140 |
p := PlayerNo() ; |
| 141 |
ClearScreen(p) ; |
| 142 |
WriteString(p, 'Written whilst on holiday during the rainy months of\n') ; |
| 143 |
WriteString(p, 'August 85, August 86 and ported to GNU/linux during July/August 2005\n\n') ; |
| 144 |
WriteString(p, '\n') ; |
| 145 |
WriteString(p, 'A multiplayer game inspired by two single player Commodore PET\n') ; |
| 146 |
WriteString(p, 'game of circa 1979 (Morloc Tower and Temple of Apshai)\n') ; |
| 147 |
WriteString(p, '\n') ; |
| 148 |
WriteString(p, 'This game is rather different (similar key commands) and\n') ; |
| 149 |
WriteString(p, 'in retrospect a very very poor persons multiplayer doom!\n') ; |
| 150 |
Pause(p) |
| 151 |
END Copyleft ; |
| 152 |
|
| 153 |
|
| 154 |
PROCEDURE Title ; |
| 155 |
VAR |
| 156 |
p: CARDINAL ; |
| 157 |
BEGIN |
| 158 |
p := PlayerNo() ; |
| 159 |
ClearScreen(p) ; |
| 160 |
WriteString(p, '...set in a time of long ago, when life hast no value and\n') ; |
| 161 |
WriteString(p, ' death sometimes, hadst a price. Thou needst to be quick\n') ; |
| 162 |
WriteString(p, ' with thy sword and fast with thy bow, for only the best\n') ; |
| 163 |
WriteString(p, ' survived...\n\n\n') |
| 164 |
END Title ; |
| 165 |
|
| 166 |
|
| 167 |
PROCEDURE EquipKnight ; |
| 168 |
VAR |
| 169 |
p: CARDINAL ; |
| 170 |
BEGIN |
| 171 |
p := PlayerNo() ; |
| 172 |
PromptString(p, 'What is thy name? ') ; |
| 173 |
WITH Player[PlayerNo()] DO |
| 174 |
ReadString(ManName) |
| 175 |
END ; |
| 176 |
WriteString(p, '\n') |
| 177 |
END EquipKnight ; |
| 178 |
|
| 179 |
|
| 180 |
PROCEDURE SetUpKnight ; |
| 181 |
BEGIN |
| 182 |
WITH Player[PlayerNo()] DO |
| 183 |
NoOfMagic := 1 ; |
| 184 |
NoOfNormal := 7 |
| 185 |
END ; |
| 186 |
Positioning |
| 187 |
END SetUpKnight ; |
| 188 |
|
| 189 |
|
| 190 |
PROCEDURE GiveResults ; |
| 191 |
VAR |
| 192 |
yes: BOOLEAN ; |
| 193 |
p : CARDINAL ; |
| 194 |
BEGIN |
| 195 |
p := PlayerNo() ; |
| 196 |
Pause(p) ; |
| 197 |
GetReadAccessToPlayer ; |
| 198 |
GetAccessToScreen ; |
| 199 |
ClearScreen(p) ; |
| 200 |
WITH Player[p] DO |
| 201 |
IF Wounds=0 |
| 202 |
THEN |
| 203 |
WriteString(p, 'Thou art slain...') ; |
| 204 |
GiveDescriptionOfDeath(p, DeathType) |
| 205 |
ELSE |
| 206 |
TestIfLastLivePlayer(yes) ; |
| 207 |
IF yes |
| 208 |
THEN |
| 209 |
WriteString(p, 'Thou art the conqueror of the dungeon') |
| 210 |
ELSE |
| 211 |
WriteString(p, 'Thou art the coward of the dungeon') |
| 212 |
END ; |
| 213 |
Wounds := 0 |
| 214 |
END ; |
| 215 |
WriteString(p, '\n\n\n') |
| 216 |
END ; |
| 217 |
ReleaseAccessToScreen ; |
| 218 |
ReleaseReadAccessToPlayer ; |
| 219 |
Pause(p) ; |
| 220 |
Quit(p) |
| 221 |
END GiveResults ; |
| 222 |
|
| 223 |
|
| 224 |
PROCEDURE GiveDescriptionOfDeath (p: CARDINAL; Dt: TypeOfDeath) ; |
| 225 |
BEGIN |
| 226 |
WriteString(p, '\n\n\n\nThou expired from life after :\n\n') ; |
| 227 |
CASE Dt OF |
| 228 |
|
| 229 |
sword : WriteString(p, 'being slain with a sword') | |
| 230 |
magicarrow : WriteString(p, 'being pierced by a magic arrow') | |
| 231 |
fireball : WriteString(p, 'thou wast struck by a fireball burning thy body fatally') | |
| 232 |
normalarrow : WriteString(p, 'thou wast struck a deadly blow caused by an arrow') | |
| 233 |
explosion : WriteString(p, 'having thy guts blown all over the dungeon') | |
| 234 |
exitdungeon : WriteString(p, 'thou crawlest out of the dungeon and expired') |
| 235 |
|
| 236 |
END |
| 237 |
END GiveDescriptionOfDeath ; |
| 238 |
|
| 239 |
|
| 240 |
(* Monitor allows a dead player to look around the dungeon unaffecting *) |
| 241 |
(* the current game. *) |
| 242 |
|
| 243 |
PROCEDURE Monitor ; |
| 244 |
VAR |
| 245 |
p : CARDINAL ; |
| 246 |
ch: CHAR ; |
| 247 |
BEGIN |
| 248 |
p := PlayerNo() ; |
| 249 |
REPEAT |
| 250 |
ClearScreen(p) ; |
| 251 |
WriteString(p, 'Monitor --- Look at other players\n\n\n\n') ; |
| 252 |
WriteString(p, 'Commands:\n') ; |
| 253 |
WriteString(p, '1) Look at other players\n') ; |
| 254 |
WriteString(p, '2) Exit\n\n') ; |
| 255 |
WriteString(p, 'Option:') ; |
| 256 |
IF ClientRead(ch) |
| 257 |
THEN |
| 258 |
DefaultWrite(ch) ; |
| 259 |
IF ch='1' |
| 260 |
THEN |
| 261 |
DisplayEnemy |
| 262 |
END |
| 263 |
ELSE |
| 264 |
RETURN |
| 265 |
END |
| 266 |
UNTIL ch='2' |
| 267 |
END Monitor ; |
| 268 |
|
| 269 |
|
| 270 |
END AdvIntroduction. |
| 271 |
(* |
| 272 |
* Local variables: |
| 273 |
* compile-command: "make" |
| 274 |
* End: |
| 275 |
*) |