| 1 |
IMPLEMENTATION MODULE DrawL ; |
| 2 |
|
| 3 |
|
| 4 |
FROM ASCII IMPORT lf, bs ; |
| 5 |
FROM Window IMPORT Clip, ClipPoint ; |
| 6 |
FROM StrIO IMPORT WriteString, WriteLn ; |
| 7 |
FROM NumberIO IMPORT WriteCard ; |
| 8 |
FROM StdIO IMPORT Write ; |
| 9 |
FROM Debug IMPORT Halt ; |
| 10 |
FROM Assertion IMPORT Assert ; |
| 11 |
|
| 12 |
FROM AdvMap IMPORT Rooms, DoorStatus, Line, Room, Door, Treasure ; |
| 13 |
|
| 14 |
FROM AdvMath IMPORT MaxNoOfTreasures ; |
| 15 |
|
| 16 |
FROM AdvSystem IMPORT Player, PlayerNo, |
| 17 |
IsPlayerActive, |
| 18 |
NextFreePlayer, |
| 19 |
GetAccessToScreen, |
| 20 |
ReleaseAccessToScreen, |
| 21 |
GetAccessToScreenNo, |
| 22 |
ReleaseAccessToScreenNo, |
| 23 |
GetWriteAccessToPlayer, |
| 24 |
ReleaseWriteAccessToPlayer, |
| 25 |
GetReadAccessToPlayer, |
| 26 |
ReleaseReadAccessToPlayer, |
| 27 |
GetReadAccessToDoor, |
| 28 |
ReleaseReadAccessToDoor, |
| 29 |
GetReadAccessToTreasure, |
| 30 |
ReleaseReadAccessToTreasure ; |
| 31 |
|
| 32 |
|
| 33 |
(* Draws the current Room that the callers player is in. It also draws *) |
| 34 |
(* all treasures, doors and players associated with this room. This *) |
| 35 |
(* procedure DOES get access to treasure locks and door locks but NO *) |
| 36 |
(* player lock is used. *) |
| 37 |
(* This procedure does NOT draw SECRET doors as might give them away! *) |
| 38 |
(* It is assumed that walls cover ALL doors. *) |
| 39 |
|
| 40 |
PROCEDURE DrawRoom ; |
| 41 |
VAR |
| 42 |
ok : BOOLEAN ; |
| 43 |
hx, hy, |
| 44 |
x1, y1, x2, y2, |
| 45 |
p, t, r, i, |
| 46 |
Sx, Sy : CARDINAL ; |
| 47 |
ds : DoorStatus ; |
| 48 |
BEGIN |
| 49 |
p := PlayerNo() ; |
| 50 |
WITH Player[p] DO |
| 51 |
|
| 52 |
r := RoomOfMan ; |
| 53 |
Sx := ScreenX ; |
| 54 |
Sy := ScreenY ; |
| 55 |
t := Rooms[r].NoOfWalls ; |
| 56 |
FOR i := 1 TO t DO |
| 57 |
WITH Rooms[r].Walls[i] DO |
| 58 |
x1 := X1 ; |
| 59 |
y1 := Y1 ; |
| 60 |
x2 := X2 ; |
| 61 |
y2 := Y2 |
| 62 |
END ; |
| 63 |
Clip( x1, y1, x2, y2, Sx, Sy, ok ) ; |
| 64 |
|
| 65 |
IF ok |
| 66 |
THEN |
| 67 |
GetAccessToScreen ; |
| 68 |
WLine(x1, y1, x2, y2) ; |
| 69 |
ReleaseAccessToScreen |
| 70 |
END |
| 71 |
END ; |
| 72 |
|
| 73 |
GetReadAccessToDoor ; |
| 74 |
t := Rooms[r].NoOfDoors ; |
| 75 |
FOR i := 1 TO t DO |
| 76 |
WITH Rooms[r].Doors[i] DO |
| 77 |
x1 := Position.X1 ; |
| 78 |
y1 := Position.Y1 ; |
| 79 |
x2 := Position.X2 ; |
| 80 |
y2 := Position.Y2 ; |
| 81 |
ds := StateOfDoor ; |
| 82 |
IF ds#Secret |
| 83 |
THEN |
| 84 |
Clip( x1, y1, x2, y2, Sx, Sy, ok ) ; |
| 85 |
IF ok |
| 86 |
THEN |
| 87 |
GetAccessToScreen ; |
| 88 |
IF Position.X1=Position.X2 |
| 89 |
THEN |
| 90 |
hx := Position.X2 ; |
| 91 |
hy := Position.Y2 ; |
| 92 |
Assert((ScreenX=Sx) AND (ScreenY=Sy)) ; |
| 93 |
ClipPoint(hx, hy, ScreenX, ScreenY, ok) ; |
| 94 |
DLine(x1, y1, x2, y2, ok, ds) |
| 95 |
ELSE |
| 96 |
hx := Position.X1 ; |
| 97 |
hy := Position.Y1 ; |
| 98 |
Assert((ScreenX=Sx) AND (ScreenY=Sy)) ; |
| 99 |
ClipPoint(hx, hy, ScreenX, ScreenY, ok) ; |
| 100 |
DLine(x1, y1, x2, y2, ok, ds) |
| 101 |
END ; |
| 102 |
ReleaseAccessToScreen |
| 103 |
END |
| 104 |
END |
| 105 |
END |
| 106 |
END ; |
| 107 |
ReleaseReadAccessToDoor ; |
| 108 |
|
| 109 |
GetReadAccessToTreasure ; |
| 110 |
FOR i := 1 TO MaxNoOfTreasures DO |
| 111 |
WITH Rooms[r] DO |
| 112 |
IF i IN Treasures |
| 113 |
THEN |
| 114 |
x1 := Treasure[i].Xpos ; |
| 115 |
y1 := Treasure[i].Ypos ; |
| 116 |
ClipPoint(x1, y1, ScreenX, ScreenY, ok) ; |
| 117 |
IF ok |
| 118 |
THEN |
| 119 |
GetAccessToScreen ; |
| 120 |
DTreasure(x1, y1) ; |
| 121 |
ReleaseAccessToScreen |
| 122 |
END |
| 123 |
END |
| 124 |
END |
| 125 |
END ; |
| 126 |
ReleaseReadAccessToTreasure ; |
| 127 |
END ; |
| 128 |
|
| 129 |
(* This called routine must now draw the other players as well *) |
| 130 |
(* as drawing the current man. *) |
| 131 |
(* Assumes that this player has been updated in Data Structure *) |
| 132 |
(* but has not yet been displayed on the screen. *) |
| 133 |
|
| 134 |
DrawAllPlayers ; |
| 135 |
|
| 136 |
END DrawRoom ; |
| 137 |
|
| 138 |
|
| 139 |
(* Draw all players uses no player lock. *) |
| 140 |
|
| 141 |
PROCEDURE DrawAllPlayers ; |
| 142 |
VAR |
| 143 |
pn, |
| 144 |
Sx, Sy, dir, p: CARDINAL ; |
| 145 |
x, y, r : CARDINAL ; |
| 146 |
ok : BOOLEAN ; |
| 147 |
ch : CHAR ; |
| 148 |
BEGIN |
| 149 |
p := PlayerNo() ; |
| 150 |
WITH Player[p] DO |
| 151 |
Sx := ScreenX ; |
| 152 |
Sy := ScreenY ; |
| 153 |
r := RoomOfMan ; |
| 154 |
dir := Direction ; |
| 155 |
x := Xman-Sx ; |
| 156 |
y := Yman-Sy ; |
| 157 |
GetAccessToScreenNo(p) ; |
| 158 |
DrawMan(FALSE, x, y, dir) ; |
| 159 |
ReleaseAccessToScreenNo(p) |
| 160 |
END ; |
| 161 |
|
| 162 |
(* Now write all the other Players on the screen *) |
| 163 |
|
| 164 |
FOR pn := 0 TO NextFreePlayer-1 DO |
| 165 |
IF (pn#p) AND IsPlayerActive(pn) |
| 166 |
THEN |
| 167 |
WITH Player[pn] DO |
| 168 |
IF r=RoomOfMan |
| 169 |
THEN |
| 170 |
x := Xman ; |
| 171 |
y := Yman ; |
| 172 |
dir := Direction ; |
| 173 |
ClipPoint(x, y, Sx, Sy, ok) ; |
| 174 |
IF ok |
| 175 |
THEN |
| 176 |
GetAccessToScreenNo( p ) ; |
| 177 |
DrawMan(TRUE, x, y, dir) ; |
| 178 |
ReleaseAccessToScreenNo( p ) |
| 179 |
END |
| 180 |
END |
| 181 |
END |
| 182 |
END |
| 183 |
END |
| 184 |
END DrawAllPlayers ; |
| 185 |
|
| 186 |
|
| 187 |
(* This procedure uses no player lock. *) |
| 188 |
|
| 189 |
PROCEDURE EraseAllPlayers ; |
| 190 |
VAR |
| 191 |
pn, |
| 192 |
Sx, Sy, p: CARDINAL ; |
| 193 |
x, y, r : CARDINAL ; |
| 194 |
ok : BOOLEAN ; |
| 195 |
BEGIN |
| 196 |
p := PlayerNo() ; |
| 197 |
WITH Player[p] DO |
| 198 |
Sx := ScreenX ; |
| 199 |
Sy := ScreenY ; |
| 200 |
r := RoomOfMan ; |
| 201 |
x := Xman-Sx ; |
| 202 |
y := Yman-Sy ; |
| 203 |
GetAccessToScreenNo(p) ; |
| 204 |
Erase(x, y) ; |
| 205 |
ReleaseAccessToScreenNo(p) |
| 206 |
END ; |
| 207 |
|
| 208 |
(* Now write all the other Players on the screen *) |
| 209 |
|
| 210 |
FOR pn := 0 TO NextFreePlayer-1 DO |
| 211 |
IF (pn#p) AND IsPlayerActive(pn) |
| 212 |
THEN |
| 213 |
WITH Player[pn] DO |
| 214 |
IF r=RoomOfMan |
| 215 |
THEN |
| 216 |
x := Xman ; |
| 217 |
y := Yman ; |
| 218 |
ClipPoint(x, y, Sx, Sy, ok) ; |
| 219 |
IF ok |
| 220 |
THEN |
| 221 |
GetAccessToScreenNo(p) ; |
| 222 |
Erase(x, y) ; |
| 223 |
ReleaseAccessToScreenNo(p) |
| 224 |
END |
| 225 |
END |
| 226 |
END |
| 227 |
END |
| 228 |
END |
| 229 |
END EraseAllPlayers ; |
| 230 |
|
| 231 |
|
| 232 |
(* Clears the Room specified of all treasures and all OTHER players. *) |
| 233 |
(* It uses NO lock on any Player. But uses Treasure Lock. *) |
| 234 |
|
| 235 |
PROCEDURE ClearRoom (r: CARDINAL) ; |
| 236 |
VAR |
| 237 |
p, Sx, Sy, |
| 238 |
x, y, pn, |
| 239 |
x1, y1, i: CARDINAL ; |
| 240 |
ok : BOOLEAN ; |
| 241 |
BEGIN |
| 242 |
p := PlayerNo() ; |
| 243 |
WITH Player[p] DO |
| 244 |
Sx := ScreenX ; |
| 245 |
Sy := ScreenY ; |
| 246 |
GetReadAccessToTreasure ; |
| 247 |
FOR i := 1 TO MaxNoOfTreasures DO |
| 248 |
WITH Rooms[r] DO |
| 249 |
IF i IN Treasures |
| 250 |
THEN |
| 251 |
x1 := Treasure[i].Xpos ; |
| 252 |
y1 := Treasure[i].Ypos ; |
| 253 |
ClipPoint(x1, y1, Sx, Sy, ok) ; |
| 254 |
IF ok |
| 255 |
THEN |
| 256 |
GetAccessToScreenNo(p) ; |
| 257 |
Erase(x1, y1) ; |
| 258 |
ReleaseAccessToScreenNo(p) |
| 259 |
END |
| 260 |
END |
| 261 |
END |
| 262 |
END ; |
| 263 |
ReleaseReadAccessToTreasure |
| 264 |
END ; |
| 265 |
|
| 266 |
(* Now erase all the other Players on the screen *) |
| 267 |
|
| 268 |
FOR pn := 0 TO NextFreePlayer-1 DO |
| 269 |
IF p#pn |
| 270 |
THEN |
| 271 |
WITH Player[pn] DO |
| 272 |
IF r=RoomOfMan |
| 273 |
THEN |
| 274 |
x := Xman ; |
| 275 |
y := Yman ; |
| 276 |
ClipPoint(x, y, Sx, Sy, ok) ; |
| 277 |
IF ok |
| 278 |
THEN |
| 279 |
GetAccessToScreenNo(p) ; |
| 280 |
Erase(x, y) ; |
| 281 |
ReleaseAccessToScreenNo(p) |
| 282 |
END |
| 283 |
END |
| 284 |
END |
| 285 |
END |
| 286 |
END |
| 287 |
END ClearRoom ; |
| 288 |
|
| 289 |
|
| 290 |
PROCEDURE StrLine (a: ARRAY OF CHAR; x1, y1, x2, y2: CARDINAL) ; |
| 291 |
BEGIN |
| 292 |
WriteString(a) ; Write(' ') ; |
| 293 |
WriteCard(x1, 0) ; Write(' ') ; |
| 294 |
WriteCard(y1, 0) ; Write(' ') ; |
| 295 |
WriteCard(x2, 0) ; Write(' ') ; |
| 296 |
WriteCard(y2, 0) ; WriteLn |
| 297 |
END StrLine ; |
| 298 |
|
| 299 |
|
| 300 |
PROCEDURE WLine (x1, y1, x2, y2: CARDINAL) ; |
| 301 |
BEGIN |
| 302 |
IF y1=y2 |
| 303 |
THEN |
| 304 |
StrLine('hwall', x1, y1, x2, y2) |
| 305 |
ELSE |
| 306 |
Assert(x1=x2) ; |
| 307 |
StrLine('vwall', x1, y1, x2, y2) |
| 308 |
END |
| 309 |
END WLine ; |
| 310 |
|
| 311 |
|
| 312 |
PROCEDURE DLine (x1, y1, x2, y2: CARDINAL; hinge: BOOLEAN; ds: DoorStatus) ; |
| 313 |
VAR |
| 314 |
x, ys: CARDINAL ; |
| 315 |
BEGIN |
| 316 |
IF y1=y2 |
| 317 |
THEN |
| 318 |
CASE ds OF |
| 319 |
|
| 320 |
Closed: IF hinge |
| 321 |
THEN |
| 322 |
WriteString('hhinge ') ; WriteCard(x1, 0) ; Write(' ') ; WriteCard(y1, 0) ; WriteLn ; |
| 323 |
INC(x1) |
| 324 |
END ; |
| 325 |
IF x1<=x2 |
| 326 |
THEN |
| 327 |
StrLine('hdoor', x1, y1, x2, y2) |
| 328 |
END | |
| 329 |
Open : StrLine('eL', x1, y1, x2, y2) | |
| 330 |
Secret: WLine(x1, y1, x2, y2) |
| 331 |
|
| 332 |
END |
| 333 |
ELSE |
| 334 |
CASE ds OF |
| 335 |
|
| 336 |
Closed: IF hinge |
| 337 |
THEN |
| 338 |
WriteString('vhinge ') ; WriteCard(x1, 0) ; Write(' ') ; WriteCard(y2, 0) ; WriteLn ; |
| 339 |
DEC(y2) |
| 340 |
END ; |
| 341 |
IF y1<=y2 |
| 342 |
THEN |
| 343 |
StrLine('vdoor', x1, y1, x2, y2) |
| 344 |
END | |
| 345 |
Open : StrLine('eL', x1, y1, x2, y2) | |
| 346 |
Secret: WLine(x1, y1, x2, y2) |
| 347 |
|
| 348 |
END |
| 349 |
END |
| 350 |
END DLine ; |
| 351 |
|
| 352 |
|
| 353 |
PROCEDURE StrPoint (a: ARRAY OF CHAR; x, y: CARDINAL) ; |
| 354 |
BEGIN |
| 355 |
WriteString(a) ; Write(' ') ; |
| 356 |
WriteCard(x, 0) ; Write(' ') ; |
| 357 |
WriteCard(y, 0) ; WriteLn |
| 358 |
END StrPoint ; |
| 359 |
|
| 360 |
|
| 361 |
PROCEDURE DTreasure (x, y: CARDINAL) ; |
| 362 |
BEGIN |
| 363 |
StrPoint('treasure', x, y) |
| 364 |
END DTreasure ; |
| 365 |
|
| 366 |
|
| 367 |
PROCEDURE Erase (x, y: CARDINAL) ; |
| 368 |
BEGIN |
| 369 |
StrPoint('eL', x, y) |
| 370 |
END Erase ; |
| 371 |
|
| 372 |
|
| 373 |
PROCEDURE DrawMan (other: BOOLEAN; x, y, dir: CARDINAL) ; |
| 374 |
BEGIN |
| 375 |
IF other |
| 376 |
THEN |
| 377 |
CASE dir OF |
| 378 |
|
| 379 |
0: StrPoint('Nman', x, y) | |
| 380 |
1: StrPoint('Wman', x, y) | |
| 381 |
2: StrPoint('Sman', x, y) | |
| 382 |
3: StrPoint('Eman', x, y) |
| 383 |
|
| 384 |
ELSE |
| 385 |
Halt ('unexpected direction', __FILE__, __FUNCTION__, __LINE__) |
| 386 |
END |
| 387 |
ELSE |
| 388 |
CASE dir OF |
| 389 |
|
| 390 |
0: StrPoint('nman', x, y) | |
| 391 |
1: StrPoint('wman', x, y) | |
| 392 |
2: StrPoint('sman', x, y) | |
| 393 |
3: StrPoint('eman', x, y) |
| 394 |
|
| 395 |
ELSE |
| 396 |
Halt ('unexpected direction', __FILE__, __FUNCTION__, __LINE__) |
| 397 |
END |
| 398 |
END |
| 399 |
END DrawMan ; |
| 400 |
|
| 401 |
|
| 402 |
PROCEDURE DArrow (x, y, dir: CARDINAL) ; |
| 403 |
BEGIN |
| 404 |
CASE dir OF |
| 405 |
|
| 406 |
0: StrPoint('nar', x, y) | |
| 407 |
1: StrPoint('war', x, y) | |
| 408 |
2: StrPoint('sar', x, y) | |
| 409 |
3: StrPoint('ear', x, y) |
| 410 |
|
| 411 |
ELSE |
| 412 |
Halt ('unexpected direction', __FILE__, __FUNCTION__, __LINE__) |
| 413 |
END |
| 414 |
END DArrow ; |
| 415 |
|
| 416 |
|
| 417 |
END DrawL. |
| 418 |
(* |
| 419 |
* Local variables: |
| 420 |
* compile-command: "make" |
| 421 |
* End: |
| 422 |
*) |