source:
branches/AlphaChannel/AI Template/Project/Persistent.cs
Last change on this file was 191, checked in by , 5 years ago | |
---|---|
File size: 1.6 KB |
Line | |
---|---|
1 | using System; |
2 | using System.Collections.Generic; |
3 | using CevoAILib; |
4 | |
5 | namespace AI |
6 | { |
7 | unsafe class Persistent |
8 | { |
9 | struct MyData |
10 | { |
11 | public int Version; |
12 | public fixed short EstimatedStrength[Cevo.MaxNumberOfNations]; |
13 | public Advance LastResearch; |
14 | public fixed sbyte BiggestFriend[Cevo.MaxNumberOfNations]; |
15 | } |
16 | |
17 | Empire theEmpire; |
18 | MyData* data; |
19 | |
20 | public Persistent(Empire empire, IntPtr dataPtr) |
21 | { |
22 | if (sizeof(MyData) > 4096) |
23 | throw new Exception("Persistent data size exceeds limit!"); |
24 | |
25 | this.theEmpire = empire; |
26 | this.data = (MyData*)dataPtr; |
27 | |
28 | // initialization |
29 | data->LastResearch = Advance.None; |
30 | for (int nationID = 0; nationID < Cevo.MaxNumberOfNations; nationID++) |
31 | { |
32 | data->EstimatedStrength[nationID] = 100; |
33 | data->BiggestFriend[nationID] = (sbyte)Nation.None.ID; |
34 | } |
35 | } |
36 | |
37 | public int Version |
38 | { |
39 | get |
40 | { |
41 | return data->Version; |
42 | } |
43 | set |
44 | { |
45 | data->Version = value; |
46 | } |
47 | } |
48 | |
49 | public int EstimatedStrength(Nation nation) |
50 | { |
51 | return data->EstimatedStrength[nation.ID]; |
52 | } |
53 | |
54 | public void SetEstimatedStrength(Nation nation, int strength) |
55 | { |
56 | data->EstimatedStrength[nation.ID] = (short)strength; |
57 | } |
58 | |
59 | public Advance LastResearch |
60 | { |
61 | get |
62 | { |
63 | return data->LastResearch; |
64 | } |
65 | set |
66 | { |
67 | data->LastResearch = value; |
68 | } |
69 | } |
70 | |
71 | public Nation BiggestFriendOf(Nation nation) |
72 | { |
73 | return new Nation(theEmpire, data->BiggestFriend[nation.ID]); |
74 | } |
75 | |
76 | public void SetBiggestFriendOf(Nation nation, Nation friend) |
77 | { |
78 | data->BiggestFriend[nation.ID] = (sbyte)friend.ID; |
79 | } |
80 | } |
81 | } |
Note:
See TracBrowser
for help on using the repository browser.