source: branches/AlphaChannel/AI Template/Project/Lib/PlayResult.cs

Last change on this file was 191, checked in by chronos, 5 years ago
  • Added: AI Template directory with manual for development of custom AI from original game.
File size: 3.6 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace CevoAILib
5{
6 enum PlayError
7 {
8 None = -1,
9
10 // internal, should not occur
11 InternalError_UnknownCommand = 1,
12 InternalError_InvalidData = 0,
13
14 // general
15 NoTurn = 2, // command only allowed during player's turn
16 RulesViolation = 3, // general violation of game rules
17 PrerequisitesMissed = 4, // the prerequisites for this command are not fully met
18 InvalidLocation = 512, // location is not valid
19
20 // unit movement
21 NoTime_Move = 8, // normal unit move: too few movement points left
22 NoTime_Load = 9, // load unit: too few movement points left
23 DomainMismatch = 17, // move/attack: action not allowed for this unit domain
24 NoNavigation = 25, // unit move: not possible, open sea without navigation
25 NoRoad = 23, // unit move: not possible, no road
26 NoCapturer = 18, // unit move: this type of unit is not allowed to capture a city
27 ZoCViolation = 20, // unit move: not possible, ZoC violation
28 TreatyViolation = 21, // move/attack: not possible, peace treaty violation
29 SubmarineBlock = 19, // unit move: not possible, destination tile occupied by hidden foreign submarine
30 StealthUnitBlock = 26, // unit move: not possible, destination tile occupied by foreign stealth unit
31 NoLoadCapacity = 27, // load to transport: no more transport capacity
32 NoWay = 513,
33 RecoverFirst = 514,
34 Incomplete = 515,
35
36 // fighting
37 NoTime_Attack = 10, // attack: no movement points left
38 NoTime_Bombard = 11, // bombard city: too few movement points left
39 NoTime_Expel = 12, // expel spy: too few movement points left
40 NoBombarder = 28, // bombardment impossible because no attack power
41
42 // settlers
43 NoCityTerrain = 34, // found city: not possible in this terrain
44 NoBridgeBuilding = 35,
45 DeadLands = 22, // sStartJob: not possible, dead lands
46 MaxSize = 32, // add to city: bigger size not allowed due to missing aqueduct/sewer
47
48 // city
49 RebuildSellOnlyOnce = 88, // sell/rebuild city improvement: only once per city and turn!
50 UselessBuilding = 89, // city project: more advanced improvement already exists
51 OutOfControl = 90, // buy/sell/rebuild improvement: not in anarchy, not in captured cities
52 LocationNotAvailable = 80, // set exploited locations
53 TooManyLocations = 81, // set exploited locations
54
55 // model
56 ResearchInProgress = 516, // blueprint can't be changed during military research
57
58 // negotiation
59 InvalidOffer = 48,
60 OfferNotAcceptable = 49,
61 CancelTreatyRush = 50,
62 }
63
64 struct PlayResult
65 {
66 readonly int code;
67
68 public PlayResult(int code) { this.code = code; }
69 public PlayResult(PlayError error) { this.code = (int)error & 0xFFFF; }
70
71 public override string ToString()
72 {
73 if ((code & Protocol.rExecuted) != 0)
74 return "OK";
75 else
76 return string.Format("{0}", Error);
77 }
78
79 public PlayError Error
80 {
81 get
82 {
83 if (OK)
84 return PlayError.None;
85 else
86 return (PlayError)(code & 0xFFFF);
87 }
88 }
89
90 public bool OK { get { return (code & Protocol.rExecuted) != 0; } }
91 public bool Effective { get { return (code & Protocol.rEffective) != 0; } }
92 public bool UnitRemoved { get { return (code & Protocol.rUnitRemoved) != 0; } }
93 public bool EnemyDestroyed { get { return OK && (code & 0xFFFF) == Protocol.eEnemyDestroyed; } }
94 public bool NewUnitOrCitySpotted { get { return (code & Protocol.rEnemySpotted) != 0; } }
95
96 public static PlayResult Success { get { return new PlayResult(Protocol.rExecuted | Protocol.rEffective); } }
97 public static PlayResult NoChange { get { return new PlayResult(Protocol.rExecuted); } }
98 }
99}
Note: See TracBrowser for help on using the repository browser.