1
Name:
Anonymous
2011-12-03 3:45
Do any exist? I've been looking for something like a high level C. The closest thing is probably Lua, but that's obviously unacceptable. Plus Lua is more C++ and less C. I liked Perl, but Perl 6 is not so good and has left a bad taste in my mouth.
91
Name:
Anonymous
2011-12-06 15:27
dead? U -> U,n? || (and U.Mask TileMasks.Dead)!=0
targetable? U -> U && U.Parent,n?
selectable? U -> U,dead?,n? && U,targetable? && U.HP,pos?
center U -> U.Tile + U.Size%%2
centerDisp U -> U.Disp +16U.Size-[16 16]
distanceToPlayer XY -> abs XY - Units,ThisPlayer,center
prettyName U -> U.UIName || sym (subst "_" " " U.Type,str)
unitUiColor U -> U.Owner==ThisPlayer |> #00FF00 :: Tints.(U.Color)
hp100 U -> H:U.HP (H-U.Hits)*100%%H
actGT N O -> NP:N.Prio OP:O.Prio -> OP<NP || OP==NP && O.Forced,n?
order O U -> O,sym? |> O=:UTs.'O -> Id:(U,xs? |> U.Id :: U)
-> actGT O Orders.'Id |> Orders.'Id=:O -> U
unitSay S U -> U,int? |> U=:Units,U -> D:n
-> S:U.Sounds.(S,([N I] -> D=:I -> N; S->S))
-> snd\play (D|>S,D::S,pick) Volume=1.0-U.Tile,distanceToPlayer/24
act O U -> O,sym? |> O=:UTs.'O -> !O.Dst || U.Id -> !O.Range || U.Range || 1
-> U.Path |> U.Path=:n -> U.Act=:O
units Is -> map ?,(I:int?->Units,I; U->U) Is
anim A U -> U.Anim =: (U.Anims.'A||U.Anims.Still)
swapAnim D S U -> UTs.(U.Type).Anims.'S |> U.Anims.'D=:It :: U
morph T U -> O:U.Owner T:(T,sym? |> UTs.'T :: T) -> T.Id=:U.Id
-> T.Owner=:O -> T.Color=:U.Color -> T.Act=:U.Act -> T.Tile=:U.Tile
-> T.Disp=:U.Disp -> T.Dir=:U.Dir -> T.Frame=:U.Frame -> T.Anim=:U.Anim
-> T.Hits=:U.Hits -> T.Kids=:U.Kids -> U.Effects |> T.Effects=:It
-> U.Fire |> T.Fire=:It -> U.Res |> T.Res=:It -> U.Mana |> T.Mana=:It
-> skip1 U.Id !Owned,O.(U.Type) => @!Owned,O.(T.Type) T.Id -> T
awayFrom 'f R SR -> RT:~[R R] RS:[2R 2R] take MaxUnits Units
| all (n?->y; U->rectsIsect [@(U.Tile+RT) @(U.Size+RS)] SR && f U | n?)
efx U Es -> merge !U.Effects Es
flipUnitLayer U -> updArea U (C->xor !C.Mask U.Layer)
mark U -> Id:U.Id S:U.Sight
-> updArea U (C => @!C.Content Id -> xor !C.Mask U.Layer)
-> updArea [Tile=U.Tile-[S S] Size=U.Size+[2S 2S]] (C => @!C.Sensors Id)
unmark U -> Id:U.Id S:U.Sight
-> updArea U (C -> skip1 Id !C.Content -> xor !C.Mask U.Layer)
-> updArea [Tile=U.Tile-[S S] Size=U.Size+[2S 2S]] (C -> skip1 Id !C.Sensors)
deployUnit XY U => @!U Tile=XY Disp=32XY -> aset U.Id U Units -> mark U
newUnit O T Delay=n -> T,sym? |> T=:UTs.'T -> R:(Delay||rand 6)+1+Cycle
-> U:[@T Id=FreeIds,pop Owner=O Color=(T.Color||Units,O.Color||{Yellow})]
-> U.MP |> [@!MUs updMana U.Id]
-> U.Upgrades |> map (upgrade ? !U) (keep Owned,O.? It)
=> @!Scheds.'R U.Id => @!Owned,O.(T.Type) U.Id -> U
delUnit Id -> U:Units,Id O:U.Owner -> U.Disp |> unmark U -> ~@!Orders.'Id
-> skip1 Id !Owned,O.(U.Type) => @!FreeIds Id -> aset Id n Units
freeUnit U => @!DelUnits (U,int? |> U :: U.Id) -> U
killUnit U
-> (and U.Mask TileMasks.Dead)==0 |>
(-> U.Disp |>
(-> U.Layer == TileMasks.`2` |>
(-> U,unmark -> U.Layer=:TileMasks.`0` -> U,mark)
-> U.Explodes |> spawnFx U.Tile It D=U,centerDisp-[16 16]
-> U.Building |>
(-> U.Fire=:n
-> E:UTs.(U.Extends) R:E.Resource E && (R,n?||U.'R,pos?) |>
(-> N:(newUnit 0 E.Type) -> deployUnit U.Tile N.'R=:U.'R)))
-> U.Parent |> [@!Trans 'unkid [It U.Id]]
-> U.Incomplete,n? && U.Supply |> [[U.Id {Food} ~It]@!NQs.(U.Owner).`+`]
-> U.Cost.Food |> [[U.Id {Food} It]@!NQs.(U.Owner).`+`]
-> or !U.Mask TileMasks.Dead)
-> U
spawnUnit O T XY A=n TTL=n -> U:[@(newUnit O T) Tile=XY] -> A |> (anim A !U)
-> U.Building||U.Dir=:Dirs,pick => @!Trans 'show U.Id => U@!NewUnits -> u
DeathAnim ~> (0 0)
StillAnim ~> (0 6)
BuildingAnim => Still={(0 6)} `50`={(1 6)} `25`={(2 6)} `0`={(3 6)}
Attack={attack (0 60)} Death={(4 200) (5 200)}
chkCost Rs C -> D:(~@C.Time | map ([R A] => R Rs.'R-A))
-> keep ([_ neg?]->y) D |> D
chkCosts U T
-> (T.UCost |> chkCost U It) || (T.OCost |> chkCost Units,(U.Owner) It)
canAct U A T
-> A.Rule |> fc It U A T :: y |>
(chkCosts U A |> do (notify "Not enough $(It,0,0) for $(A.Type)") n :: y)
enemyOf U X -> fnd X.Owner Units,(U.Owner).Enemies
canAttack U A T -> T && (A.Confirm||enemyOf U T) && (and A.Mask T.Mask)==T.Mask
CoastMask -> TileMasks.Coast
ruleCoast P -> points [@P 3 3] | any (P->(and P,cell.Mask CoastMask)!=0)
ruleGoldMine P -> awayFrom ?.Depot=={Gold} 3 [@P 3 3]
ruleGoldDepot P -> awayFrom ?.Resource=={Gold} 3 [@P 4 4]
ruleOilDepot P -> P,ruleCoast && awayFrom ?.Resource=={Oil} 3 [@P 3 3]
canHarvest U A -> R:U.Resource
-> R && U.Foundation,n? && (fnd R A.Harvests |> U.'It,pos? && It)
ruleHarvest U A T -> canHarvest T A |> U.'It<100
doHarvest U -> A:U.Act Dst:A.Dst D:Units,Dst R:A.Res
-> R || (-> R=:(canHarvest D A) -> U.Act.Res=:R)
-> cnd {U.Parent || D.TileId ->
;y => @!Trans 'hide [Dst U.Id] -> U.Act.Sounds=:n -> anim {Still} !U}
-> U
fixHarvest U -> A:U.Act Id:A.Dst D:Units,Id R:A.Res
-> cnd {U.'R>=100 -> swapAnim {Move} R !U | swapAnim {Still} "$(R)Still"
-> U.Parent |> (=> @!Trans 'show U.Id -> anim {Still} !U)
-> act [@UTs.Store Back=Id Res=R Depot=A.Depot] !U
;D.TileId && findResource U D.Tile A -> U.Act.Dst=:It
;y -> U.Act=:n}
-> U
resources U -> keep U.?,pos? ResNames
doStore U -> A:U.Act R:(A.Res || U,resources,([R@_] -> U.Act.Res=:R -> R))
Depot:A.Depot T:(Depot |> Units,Depot) | dead?
|>(Depot || findDepot R U
|> U.Act.Depot=:It :: (-> notify "Nowhere to store $R" -> U.Act=:n))
::A.State,({Near} -> swapAnim {Move} {Move} !U | swapAnim {Still} {Still}
=> @!Trans 'hide [Depot U.Id] -> U.Act.State=:{Inside}
;{Inside} -> pos? U.'R
|> (=> @!NQs.(U.Owner).`+` [U.Id R 5] -> !U.'R-5)
:: (=> @!Trans 'show U.Id
-> O:(map UTs.? U.Acts | fnd (X -> fnd R X.Harvests))
-> order [@O Dst=A.Back Depot=A.Depot] U)
; _ -> U.Act.State=:{Near} -> U.Act.Dst=:Depot)
-> U
ruleMove U A T -> canMoveTo T.Tile U
ruleBoard U A T -> T.Transport && T.Owner==U.Owner
doBoard U => @!Trans 'hide [U.Act.Dst U.Id] -> U.Act=:n
doUnloadSelf U => @!Trans 'show U.Id -> U.Act=:n
produce C U HP=n
-> O:[@UTs.Producing O=Cycle T=(max 1 24C.Time%%32) Last=Cycle Cost=C]
-> HP |> (-> U.Hits=:U.HP-1 -> O.AddHP=:U.HP/O.T) -> U.Incomplete=:y -> act O U
ruleBuild U A T -> buildRect T.Tile U UTs.(A.What) | all 'y?
doBuild U -> A:U.Act
-> B:(newUnit U.Owner A.What) -> B.Tile=:Units,(A.Dst).Tile
-> E:(map Units,? B.Tile,cell.Content | fnd ?.Type==B.Extends)
|> (-> R:E.Resource B.'R=:E.'R -> freeUnit E)
-> swapAnim {Still} "0" !B -> produce A.OCost !B HP=y
-> B.Anims.Still | ([[F _]@_] -> B.Frame=:F) -> unitSay {Construction} B
=> @!Trans 'hide [B.Id U.Id] 'show B.Id => @!NewUnits B -> U.Act=:n
doTrain U -> A:U.Act P:A.Producing
|> (-> fnd P U.Kids |> U :: U.Act=:n)
:: (-> NU:[@(newUnit U.Owner A.What) Tile=U,center Parent=U.Id]
-> produce A.OCost !NU -> A.Research |> NU.Research=:y
-> NU.Dir=:Dirs,pick => @!NewUnits NU
=> @!U.Kids NU.Id => @!U.Act Producing=NU.Id OCost=n)
doMorph U -> A:U.Act T:UTs.(A.Into) -> U.MorphTo=:T.Type -> U.Gfxes=:T.Gfxes
-> produce T.Cost !U -> U.Anims=:T.Anims -> anim "50" !U -> U
doProducing U
-> A:U.Act fin:(-> swapAnim {Still} {Still} !U | anim {Still}
-> max !U.Hits 0 | int -> ~@U.Incomplete -> U.Act=:n)
cnd {(C:Cycle-A.O) < (T:A.T)
-> anim cnd,{C/T<1/4->"0"; C/T<1/2->"25"; y->"50"} !U
-> !U.Hits - (Cycle-A.Last)*A.AddHP => @!U.Act Last=Cycle
;U.Research -> T:U.Type O:U.Owner
-> U.MorphAll |> morphUnits O It T
-> U.Upgrade |> map (upgradeUnits O ? T) Upgrades.'T
-> rekid U.Owner U.Id -> fin
;U.Parent -> unitSay {Ready} U => @!Trans 'show U.Id -> fin
;N:UTs.(U.MorphTo) -> morph N !U -> fin
;y -> U.Supply |> [[U.Id {Food} It]@!NQs.(U.Owner).`+`]
-> U.Kids,([Id@_] -> unitSay {Work_Done} Id -> showKids U) -> fin}
doCancel U
-> (A:U.Act.What).Type == {Producing}
|> (-> for [R A]=~@A.Cost.Food [[U.Id R A]@!NQs.(U.Owner).`+`]
-> U.MorphTo |> (-> U.Gfxes=:UTs.(U.Type).Gfxes -> U.Act=:n)
:: (-> showKids U | order {Die}))
:: U.Act=:n
-> U
animSpeed [[_ W _]@Xs] -> W+Xs,animSpeed
DummyFrame => 8++DummyGfx
AttackLayers -> map TileMasks.? 0..9 | fold 'or
MCs => Coast={Water Coast} Water={Water} Land={Plain Mud}
Air={Rock Forest Plain Mud Coast Water Wall}
Plain={Plain} Wall={Wall} Invuln={Invuln}