-
Notifications
You must be signed in to change notification settings - Fork 0
/
AI_Chain.fs
42 lines (37 loc) · 1.08 KB
/
AI_Chain.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
type Microsoft.FSharp.Collections.FSharpList<'a> with
static member iterWhile (f:'a -> bool) (ls:'a list) =
let rec iterLoop f ls =
match ls with
| head :: tail -> if f head then iterLoop f tail
| _ -> ()
iterLoop f ls
open AI
type AI_Chain(ais : AI list) =
inherit AI()
let mutable started = []
override this.Start() =
base.Start()
match ais with
| head :: tail ->
head.Start()
started <- head :: started
| _ -> ()
override this.Stop() =
base.Stop()
started |> List.iter (fun x -> x.Stop())
started <- []
override this.Reset() =
base.Reset()
override this.Priority() =
match started with
| head :: tail -> head.Priority()
| _ -> 0.0
override this.Update(gameTime) =
ais
|> List.iterWhile (fun x ->
if not x.Running then
x.Start()
started <- x :: started
x.Update(gameTime)
x.Priority() > 0.0)