chiark / gitweb /
Fix Ahoy! recognition; make ADJUST_BOX take an OP argument
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 4 Jul 2009 20:15:17 +0000 (21:15 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 4 Jul 2009 20:15:17 +0000 (21:15 +0100)
pctb/structure.c

index 94c6b42..28caa24 100644 (file)
@@ -210,20 +210,20 @@ static int commod_selector_matches(Rect search, const char *const *all,
          );                                            \
   }while(0)
 
-#define ADJUST_BOX(search,insidechrs,want, lim,LIMIT_MUST, TLBR,XY,increm) \
-  for (;;) {                                                              \
-    LIMIT_MUST( (search).tl.XY != (search).br.XY &&                       \
-               (search).tl.XY != (lim),                                   \
-               MR((search));MSB(#TLBR);MSB(#XY) );                        \
-    int got=0;                                                            \
-    Point p=(search).tl;                                                  \
-    for (p.XY=(search).TLBR.XY;                                                   \
-        p.OTHERCOORD_##XY <= (search).br.OTHERCOORD_##XY;                 \
-        p.OTHERCOORD_##XY++)                                              \
-      got += !!strchr(insidechrs, get_p(p));                              \
-    if (got >= (want))                                                    \
-      break;                                                              \
-    (search).TLBR.XY += increm;                                                   \
+#define ADJUST_BOX(search,insidechrs,OP,want, lim,LIMIT_MUST, TLBR,XY,increm) \
+  for (;;) {                                                                 \
+    LIMIT_MUST( (search).tl.XY != (search).br.XY &&                          \
+               (search).tl.XY != (lim),                                      \
+               MR((search));MSB(#TLBR);MSB(#XY) );                           \
+    int got=0;                                                               \
+    Point p=(search).tl;                                                     \
+    for (p.XY=(search).TLBR.XY;                                                      \
+        p.OTHERCOORD_##XY <= (search).br.OTHERCOORD_##XY;                    \
+        p.OTHERCOORD_##XY++)                                                 \
+      got += !!strchr(insidechrs, get_p(p));                                 \
+    if ((got) OP (want))                                                     \
+      break;                                                                 \
+    (search).TLBR.XY += increm;                                                      \
   }
 
 void find_structure(CanonImage *im, int *max_relevant_y_r) {
@@ -326,8 +326,8 @@ void find_structure(CanonImage *im, int *max_relevant_y_r) {
 void check_correct_commodities(void) {
   Rect search= { { 50,39 }, { 130,59 } };
 
-  ADJUST_BOX(search,"_",10, cim->h, MUST, tl,y,+1);
-  ADJUST_BOX(search,"_",10, 0,      MUST, br,y,-1);
+  ADJUST_BOX(search,"_",>=,10, cim->h, MUST, tl,y,+1);
+  ADJUST_BOX(search,"_",>=,10, 0,      MUST, br,y,-1);
 
   debug_rect("commodselr",1, search);
 
@@ -608,15 +608,15 @@ Rect find_sunshine_widget(void) {
   sunshiner.tl.y= 227;
   sunshiner.br.y= 228;
 
-  ADJUST_BOX(sunshiner,"o*",30, 100,MUST, tl,y,-1);
-  ADJUST_BOX(sunshiner,"o*",30, 100,MUST, br,y,+1);
+  ADJUST_BOX(sunshiner,"o*",>=,30, 100,MUST, tl,y,-1);
+  ADJUST_BOX(sunshiner,"o*",>=,30, 100,MUST, br,y,+1);
   debug_rect("sunshiner",0, sunshiner);
 
   MUST(sunshiner.br.y - sunshiner.tl.y > 20, MR(sunshiner));
   sunshiner.br.y--;
 
-  ADJUST_BOX(sunshiner,"o",20, (cim->w - 1034 + 700), MUST, tl,x,-1);
-  ADJUST_BOX(sunshiner,"o",20,  cim->w,               MUST, br,x,+1);
+  ADJUST_BOX(sunshiner,"o",>=,20, (cim->w - 1034 + 700), MUST, tl,x,-1);
+  ADJUST_BOX(sunshiner,"o",>=,20,  cim->w,               MUST, br,x,+1);
   debug_rect("sunshiner",1, sunshiner);
   return sunshiner;
 }
@@ -647,11 +647,11 @@ void find_islandname(RgbImage *ri) {
     islandnamer.tl.y=                 128;
     islandnamer.br.y=                 156;
 
-    ADJUST_BOX(islandnamer,"o",5, 0,      MUST, tl,y,+1);
-    ADJUST_BOX(islandnamer,"o",5, cim->h, MUST, br,y,-1);
+    ADJUST_BOX(islandnamer,"o",>=,5, 0,      MUST, tl,y,+1);
+    ADJUST_BOX(islandnamer,"o",>=,5, cim->h, MUST, br,y,-1);
 
-    ADJUST_BOX(islandnamer,"o",1, 0,      MUST, tl,x,+1);
-    ADJUST_BOX(islandnamer,"o",1, cim->w, MUST, br,x,-1);
+    ADJUST_BOX(islandnamer,"o",>=,1, 0,      MUST, tl,x,+1);
+    ADJUST_BOX(islandnamer,"o",>=,1, cim->w, MUST, br,x,-1);
 
     debug_rect("islandnamer",0, islandnamer);
 //    int larger_islandnamebry= islandnamer.tl.y + 25;
@@ -671,7 +671,7 @@ void find_islandname(RgbImage *ri) {
       }
 
     identify_rgbimage(ri, islandnamer, archisland, "island");
-  } else if (!strcmp(sunshine,"Land - Ahoy")) {
+  } else if (!strcmp(sunshine,"Land - Ahoy!")) {
     Rect islandnamer;
 
     islandnamer.tl.x= (sunshiner.tl.x + sunshiner.br.x) / 2;
@@ -687,17 +687,18 @@ void find_islandname(RgbImage *ri) {
     require_rectangle_r(islandnamer, "O*", __LINE__);
 
     int rw= RECT_W(islandnamer);
-    ADJUST_BOX(islandnamer,"O",rw-4, cim->h, MUST,br,y,+1);
+    ADJUST_BOX(islandnamer,"O",>=,rw-4, cim->h, MUST,br,y,+1);
     debug_rect("islandnamer",__LINE__, islandnamer);
 
     islandnamer.br.y += 2;
-    ADJUST_BOX(islandnamer,"O",1,    cim->h, MUST,br,y,+1);
+    ADJUST_BOX(islandnamer,"O",>=,1,    cim->h, MUST,br,y,+1);
     debug_rect("islandnamer",__LINE__, islandnamer);
 
     islandnamer.tl.y= islandnamer.br.y-1;
     islandnamer.br.y= islandnamer.br.y+1;
-    ADJUST_BOX(islandnamer,"*",rw,   cim->h, MUST,br,y,+1);
-    ADJUST_BOX(islandnamer,"O",1,    cim->w, MUST,tl,x,+1);
+    int rh= RECT_H(islandnamer);
+    ADJUST_BOX(islandnamer,"*",>=,rw,   cim->h, MUST,br,y,+1);
+    ADJUST_BOX(islandnamer,"O",>=,rh,   cim->w, MUST,tl,x,+1);
     debug_rect("islandnamer",__LINE__, islandnamer);
 
     MUST( RECT_H(islandnamer) <= 31, MR(islandnamer));