//----------------------------------------------------------------------- // void DisplayArchiveMoveFolderList() { int printLine, index, lineHeight; appendToLogfile("DisplayArchiveMoveFolderList: Started.", WARNING); // Vertical spacing for each of the rows to display the list of target folders. lineHeight = 30; // Where in the list should we start the printing from. index = printMoveFolderLine; // Start the printing on the first row. printLine = 1; // Build the folder list in a memory screen region. TAP_Osd_PutGd( moveRgn, MOVE_WINDOW_X, MOVE_WINDOW_Y, &_popup476x416Gd, TRUE ); // Redisplay blank popup window to clear out old list. while ((index<=numberOfDestinationFolders) && (printLine<=MAX_MOVE_FOLDERS_SHOWN)) { if (index == chosenFolderLine) // If we're about to print the selected folder, print it with a different background. PrintLeft (moveRgn, MOVE_WINDOW_X+20, MOVE_WINDOW_Y+ 50 + (printLine * lineHeight), MOVE_WINDOW_X+MOVE_WINDOW_W-8, moveFiles[index]->name, MAIN_TEXT_COLOUR, HEADING_TEXT_COLOUR, FNT_Size_1926 ); else // If we're about to print a normal folder, print it with a normal background PrintLeft (moveRgn, MOVE_WINDOW_X+20, MOVE_WINDOW_Y+ 50 + (printLine * lineHeight), MOVE_WINDOW_X+MOVE_WINDOW_W-8, moveFiles[index]->name, MAIN_TEXT_COLOUR, 0, FNT_Size_1926 ); index++; // Increment the counter for the list. printLine++; // Increment the row counter. } // Print "+" indicators and top and/or bottom of the list to indicate if there are more files above/below in the list. // Check if there are some folders not shown at TOP of the list. if (printMoveFolderLine > 1) PrintLeft (moveRgn, MOVE_WINDOW_X+MOVE_WINDOW_W-30, MOVE_WINDOW_Y+ 50 + ((1) * lineHeight), MOVE_WINDOW_X+MOVE_WINDOW_W-8, "+", MAIN_TEXT_COLOUR, 0, FNT_Size_1926 ); // Check if there are some folders not shown at BOTTOM of the list. if (index <= numberOfDestinationFolders) // We've have't printed all of our list entries. PrintLeft (moveRgn, MOVE_WINDOW_X+MOVE_WINDOW_W-30, MOVE_WINDOW_Y+ 50 + ((printLine-1) * lineHeight), MOVE_WINDOW_X+MOVE_WINDOW_W-8, "+", MAIN_TEXT_COLOUR, 0, FNT_Size_1926 ); // Copy the screen region from memory to the real screen. This reduces any flicker when moving between rows. TAP_Osd_Copy( moveRgn, rgn, MOVE_WINDOW_X+20, MOVE_WINDOW_Y+50+(1*lineHeight), MOVE_WINDOW_W-20-8, (MAX_MOVE_FOLDERS_SHOWN*lineHeight), MOVE_WINDOW_X+20, MOVE_WINDOW_Y+50+(1*lineHeight), FALSE ); appendToLogfile("DisplayArchiveMoveFolderList: Finised.", WARNING); }
static int WriteOneColLine(int col) { CalEntry *e = CalColumn[col]; char const *s; char const *space; #ifdef REM_USE_WCHAR wchar_t const *ws; wchar_t const *wspace; #endif int numwritten = 0; /* Print as many characters as possible within the column */ #ifdef REM_USE_WCHAR if (e->wc_text) { wspace = NULL; ws = e->wc_pos; /* If we're at the end, and there's another entry, do a blank line and move to next entry. */ if (!*ws && e->next) { PrintLeft("", ColSpaces, ' '); CalColumn[col] = e->next; free((void *)e->text); free((void *)e->filename); if (e->wc_text) free((void *)e->wc_text); free(e); return 1; } /* Find the last space char within the column. */ while (ws - e->wc_pos <= ColSpaces) { if (!*ws) {wspace = ws; break;} if (iswspace(*ws)) wspace = ws; ws++; } /* Colorize reminder if necessary */ if (UseVTColors && e->is_color) { Colorize(e); } /* If we couldn't find a space char, print what we have. */ if (!wspace) { for (ws = e->wc_pos; ws - e->wc_pos < ColSpaces; ws++) { if (!*ws) break; numwritten++; PutWideChar(*ws); } e->wc_pos = ws; } else { /* We found a space - print everything before it. */ for (ws = e->wc_pos; ws<wspace; ws++) { if (!*ws) break; numwritten++; PutWideChar(*ws); } } /* Decolorize reminder if necessary */ if (UseVTColors && e->is_color) { Decolorize(); } /* Flesh out the rest of the column */ while(numwritten++ < ColSpaces) PutChar(' '); /* Skip any spaces before next word */ while (iswspace(*ws)) ws++; /* If done, free memory if no next entry. */ if (!*ws && !e->next) { CalColumn[col] = e->next; free((void *)e->text); free((void *)e->filename); if (e->wc_text) free((void *)e->wc_text); free(e); } else { e->wc_pos = ws; } if (CalColumn[col]) return 1; else return 0; } else { #endif space = NULL; s = e->pos; /* If we're at the end, and there's another entry, do a blank line and move to next entry. */ if (!*s && e->next) { PrintLeft("", ColSpaces, ' '); CalColumn[col] = e->next; free((void *)e->text); free((void *)e->filename); #ifdef REM_USE_WCHAR if (e->wc_text) free((void *)e->wc_text); #endif free(e); return 1; } /* Find the last space char within the column. */ while (s - e->pos <= ColSpaces) { if (!*s) {space = s; break;} if (*s == ' ') space = s; s++; } /* Colorize reminder if necessary */ if (UseVTColors && e->is_color) { Colorize(e); } /* If we couldn't find a space char, print what we have. */ if (!space) { for (s = e->pos; s - e->pos < ColSpaces; s++) { if (!*s) break; numwritten++; PutChar(*s); } e->pos = s; } else { /* We found a space - print everything before it. */ for (s = e->pos; s<space; s++) { if (!*s) break; numwritten++; PutChar(*s); } } /* Decolorize reminder if necessary */ if (UseVTColors && e->is_color) { Decolorize(); } /* Flesh out the rest of the column */ while(numwritten++ < ColSpaces) PutChar(' '); /* Skip any spaces before next word */ while (*s == ' ') s++; /* If done, free memory if no next entry. */ if (!*s && !e->next) { CalColumn[col] = e->next; free((void *)e->text); free((void *)e->filename); #ifdef REM_USE_WCHAR if (e->wc_text) free((void *)e->wc_text); #endif free(e); } else { e->pos = s; } if (CalColumn[col]) return 1; else return 0; #ifdef REM_USE_WCHAR } #endif }
static void DoCalendarOneWeek(nleft) { int y, m, d, done, i, l, wd; char buf[81]; int LinesWritten = 0; int OrigJul = JulianToday; /* Fill in the column entries */ for (i=0; i<7; i++) { GenerateCalEntries(i); JulianToday++; } /* Output the entries */ /* If it's "Simple Calendar" format, do it simply... */ if (DoSimpleCalendar) { if (MondayFirst) wd = JulianToday % 7; else wd = (JulianToday + 1) % 7; for (i=0; i<7; i++) { WriteSimpleEntries(i, OrigJul+i-wd); } return; } /* Here come the first few lines... */ gon(); DRAW(tb); goff(); for (i=0; i<7; i++) { FromJulian(OrigJul+i, &y, &m, &d); sprintf(buf, "%d %c%c%c ", d, MonthName[m][0], MonthName[m][1], MonthName[m][2]); if (OrigJul+i == RealToday) PrintLeft(buf, ColSpaces, '*'); else PrintLeft(buf, ColSpaces, ' '); gon(); DRAW(tb); goff(); } PutChar('\n'); for (l=0; l<CalPad; l++) { gon(); DRAW(tb); goff(); for (i=0; i<7; i++) { PrintLeft("", ColSpaces, ' '); gon(); DRAW(tb); goff(); } PutChar('\n'); } /* Write the body lines */ done = 0; while (!done) { done = WriteOneCalLine(); LinesWritten++; } /* Write any blank lines required */ while (LinesWritten++ < CalLines) { gon(); DRAW(tb); goff(); for (i=0; i<7; i++) { PrintLeft("", ColSpaces, ' '); gon(); DRAW(tb); goff(); } PutChar('\n'); } /* Write the final line */ if (nleft) { WriteIntermediateCalLine(); } else { WriteBottomCalLine(); } }
static int WriteCalendarRow(void) { int y, m, d, wd, i, l; int done; char buf[81]; int OrigJul = JulianToday; int LinesWritten = 0; int moreleft; /* Get the date of the first day */ FromJulian(JulianToday, &y, &m, &d); if (!MondayFirst) wd = (JulianToday + 1) % 7; else wd = JulianToday % 7; /* Fill in the column entries */ for (i=wd; i<7; i++) { if (d+i-wd > DaysInMonth(m, y)) break; GenerateCalEntries(i); JulianToday++; } /* Output the entries */ /* If it's "Simple Calendar" format, do it simply... */ if (DoSimpleCalendar) { for (i=wd; i<7 && d+i-wd<=DaysInMonth(m, y); i++) { WriteSimpleEntries(i, OrigJul+i-wd); } return (d+7-wd <= DaysInMonth(m, y)); } /* Here come the first few lines... */ gon(); DRAW(tb); goff(); for (i=0; i<7; i++) { if (i < wd || d+i-wd>DaysInMonth(m, y)) PrintLeft("", ColSpaces, ' '); else { sprintf(buf, "%d", d+i-wd); PrintLeft(buf, ColSpaces, ' '); } gon(); DRAW(tb); goff(); } PutChar('\n'); for (l=0; l<CalPad; l++) { gon(); DRAW(tb); goff(); for (i=0; i<7; i++) { PrintLeft("", ColSpaces, ' '); gon(); DRAW(tb); goff(); } PutChar('\n'); } /* Write the body lines */ done = 0; while (!done) { done = WriteOneCalLine(); LinesWritten++; } /* Write any blank lines required */ while (LinesWritten++ < CalLines) { gon(); DRAW(tb); goff(); for (i=0; i<7; i++) { PrintLeft("", ColSpaces, ' '); gon(); DRAW(tb); goff(); } PutChar('\n'); } moreleft = (d+7-wd <= DaysInMonth(m, y)); if (moreleft) { WriteIntermediateCalLine(); } else { WriteBottomCalLine(); } /* Return non-zero if we have not yet finished */ return moreleft; }
void AI(void) { //Makes appropriate moves for the computer by analysing certain factors if(won || lost) { return; } working=true; turn=0; strphase="Defense Phase"; PrintPhase(); for(int i=0;i<NCountry;i++) { if(all[i].ownership==1 || all[i].nos==1) continue; int sum=0; for(int j=0;j<all[i].non;j++) { if(all[all[i].neigh[j]].ownership==0) continue; if(getNOppNeighbours(all[i].neigh[j])>all[all[i].neigh[j]].nos+6 ) { multipleAttackAI(all[i].neigh[j]); AI(); return; } if(all[i].nos>all[all[i].neigh[j]].nos+4 && willBeBlocked(i,all[i].neigh[j])==false) { attack(i,all[i].neigh[j]); //attack if no. of soldiers is more by 4 in the attacker country and comp is not getting blocked //after the attack if(aimode==false) { AI(); } return; } sum+=all[all[i].neigh[j]].nos; } //sum contains total number of opponent soldiers in the neighbourhood if(sum!=0 && (((float)all[i].nos)/sum)>=0.5 ) { for(int j=0;j<all[i].non;j++) { if(all[all[i].neigh[j]].ownership==1 && all[i].nos>=all[all[i].neigh[j]].nos && willBeBlocked(i,all[i].neigh[j])==false) { attack(i,all[i].neigh[j]); if(aimode==false) { AI(); } return; } } } } refresh(); strphase="Reinforcement Phase"; PrintPhase(); int reinf=reinforcement(0); // refresh2(); aireinforce(reinf); refresh2(); usleep(100000); //transfers int co,ci; // country pair with maximum sum of no. of opponent soldiers as neighbours of ci -(minus) that for co if(getMaxNCountry(co,ci,1) && co>=0 && co<=42 && ci>=0 && ci<=42 && all[co].nos>1) { // get country pair with maximum (sum of no. of opponent soldiers as neighbours of ci -(minus) that for co) // and transfer maximum possible sodiers from co to ci PrintLeft("Transferring soldiers from " + all[co].name+ " to " + all[ci].name); highlight(co); flush(); usleep(300000); highlight(ci); flush(); usleep(300000); createTriangle(Red,co,ci); flush(); sleep(1); transfer(co,ci,all[co].nos-1); refresh(); } working=false; turn=1; focus=1; c1=-1;c2=-1; strphase="Attack Phase"; PrintLeft("Computer's turn is over. Your chance... "); //being ready for player 1's attack phase showmsg.msg="Computer's Reinforcement Phase is over. ^ It's Your turn...^ Attack Phase Begins "; PrintRein(); showmsg.show(); PrintPhase(); return; }