-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathempire-commands.adb
165 lines (142 loc) · 4.46 KB
/
empire-commands.adb
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
-- simple commands.
with Ada.Text_IO;
with Empire.Ai;
with Empire.Game;
with Empire.Locations;
with Empire.Math;
with Empire.Objects;
with Empire.Ui;
package body Empire.Commands is
-- Debugging commands should be implemented here. The order cannot be any
-- legal command.
procedure Debug (Order : Character) is
E : Character;
begin
case Order is
when '#' =>
Examine;
when '%' =>
Movie;
when '@' => -- change trace state
E := Ui.Get_Chx;
if E = '+' then
Trace_Pmap := True;
elsif E = '-' then
Trace_Pmap := False;
else
Ui.Huh;
end if;
when '$' => -- change print_debug state
E := Ui.Get_Chx;
if E = '+' then
Print_Debug := True;
elsif E = '-' then
Print_Debug := False;
else
Ui.Huh;
end if;
when '&' => -- change print_vmap state
E := Ui.Get_Chx;
case E is
when 'A' | 'I' | 'L' | 'S' | 'U' =>
Print_Vmap := E;
when others =>
Ui.Huh;
end case;
when others =>
Ui.Huh;
end case;
end Debug;
-- Allow user to examine the computer's map
procedure Examine is
Sec : Sector_T;
begin
Sec := Ui.Get_Int ("Sector number? ", Sector_T'First, Sector_T'Last);
Ui.Print_Sector (COMP, Sec);
end Examine;
-- Give an unowned city (if any) to the computer. We make a list of unowned
-- cities, choose one at random, and mark it as the computers.
procedure Give is
Unowned_Cities : array (City'Range) of Integer;
City_Index : Integer;
Count : Integer := 0; -- nothing in list yet
begin
for I in City'Range loop
if City (I).Owner = UNOWNED then
Count := Count + 1;
Unowned_Cities (Count) := I;
end if;
end loop;
if Count = 0 then
Ui.Error ("There are no unowned cities.");
return;
end if;
City_Index :=
Unowned_Cities
(Math.Rand_Long (Count)); -- pick a city, get its index
City (City_Index).Owner := COMP;
City (City_Index).Prod := NOPIECE;
City (City_Index).work := 0;
Objects.Scan (COMP, City (City_Index).Loc);
end Give;
-- The quit command. Make sure the user really wants to quit
procedure Quit is
begin
if Ui.Get_Yn ("QUIT -- Are you sure? ") then
Emp_End;
end if;
end Quit;
-- Read the sector number from the user and print that sector
procedure Sector is
Sec : Sector_T;
begin
Sec := Ui.Get_Int ("Sector number? ", Sector_T'First, Sector_T'Last);
Ui.Print_Sector (USER, Sec);
end Sector;
-- Print the map to a file.
-- We print the map sideways to make it easier for the user to print out the
-- map. XXX XXX For now, unlike C version, we always use the same file name
-- (which is symmetric with game and movie saves). All three should change.
procedure Map is
F : Ada.Text_IO.File_Type;
begin
Ada.Text_IO.Create (F, Ada.Text_IO.Out_File, MAP_NAME);
for I in Column_T'Range loop
for J in Row_T'Range loop
-- XXX we should do this line-at-a-time, as the C does.
Content_IO.Put
(F,
View (USER) (Locations.Row_Col_Loc (J, I)).Contents);
end loop;
Ada.Text_IO.Put_Line (F, "");
end loop;
exception
when others => -- XXX XXX much too general
Ui.Error ("Unable to write map to file " & MAP_NAME & ".");
end Map;
-- We give the computer lots of free moves and Print a "zoomed" version of the
-- computer's map.
procedure Movie is
begin
loop
Ai.Comp_Move;
Ui.Print_Zoom (View (COMP));
Game.Save_Game;
end loop;
end Movie;
-- restore game with some error handling
procedure Restore is
begin
Game.Restore_Game;
exception
when Game.No_Saved_Game =>
Game.Init_Game;
when Game.Corrupt_Saved_Game =>
Ui.Error ("Saved game is corrupted!");
if Ui.Get_Yn ("Overwrite with new game? ") then
Game.Init_Game;
else
Emp_End;
end if;
end Restore;
end Empire.Commands;