1 #include "xrisk.h"
2 #include "xriskex.h"
3 #include "risklibex.h"
4 #include "xrisklibex.h"
5 #include "control_states.h"
6 
7 /* Control functions */
8 
9 /* Someone fullfilled his mission */
done_mission(player)10 int done_mission(player)
11      playerp player;
12 {
13   int t;
14 
15   write_msg(player,"#072_Congratulations, you have fullfilled your mission");
16   write_msg_all_arg("#073_%s's mission was to :",player->name,LAST_ARG);
17   write_msg_all(player->mission->sentence);
18   write_msg_all("#074_This mission is now fullfilled");
19   write_msg_all_arg
20     ("#075_%s is the winner of xrisk",player->name,LAST_ARG);
21   Do_each_player(t) if (players[t]->state->state < END_GAME)
22     parse_killed(players[t]);
23   return(0);
24 }
25 
26 /* We have got a winner */
a_winner()27 int a_winner()
28 {
29   int t;
30   Do_each_player(t) if (players[t]->state->state < END_GAME)
31     {
32       parse_killed(players[t]);
33       write_msg(players[t],
34 		"#032_Congratulations, you have conquered the world");
35       write_msg_all_arg("#008_%s conquered the world",
36 			players[t]->name,LAST_ARG);
37     }
38   return(0);
39 }
40 
41 #define BitSet(a,b) ( ( (a) >> (b) ) & 1 )
42 
43 /* Over to the next control_state */
next_control_state()44 int next_control_state()
45 {
46   control_data.control_action =
47     &control_actions[control_data.control_action->index_next];
48   control_data.who_where = &who_where[control_data.control_action->c_state];
49   return(0);
50 }
51 
52 /* Wait for all the others before continuing */
wait_for_all()53 int wait_for_all()
54 {
55   int i,c,next_state,players_in_state;
56 
57   if (num_players==1) a_winner();
58   if (num_players < 2)
59     {
60       next_control_state();
61       return(0);
62     }
63 
64   i = *(control_data.who_where);
65 
66   for(c=0,players_in_state=0;c<16;c++) if (BitSet(i,c)) players_in_state++;
67 
68   if (players_in_state != num_players) return(0);
69 
70   next_state = control_data.control_action->next_state;
71   for(c=0;c<16;c++) if (BitSet(i,c)) new_state(players[c],next_state);
72   next_control_state();
73   return(0);
74 }
75 
76 /* Wait for your turn */
wait_for_turn()77 int wait_for_turn()
78 {
79   int        i,c,next_state,players_in_state;
80   static int which_player=0;
81 
82   if (num_players == 1) a_winner();
83   if (num_players  < 2)
84     {
85       next_control_state();
86       return(0);
87     }
88 
89   i = *(control_data.who_where);
90 
91   for(c=0,players_in_state=0;c<16;c++) if (BitSet(i,c)) players_in_state++;
92 
93   if ((game_options.options & TWO_ACTIVE_PLAYERS) && (num_players > 2))
94     { if (players_in_state < num_players-1 ) return(0); }
95   else
96     { if (players_in_state != num_players)   return(0); }
97 
98   do
99     if (which_player>MAX_PLAYERS) which_player=0;
100     else                          which_player++;
101   while(!BitSet(i,which_player));
102 
103   next_state = control_data.control_action->next_state;
104   new_state(players[which_player],next_state);
105   return(0);
106 }
107 
108 /* Wait for all to quit */
wait_all_quit()109 int wait_all_quit()
110 {
111   if (*control_data.who_where) return(0);
112   next_control_state();
113   return(0);
114 }
115 
116 /* Wait for the players to close down */
control_next()117 int control_next()
118 {
119   if (*control_data.who_where) return(0);
120   return(1);
121 }
122