summaryrefslogtreecommitdiff
path: root/extra/foobillard/06_show_ball_to_hit
blob: 9c49f58cc0fb49a421c34f531b81dcb15e08834d (plain)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
Index: foobillard-3.0a/src/billard.c
===================================================================
--- foobillard-3.0a.orig/src/billard.c	2006-10-12 16:45:04.000000000 +0200
+++ foobillard-3.0a/src/billard.c	2006-10-12 16:45:23.000000000 +0200
@@ -31,6 +31,8 @@
 void * (*billard_malloc)( size_t size ) = malloc;
 void (*billard_free)( void * ptr ) = free;
 
+SnookerState snooker_state={SN_PLAY_RED};
+
 void setfunc_create_scene( void (*func)( BallsType * balls ) )
 {
     create_scene=func;
Index: foobillard-3.0a/src/billard.h
===================================================================
--- foobillard-3.0a.orig/src/billard.h	2006-10-12 16:45:05.000000000 +0200
+++ foobillard-3.0a/src/billard.h	2006-10-12 16:45:23.000000000 +0200
@@ -76,9 +76,30 @@
 #define BALL_HALF 2
 #define BALL_ANY  0
 
+typedef enum
+{
+   SN_PLAY_RED,
+   SN_PLAY_ANY_COLOR,
+   SN_PLAY_YELLOW,
+   SN_PLAY_GREEN,
+   SN_PLAY_BROWN,
+   SN_PLAY_BLUE,
+   SN_PLAY_PINK,
+   SN_PLAY_BLACK,
+   SN_DONE
+}
+SnookerBallToPlay;
+
+typedef struct
+{
+   SnookerBallToPlay to_play;
+}
+SnookerState;
+
 #ifndef BILLARD_C
 extern void (*create_scene)( BallsType * balls );
 extern void (*create_walls)( BordersType * walls );
+extern SnookerState snooker_state;
 #endif
 
 void create_0hole_walls( BordersType * walls );   /* carambol */
Index: foobillard-3.0a/src/billard3d.c
===================================================================
--- foobillard-3.0a.orig/src/billard3d.c	2006-10-12 16:45:08.000000000 +0200
+++ foobillard-3.0a/src/billard3d.c	2006-10-12 16:45:23.000000000 +0200
@@ -829,6 +829,7 @@
         player[act_player].place_cue_ball=1;
         human_player_roster.player[0].cue_ball=0;   human_player_roster.player[1].cue_ball=0;
         human_player_roster.player[act_player].place_cue_ball=1;
+        snooker_state.to_play=SN_PLAY_RED;
     }
 }
 
@@ -1787,6 +1788,7 @@
            /* score text */
            for(i=0;i<2;i++){
                char str[256];
+               char *color;
                switch(gametype){
                case GAME_8BALL: strcpy(str,"0"); break;
                case GAME_9BALL:
@@ -1805,7 +1807,44 @@
                    sprintf( str, "%d", player[i].score );
                    break;
                case GAME_SNOOKER:
-                   sprintf( str, "%c%03d  %s", (player[i].score<0)?'-':'+', abs(player[i].score), player[i].snooker_on_red ? "red":"col" );
+                   switch(snooker_state.to_play)
+                   {
+                   case SN_PLAY_RED:
+                       color="red";
+                       break;
+                   case SN_PLAY_ANY_COLOR:
+                       color="color";
+                       break;
+                   case SN_PLAY_YELLOW:
+                       color="yellow";
+                       break;
+                   case SN_PLAY_GREEN:
+                       color="green";
+                       break;
+                   case SN_PLAY_BROWN:
+                       color="brown";
+                       break;
+                   case SN_PLAY_BLUE:
+                       color="blue";
+                       break;
+                   case SN_PLAY_PINK:
+                       color="pink";
+                       break;
+                   case SN_PLAY_BLACK:
+                       color="black";
+                       break;
+                   case SN_DONE:
+                       color="";
+                       break;
+                   }
+                   if(i==act_player)
+                   {
+                       sprintf( str, "%.3d  %s", player[i].score, color);
+                   }
+                   else
+                   {
+                       sprintf( str, "%.3d", player[i].score);
+                   }
                    break;
                }
                textObj_setText( player[i].score_text, str );
Index: foobillard-3.0a/src/evaluate_move.c
===================================================================
--- foobillard-3.0a.orig/src/evaluate_move.c	2006-10-12 16:45:12.000000000 +0200
+++ foobillard-3.0a/src/evaluate_move.c	2006-10-12 16:45:23.000000000 +0200
@@ -30,26 +30,6 @@
 
 #define MAX(x,y) ((x)>(y)?(x):(y));
 
-typedef enum
-{
-   SN_PLAY_RED,
-   SN_PLAY_ANY_COLOR,
-   SN_PLAY_YELLOW,
-   SN_PLAY_GREEN,
-   SN_PLAY_BROWN,
-   SN_PLAY_BLUE,
-   SN_PLAY_PINK,
-   SN_PLAY_BLACK,
-   SN_DONE
-}
-SnookerBallToPlay;
-
-typedef struct
-{
-   SnookerBallToPlay to_play;
-}
-SnookerState;
-
 
 void spot_snooker_ball(BallsType *balls,int nr);
 
@@ -400,7 +380,6 @@
 #define act_player (*pact_player)
 #define IS_RED(x) ( x==1 || x>=8 )
     int red_balls_are_in_game=0;
-    static SnookerState st={SN_PLAY_RED};
     int color_to_pot;
     int i;
     int act_score=0;
@@ -409,7 +388,7 @@
     int ball_out;
     int other_player=(act_player==1)?0:1;
     int b1hit = BM_get_1st_ball_hit();  if (b1hit>=8) b1hit=1;
-    if(st.to_play==SN_DONE)
+    if(snooker_state.to_play==SN_DONE)
     {
         BM_reset_move_info();
         return;
@@ -417,7 +396,7 @@
 
     if( player[act_player].place_cue_ball ) player[act_player].place_cue_ball=0;
     printf("EVAL start\n");
-    printf("EVAL to_play=%d\n",st.to_play);
+    printf("EVAL to_play=%d\n",snooker_state.to_play);
     printf("EVAL b1hit=%d\n",b1hit);
     for(i=0;i<pballs->nr;i++){
         if( IS_RED(pballs->ball[i].nr) && pballs->ball[i].in_game ){
@@ -436,7 +415,7 @@
         textObj_setText(last_fault_text, "White ball is potted");
     }
 
-    switch(st.to_play)
+    switch(snooker_state.to_play)
     {
     case SN_PLAY_RED:
         color_to_pot=1;
@@ -476,7 +455,7 @@
             if( BM_get_ball_out(i))
                 spot_snooker_ball(pballs,i);
         }
-        st.to_play=SN_PLAY_ANY_COLOR;
+        snooker_state.to_play=SN_PLAY_ANY_COLOR;
         break;
     case SN_PLAY_ANY_COLOR:
         if(b1hit==1)
@@ -512,9 +491,9 @@
             }
         }
         if(red_balls_are_in_game)
-            st.to_play=SN_PLAY_RED;
+            snooker_state.to_play=SN_PLAY_RED;
         else
-            st.to_play=SN_PLAY_YELLOW;
+            snooker_state.to_play=SN_PLAY_YELLOW;
 
         for(i=2;i<8;i++)
         {
@@ -528,7 +507,7 @@
     case SN_PLAY_BLUE:
     case SN_PLAY_PINK:
     case SN_PLAY_BLACK:
-        color_to_pot=st.to_play;
+        color_to_pot=snooker_state.to_play;
         if(b1hit!=color_to_pot)
         {
             foul=1;
@@ -562,9 +541,9 @@
                 }
             }
         }
-        if(!foul && act_score>0) st.to_play++;
+        if(!foul && act_score>0) snooker_state.to_play++;
 
-        for(i=st.to_play;i<8;i++)
+        for(i=snooker_state.to_play;i<8;i++)
         {
             if( BM_get_ball_out(i))
                 spot_snooker_ball(pballs,i);
@@ -590,13 +569,13 @@
         printf("EVAL next player\n");
         if(red_balls_are_in_game)
         {
-            st.to_play=SN_PLAY_RED;
+            snooker_state.to_play=SN_PLAY_RED;
         }
         else
         {
-            if(st.to_play<=SN_PLAY_ANY_COLOR)
+            if(snooker_state.to_play<=SN_PLAY_ANY_COLOR)
             {
-                st.to_play=SN_PLAY_YELLOW;
+                snooker_state.to_play=SN_PLAY_YELLOW;
             }
         }
         player[act_player].queue_view=*pqueue_view;
@@ -605,11 +584,11 @@
         *pqueue_view=player[act_player].queue_view;
     }
 
-    player[act_player].snooker_on_red=st.to_play==SN_PLAY_RED;
-    player[act_player].snooker_next_color=st.to_play;
-    printf("EVAL to_play=%d\n",st.to_play);
+    player[act_player].snooker_on_red=snooker_state.to_play==SN_PLAY_RED;
+    player[act_player].snooker_next_color=snooker_state.to_play;
+    printf("EVAL to_play=%d\n",snooker_state.to_play);
 
-    if(st.to_play==SN_DONE)
+    if(snooker_state.to_play==SN_DONE)
     {
         int other_player;