Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Post Code

Name: Anonymous 2011-03-04 21:33

One recurring complaint is that nobody talks about code on /prog/. So everyone write go and write some code, any code, that does something, anything, and post it. A small explanation wouldn't go amiss either.

Name: Anonymous 2011-03-19 7:56


defaultTeams =: ["neutral"=0 "rescue-passive"=1 "computer"=2 "person"=3 "rescue-active"=3]

loadWorld filename
 -> clearWorld
 -> worldInfo=:["name"=(split \/ filename |> rhd) "file"=filename]
 -> tiles:[] gfxes:[] us:[] players:[]
    setTile:{id x y -> c:(Cell tileId=id seenGfx=gfxes,id terra=tiles,id."mask"
                              params=tileParams.(tiles,id."class"))
                       aset y*ww+x c cells}
    dataHandlers:
      ["Resources" = {n [var value] -> players.n.vars.var =: value}
       "RaceName" = {n [r] -> players.n.vars."race" =: r}]
    handlers:
      ["SetTile" = {[id x y v] -> setTile id x+wm y+wm}
       "SetPlayerData" = {[n type @xs] -> dataHandlers.type n xs}
       "SetStartView" = {[n x y] -> players.n.tile =: [x y]+[wm wm]}
       "SetAiType" = {[n type] -> <:say "ai $n $type":>}
       "LoadTileModels" = {[path] -> tileset =: tilesets.(drop 17 path |> drop ~4 |> asStr)
                               -> tiles   =: tileset."tiles"
                               -> gfxes   =: tileset."gfxes"}
       "DefinePlayerTypes" =
         {[@xs] -> for [n p] in (strip {[_ "nobody"]} ["neutral" @xs].cnt) do
                     players.n =: (newUnit 0 "player")
                     players.n.uid=:n
                     [@!players.n.vars "name"="Player$n" "type"=p
                      "team"=defaultTeams.p "color"=playerColors,n]}
       "CreateUnit" = {[type n tile] -> [@!us [tile+[wm wm] n type ye?]]}
       "SetResourcesHeld" = {[_ amount] -> us=:[@us.rtl [@us.rhd.rtl {u->u.vars."gold"=:amount}]]}
       "PresentMap" = {[d p w h uid] -> ["description"=d @!worldInfo]
                                     -> ww=:w+2wm -> wh=:h+2wm -> cells=:(Vector ww*wh)}
       ]
    filename.fget |> map asChr |> map {\,->\Space; \{->\(; \}->\); x->x} |> split \Newline
    |> map {[@xs @"--" @_]->xs; xs->xs}
    |> fe {[@name \( @xs] -> f:handlers.(asStr name).(_ error "loadWorld: cant handle @name")
                             as:(parseST [\( @xs])
                             f as}
 -> for [x y] in [ww-wm 0 wm wh].rectPoints setTile 0 x y
 -> for [x y] in [0 wh-wm ww wm].rectPoints setTile 0 x y
 -> for [x y] in [0 0 wm wh].rectPoints setTile 0 x y
 -> for [x y] in [0 0 ww wm].rectPoints setTile 0 x y
 -> for [id u] in players u.vars."type".{"person" -> thisPlayer=:id
                                                  -> deployUnit u.tile u
                                        ; _ -> aset id u units}
 -> for [xy p u f] in us deployUnit xy (newUnit p u).f
 -> no

Name: Anonymous 2011-03-19 8:05

Just realized, I can replace

 -> for [x y] in [ww-wm 0 wm wh].rectPoints setTile 0 x y
 -> for [x y] in [0 wh-wm ww wm].rectPoints setTile 0 x y
 -> for [x y] in [0 0 wm wh].rectPoints setTile 0 x y
 -> for [x y] in [0 0 ww wm].rectPoints setTile 0 x y

with

 -> map rectPoints [[ww-wm 0 wm wh] [0 wh-wm ww wm] [0 0 wm wh] [0 0 ww wm]]
    |> fold conc |> map [x y]~>(setTile 0 x y)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List