2020-02-02 23:33:07 +00:00
|
|
|
( M A P )
|
|
|
|
var tileselect
|
|
|
|
: invalidate-map mapsize mapsize! ;
|
|
|
|
: mouseworldpos mousepos scrollpos +pos ;
|
|
|
|
: mousetile mouseworldpos world>tile ;
|
|
|
|
: tile ( x y -- ptr ) mapsize drop * + map + ;
|
|
|
|
|
|
|
|
1 const WALKABLE
|
|
|
|
2 const NEUTABLE
|
2020-02-18 01:43:14 +00:00
|
|
|
4 const RUBBLE
|
2020-04-02 23:11:01 +00:00
|
|
|
8 const ENTITY
|
2020-02-02 23:33:07 +00:00
|
|
|
|
|
|
|
array tileflags
|
2020-02-22 03:38:32 +00:00
|
|
|
( 0: sky ) 0 b,
|
|
|
|
( 1: cloud ) 0 b,
|
|
|
|
( 2: wall ) NEUTABLE b,
|
|
|
|
( 3: carpet ) WALKABLE b,
|
2020-04-02 23:11:01 +00:00
|
|
|
( 4: comp-off ) ENTITY b,
|
|
|
|
( 5: comp-on ) NEUTABLE ENTITY | b,
|
2020-02-22 03:38:32 +00:00
|
|
|
( 6: table ) 0 b,
|
|
|
|
( 7: chair ) 0 b,
|
|
|
|
( 8: table-brok ) RUBBLE b,
|
2020-04-02 23:11:01 +00:00
|
|
|
( 9: door-close ) ENTITY b,
|
|
|
|
( 10:door-open ) WALKABLE ENTITY | b,
|
|
|
|
( 11:switch-off ) NEUTABLE ENTITY | b,
|
|
|
|
( 12:switch-on ) NEUTABLE ENTITY | b,
|
2020-02-22 03:38:32 +00:00
|
|
|
( 13:window ) 0 b,
|
|
|
|
( 14:chair-brok ) RUBBLE b,
|
|
|
|
( 15:bookcase ) 0 b,
|
|
|
|
( 16:bookcase-broke ) RUBBLE b,
|
2020-04-19 02:12:57 +00:00
|
|
|
( 17:scattered books ) WALKABLE b, ( don't want rexx to explode books )
|
2020-02-22 03:38:32 +00:00
|
|
|
( 18:plant ) 0 b,
|
|
|
|
( 19:tipped plant ) RUBBLE b,
|
2020-04-02 23:11:01 +00:00
|
|
|
( 20:scanner-off ) NEUTABLE ENTITY | b,
|
|
|
|
( 21:scanner-on ) NEUTABLE ENTITY | b,
|
2020-02-22 03:38:32 +00:00
|
|
|
( 22:cracked-wall ) 0 b,
|
2020-04-02 23:11:01 +00:00
|
|
|
( 23:rexx-pod ) NEUTABLE ENTITY | b,
|
|
|
|
( 24:keypad-off ) NEUTABLE ENTITY | b,
|
|
|
|
( 25:keypad-on ) NEUTABLE ENTITY | b,
|
2020-02-02 23:33:07 +00:00
|
|
|
|
|
|
|
here tileflags - 1 - const MAXTILE
|
|
|
|
|
2020-03-07 15:18:16 +00:00
|
|
|
3 const CARPET
|
2020-02-26 03:12:40 +00:00
|
|
|
4 const COMP-OFF
|
|
|
|
5 const COMP-ON
|
2020-03-07 15:18:16 +00:00
|
|
|
7 const CHAIR
|
2020-02-26 03:12:40 +00:00
|
|
|
9 const DOOR-CLOSED
|
|
|
|
10 const DOOR-OPENED
|
|
|
|
11 const SWITCH-OFF
|
|
|
|
12 const SWITCH-ON
|
|
|
|
20 const SCAN-OFF
|
|
|
|
21 const SCAN-ON
|
|
|
|
23 const REXX-POD
|
2020-03-28 20:58:47 +00:00
|
|
|
24 const PAD-OFF
|
|
|
|
25 const PAD-ON
|
2020-02-26 03:12:40 +00:00
|
|
|
|
2020-02-02 23:33:07 +00:00
|
|
|
: mapflag? ( x y flag -- b ) >rot tile b@ tileflags + b@ & ;
|
|
|
|
|
|
|
|
: tick-mapedit
|
|
|
|
tileselect @
|
|
|
|
^< key-pressed if 1 - then
|
|
|
|
^> key-pressed if 1 + then
|
|
|
|
0 max MAXTILE min
|
|
|
|
tileselect !
|
|
|
|
|
|
|
|
MOUSEL mousedown if tileselect @ mousetile tile b! invalidate-map then
|
|
|
|
MOUSER clicked if
|
|
|
|
mouseworldpos world>tile
|
|
|
|
2dup tile b@ tileselect !
|
|
|
|
swap . . cr then ;
|
|
|
|
|
|
|
|
: copy-mapseg ( neww oldw y -- )
|
|
|
|
>r ( oldw neww r: y )
|
|
|
|
2dup min >rot ( copyw neww oldw )
|
|
|
|
r@ * map + ( copyw neww src )
|
|
|
|
swap <r * map + ( copyw src dst )
|
|
|
|
swap <rot memmove ;
|
|
|
|
|
|
|
|
: resize-map ( neww newh -- )
|
|
|
|
swap mapsize >r ( newh neww oldw r: oldh )
|
|
|
|
2dup < if 1 <r else <r 1 - 0 then ( newh neww copyw ystart ylim )
|
|
|
|
for 2dup i copy-mapseg next
|
|
|
|
drop swap mapsize! ; userword
|
|
|
|
|
|
|
|
: mapw mapsize drop ;
|
|
|
|
: maph mapsize nip ;
|
|
|
|
|
|
|
|
: offset-map ( p d -- p ) dup 0 < if drop else + then ;
|
|
|
|
|
|
|
|
: shift-map ( dx dy -- )
|
|
|
|
maph over abs - >r ( dx dy r: h )
|
|
|
|
swap mapw over abs - >rot ( w dy dx r: h )
|
|
|
|
2dup map swap offset-map
|
|
|
|
swap mapw * offset-map >rot ( w end dy dx r: h )
|
|
|
|
map swap negate offset-map
|
|
|
|
swap mapw * negate offset-map ( w end start r: h )
|
|
|
|
2dup > if r@ mapw * + swap r@ mapw * + swap then
|
|
|
|
<r 0 for
|
|
|
|
3dup <rot memmove
|
|
|
|
2dup < if mapw + swap mapw + swap
|
|
|
|
else mapw - swap mapw - swap then
|
|
|
|
next drop drop drop invalidate-map ; userword
|
|
|
|
|
|
|
|
: save-map ( filename -- )
|
|
|
|
fdeactivate swap overwrite
|
|
|
|
mapsize swap fput fput
|
|
|
|
mapsize * map fwrite
|
|
|
|
factivate ; userword
|
|
|
|
|
|
|
|
: load-map ( filename -- )
|
|
|
|
fdeactivate swap open
|
|
|
|
fget fget
|
|
|
|
2dup * map fread
|
|
|
|
mapsize!
|
|
|
|
factivate ; userword
|
|
|
|
|
|
|
|
: fill-map ( tile -- )
|
|
|
|
0 mapsize * for dup map i + b! next drop invalidate-map ; userword
|