X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=pctb%2Fstructure.c;h=466c46624dda89ce1dafcf2fef8178ba3ddc2bab;hb=0cc60c89bb2ee51d5313ec54e63157b11f399633;hp=0c9750c5f5bd45c4222db71686816dee5b86b464;hpb=9c4bd3b7b5dde4ec8f37ffde2793437a299b3f2b;p=ypp-sc-tools.main.git diff --git a/pctb/structure.c b/pctb/structure.c index 0c9750c..466c466 100644 --- a/pctb/structure.c +++ b/pctb/structure.c @@ -34,7 +34,7 @@ static inline char get_p(Point p) { return get(p.x,p.y); } DEBUG_DEFINE_DEBUGF(struct) -#define START_MAIN {200,100} +#define START_MAIN {200,200} #define MIN_COLUMNS 6 #define INTERESTING_COLUMNS 7 #define TEXT_COLUMNS 2 @@ -46,6 +46,8 @@ static int colrightx[INTERESTING_COLUMNS]; static int text_h=-1, columns=-1; static OcrReader *rd; +char *archipelago, *island; + #define OTHERCOORD_x y #define OTHERCOORD_y x @@ -56,6 +58,7 @@ const CanonColourInfo canoncolourinfos[]= { { 0x6B828C, '*' }, /* background of ship status meter area */ { 0x934405, '*' }, /* border of ship meter area */ { 0x7D9094, '+' }, /* interbox */ + { 0x022158, 'a' }, /* ahoy /w output foreground */ { 0xBDC5BF, ' ' }, /* background - pale Sugar cane, etc. */ { 0xADB5AF, ' ' }, /* background - dark */ @@ -154,6 +157,32 @@ static void debug_rect(const char *what, int whati, Rect rr) { debug_flush(); } +static int commod_selector_matches(Rect search, const char *const *all, + int allh, int allw) { + int alloffy, alloffx; + for (alloffy=0; alloffy < search.br.y; alloffy++) { + if (alloffy+allh-1 < search.tl.y) continue; + for (alloffx=search.tl.x; alloffx+allw-1 <= search.br.x; alloffx++) { + int good=0, bad=0; + int x,y; + for (x=0; x 20*bad) + return 1; + } + } + return 0; +} + #define WALK_UNTIL(point,coord,increm,last,edge) \ for (;;) { \ if ((point).coord == (last)+(increm)) break; \ @@ -288,7 +317,7 @@ void check_correct_commodities(void) { debug_rect("commodselr",1, search); - static const char *all[]= { + static const char *all_small[]= { " ___________________________________ ", " ________X____X__X____________________ ", " ________ X___ X_ X_____XXXXXXXXXXX_____ ", @@ -301,34 +330,30 @@ void check_correct_commodities(void) { " ____X_____ _XX_ X______________________", " __ _______ __ ______________________ ", }; + static const char *all_big[]= { + "???_______________________________________???", + "??_________________________________________??", + "?_________X______X___X______________________?", + "_________?X_____?X__?X______XXXXXXXXXXX______", + "_________X_X____?X__?X_______XXXXXXXXX_______", + "________?X?X____?X__?X________XXXXXXX________", + "________X_?_X___?X__?X_________XXXXX_________", + "_______?X__?X___?X__?X__________XXX__________", + "_______?XXXXX___?X__?X___________X___________", + "_______X????_X__?X__?X_______________________", + "?_____?X____?X__?X__?X_______________________", + "??____X_____?_X_?X__?X_______________________", + "???__?_______?__?___?_______________________?", + }; - static int allh= sizeof(all)/sizeof(all[0]); - const int allw= strlen(all[0]); +#define COMMOD_SELECTOR_MATCHES(all) \ + commod_selector_matches(search, all, \ + sizeof((all))/sizeof((all)[0]), \ + strlen((all)[0])) - int alloffy, alloffx; - for (alloffy=0; alloffy < search.br.y; alloffy++) { - if (alloffy+allh-1 < search.tl.y) continue; - for (alloffx=search.tl.x; alloffx+allw-1 <= search.br.x; alloffx++) { - int good=0, bad=0; - int x,y; - for (x=0; x 20*bad) - goto all_found; - } - } - fatal("Commodities selector not set to `All'."); - - all_found:; + if (!(COMMOD_SELECTOR_MATCHES(all_small) || + COMMOD_SELECTOR_MATCHES(all_big))) + fatal("Commodities selector not set to `All'."); } CanonImage *alloc_canon_image(int w, int h) { @@ -468,6 +493,8 @@ void analyse(FILE *tsv_output) { if (!rd) rd= ocr_init(text_h); + progress("Scanning page %d...",page); + for (tryrect= +cim->h; tryrect >= -cim->h; tryrect--) { find_commodity(tryrect, &thisr); if (thisr.tl.x < 0) @@ -490,6 +517,7 @@ void analyse(FILE *tsv_output) { sysassert(!fflush(tsv_output)); } } + progress("Commodity table scan complete."); } //static Rect islandnamer; @@ -528,9 +556,8 @@ void find_islandname(void) { debug_rect("sunshiner",1, sunshiner); identify_rgbimage(ri, sunshiner, sunshine, "sunshine widget"); - fprintf(stderr,"sunshine: `%s'\n",sunshine); - if (!memcmp(sunshine,"Ship ",5)) { + if (!memcmp(sunshine,"Vessel ",5)) { Rect islandnamer; islandnamer.tl.x= cim->w - 1034 + 885; @@ -538,11 +565,11 @@ void find_islandname(void) { islandnamer.tl.y= 128; islandnamer.br.y= 156; -#define IR_VSHRINK_MUST(CONDMUST,PRWHY) \ - do{ if (!(CONDMUST)) goto not_in_radar; }while(0) + 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, IR_VSHRINK_MUST, tl,y,+1); - ADJUST_BOX(islandnamer,"o",5, cim->h, IR_VSHRINK_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); debug_rect("islandnamer",0, islandnamer); // int larger_islandnamebry= islandnamer.tl.y + 25; @@ -562,15 +589,14 @@ void find_islandname(void) { } identify_rgbimage(ri, islandnamer, archisland, "island"); - fprintf(stderr,"radar: `%s'\n",archisland); - - assert(!"radar ok"); - - not_in_radar: - assert(!"not in radar?"); } else { assert(!"not vessel"); } + char *delim= strstr(archisland," - "); + assert(delim); + archipelago= masprintf("%.*s", delim-archisland, archisland); + island= masprintf("%s", delim+3); + free(ri); }