123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511 |
- /*
- * Seven Kingdoms: Ancient Adversaries
- *
- * Copyright 1997,1998 Enlight Software Ltd.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- //Filename : OINFOMIL.CPP
- //Description : Economy information screen
- #include <OVGA.h>
- #include <OFONT.h>
- #include <OSPY.h>
- #include <OIMGRES.h>
- #include <OUNITRES.h>
- #include <ORACERES.h>
- #include <OVBROWIF.h>
- #include <OBUTTON.h>
- #include <OF_CAMP.h>
- #include <ONATION.h>
- #include <OUNIT.h>
- #include <OINFO.h>
- //------------- Define coordinations -----------//
- enum { TROOP_BROWSE_X1 = ZOOM_X1+6,
- TROOP_BROWSE_Y1 = ZOOM_Y1+6,
- TROOP_BROWSE_X2 = ZOOM_X2-6,
- TROOP_BROWSE_Y2 = TROOP_BROWSE_Y1+240
- };
- enum { UNIT_BROWSE_X1 = ZOOM_X1+6,
- UNIT_BROWSE_Y1 = TROOP_BROWSE_Y2+6,
- UNIT_BROWSE_X2 = ZOOM_X2-6,
- UNIT_BROWSE_Y2 = ZOOM_Y2-6,
- };
- //----------- Define static variables ----------//
- static VBrowseIF browse_troop;
- static VBrowseIF browse_unit;
- //----------- Define static functions ----------//
- static void put_troop_rec(int recNo, int x, int y, int refreshFlag);
- static void put_unit_rec(int recNo, int x, int y, int refreshFlag);
- static int troop_filter(int recNo=0);
- static int unit_filter(int recNo=0);
- static void disp_troop_total();
- static void disp_unit_total();
- //--------- Begin of function Info::disp_military ---------//
- //
- void Info::disp_military(int refreshFlag)
- {
- //------- Display the Troop report -------//
- int x=TROOP_BROWSE_X1+9;
- int y=TROOP_BROWSE_Y1+4;
- vga_back.d3_panel_up(TROOP_BROWSE_X1, TROOP_BROWSE_Y1, TROOP_BROWSE_X2, TROOP_BROWSE_Y1+33 );
- #if(defined(FRENCH))
- font_san.put( x , y+7 , "Commander" );
- font_san.put( x+170, y+7, "Leadership" );
- font_san.put( x+275, y+7, "Loyalty" );
- font_san.put( x+350, y, "Points" );
- font_san.put( x+350, y+13, "de vie" );
- font_san.put( x+410, y+7, "Garnison" );
- font_san.put( x+480, y+7, "Status" );
- #elif(defined(GERMAN))
- font_san.put( x , y+7 , "Commander" );
- font_san.put( x+210, y+7 , "Leadership" );
- font_san.put( x+275, y+7 , "Loyalty" );
- font_san.put( x+342, y+7 , "Hit Points" );
- font_san.put( x+406, y , "Commanded" );
- font_san.put( x+415, y+13, "Soldiers" );
- font_san.put( x+485, y+7 , "Status" );
- #else
- font_san.put( x , y+7 , "Commander" );
- font_san.put( x+200, y+7 , "Leadership" );
- font_san.put( x+285, y+7 , "Loyalty" );
- font_san.put( x+342, y+7 , "Hit Points" );
- font_san.put( x+406, y , "Commanded" );
- font_san.put( x+423, y+13, "Soldiers" );
- font_san.put( x+490, y+7 , "Status" );
- #endif
- if( refreshFlag == INFO_REPAINT )
- {
- browse_troop.init( TROOP_BROWSE_X1, TROOP_BROWSE_Y1+35, TROOP_BROWSE_X2, TROOP_BROWSE_Y2-20,
- 0, 22, troop_filter(), put_troop_rec, 1 );
- browse_troop.open(browse_troop_recno);
- }
- else
- {
- browse_troop.paint();
- browse_troop.open(browse_troop_recno, troop_filter());
- }
- disp_troop_total();
- //------- Display the unit report -------//
- x=UNIT_BROWSE_X1+9;
- y=UNIT_BROWSE_Y1+4;
- vga_back.d3_panel_up(UNIT_BROWSE_X1, UNIT_BROWSE_Y1, UNIT_BROWSE_X2, UNIT_BROWSE_Y1+20 );
- font_san.put( x , y, "Unit Type" );
- font_san.put( x+300, y, "No. of Units" );
- if( refreshFlag == INFO_REPAINT )
- {
- browse_unit.init( UNIT_BROWSE_X1, UNIT_BROWSE_Y1+22, UNIT_BROWSE_X2, UNIT_BROWSE_Y2-20,
- 0, 16, unit_filter(), put_unit_rec, 1 );
- browse_unit.open(browse_unit_recno);
- }
- else
- {
- browse_unit.paint();
- browse_unit.open(browse_unit_recno, unit_filter());
- }
- disp_unit_total();
- }
- //----------- End of function Info::disp_military -----------//
- //--------- Begin of function Info::detect_military ---------//
- //
- void Info::detect_military()
- {
- //------- detect the troop report -------//
- if( browse_troop.detect() )
- {
- browse_troop_recno = browse_troop.recno();
- if( browse_troop.double_click )
- {
- Unit* unitPtr = unit_array[ troop_filter(browse_troop_recno) ];
- short xLoc, yLoc;
- if( unitPtr->get_cur_loc(xLoc, yLoc) )
- {
- world.go_loc(xLoc, yLoc, 1);
- }
- }
- }
- //------- detect the unit report -------//
- if( browse_unit.detect() )
- {
- browse_unit_recno = browse_unit.recno();
- }
- }
- //----------- End of function Info::detect_military -----------//
- //-------- Begin of static function disp_troop_total --------//
- static void disp_troop_total()
- {
- //---- count the total no. of soldiers ----//
- Unit* unitPtr;
- int totalSoldier=0, totalCommandedSoldier=0;
- int i;
- for( i=unit_array.size() ; i>0 ; i-- )
- {
- if( unit_array.is_deleted(i) )
- continue;
- unitPtr = unit_array[i];
- if( unitPtr->nation_recno != info.viewing_nation_recno )
- continue;
- if( unitPtr->rank_id == RANK_SOLDIER )
- totalSoldier++;
- else
- totalCommandedSoldier += unitPtr->commanded_soldier_count();
- }
- Nation* viewingNation = nation_array[info.viewing_nation_recno];
- for( i=viewingNation->ai_camp_count-1 ; i>=0 ; i-- )
- {
- totalSoldier += firm_array[ viewingNation->ai_camp_array[i] ]->worker_count;
- }
- //--------- paint the area ----------//
- int x=TROOP_BROWSE_X1+9;
- int y=TROOP_BROWSE_Y2-16;
- vga_back.d3_panel_up(TROOP_BROWSE_X1, TROOP_BROWSE_Y2-18, TROOP_BROWSE_X2, TROOP_BROWSE_Y2 );
- //------ display commander count ------//
- String str;
- if( browse_troop.total_rec() > 1 )
- str = "Total Commanders";
- else
- str = "Total Commander";
- str = translate.process(str);
- str += ": ";
- str += browse_troop.total_rec();
- font_san.put( x, y, str );
- //------ display soldiers under command count ------//
- if( totalCommandedSoldier > 1 )
- str = "Total Soldiers Under Command";
- else
- str = "Total Soldier Under Command";
- str = translate.process(str);
- str += ": ";
- str += totalCommandedSoldier;
- font_san.put( x+160, y, str );
- //------ display soldiers count ------//
- if( totalSoldier > 1 )
- str = "Total Soldiers";
- else
- str = "Total Soldier";
- str = translate.process(str);
- str += ": ";
- str += totalSoldier;
- #if(defined(FRENCH))
- font_san.put( x+396, y, str );
- #else
- font_san.put( x+410, y, str );
- #endif
- }
- //----------- End of static function disp_troop_total -----------//
- //-------- Begin of static function disp_unit_total --------//
- static void disp_unit_total()
- {
- int totalUnitCount=0, totalUnitCost=0;
- UnitInfo* unitInfo;
- for( int unitId=1 ; unitId<=MAX_UNIT_TYPE ; unitId++ )
- {
- unitInfo = unit_res[unitId];
- int unitCount = unitInfo->nation_unit_count_array[info.viewing_nation_recno-1];
- int generalCount = unitInfo->nation_general_count_array[info.viewing_nation_recno-1];
- totalUnitCount += unitCount;
- if( unitInfo->race_id )
- {
- totalUnitCost += generalCount * GENERAL_YEAR_SALARY;
- totalUnitCost += (unitCount-generalCount) * SOLDIER_YEAR_SALARY;
- }
- else
- totalUnitCost += unitCount * unitInfo->year_cost;
- }
- //--------- paint the area ----------//
- int x=UNIT_BROWSE_X1+9;
- int y=UNIT_BROWSE_Y2-16;
- vga_back.d3_panel_up(UNIT_BROWSE_X1, UNIT_BROWSE_Y2-18, UNIT_BROWSE_X2, UNIT_BROWSE_Y2 );
- String str;
- str = "Total Units";
- str = translate.process(str);
- str += ": ";
- str += totalUnitCount;
- font_san.put( x, y, str );
- }
- //----------- End of static function disp_unit_total -----------//
- //-------- Begin of static function troop_filter --------//
- //
- // This function has dual purpose :
- //
- // 1. when <int> recNo is not given :
- // - return the total no. of firms of this nation
- //
- // 2. when <int> recNo is given :
- // - return the firm recno in firm_array of the given recno.
- //
- static int troop_filter(int recNo)
- {
- int i, unitCount=0, totalUnit=unit_array.size();
- Unit* unitPtr;
- for( i=1 ; i<=totalUnit ; i++ )
- {
- if( unit_array.is_deleted(i) )
- continue;
- unitPtr = unit_array[i];
- if( unitPtr->nation_recno == info.viewing_nation_recno &&
- (unitPtr->rank_id==RANK_GENERAL || unitPtr->rank_id==RANK_KING) )
- {
- unitCount++;
- }
- if( recNo && unitCount==recNo )
- return i;
- }
- err_when( recNo ); // the recNo is not found, it is out of range
- return unitCount;
- }
- //----------- End of static function troop_filter -----------//
- //-------- Begin of static function put_troop_rec --------//
- //
- static void put_troop_rec(int recNo, int x, int y, int refreshFlag)
- {
- int unitRecno = troop_filter(recNo);
- Unit* unitPtr = unit_array[unitRecno];
- //---------- display bitmap ----------//
- x+=3;
- y+=3;
- vga_back.put_bitmap( x, y-2, unit_res[unitPtr->unit_id]->get_small_icon_ptr(unitPtr->rank_id) );
- //-------- display name & team size -------//
- y+=2;
- font_san.put( x+28 , y, unitPtr->unit_name(), 0, 238 );
- font_san.put( x+240, y, unitPtr->skill.get_skill(SKILL_LEADING) );
- if( unitPtr->rank_id != RANK_KING )
- font_san.put( x+295, y, unitPtr->loyalty );
- //--------- display hit points -----------//
- String str;
- str = (int) unitPtr->hit_points;
- str += "/";
- str += unitPtr->max_hit_points;
- font_san.put( x+352, y, str );
- //---- display the no. of soldiers led by this general ---//
- font_san.put( x+445, y, unitPtr->commanded_soldier_count() );
- //---- display the status of the general ----//
- char* statusStr;
- if( unitPtr->unit_mode == UNIT_MODE_OVERSEE )
- {
- int firmId = firm_array[ unitPtr->unit_mode_para ]->firm_id;
- if( firmId == FIRM_CAMP )
- statusStr = "In Fort";
- else if( firmId == FIRM_BASE )
- statusStr = "In Seat";
- else
- err_here();
- }
- else if( unitPtr->unit_mode == UNIT_MODE_ON_SHIP )
- {
- statusStr = "On Ship";
- }
- else
- {
- statusStr = "Mobile";
- }
- #if(defined(FRENCH))
- font_san.put( x+470, y, statusStr );
- #else
- // German and US
- font_san.put( x+486, y, statusStr );
- #endif
- }
- //----------- End of static function put_troop_rec -----------//
- //-------- Begin of static function unit_filter --------//
- //
- // This function has dual purpose :
- //
- // 1. when <int> recNo is not given :
- // - return the total no. of firms of this nation
- //
- // 2. when <int> recNo is given :
- // - return the firm recno in firm_array of the given recno.
- //
- static int unit_filter(int recNo)
- {
- int unitTypeCount=0;
- UnitInfo* unitInfo;
- //------- count human units -------//
- Nation* nationPtr = nation_array[info.viewing_nation_recno];
- unitTypeCount++;
- if( recNo && unitTypeCount==recNo )
- return -1;
- //------- count non-human unit types -------//
- for( int unitId=1 ; unitId<=MAX_UNIT_TYPE ; unitId++ )
- {
- unitInfo = unit_res[unitId];
- //---- if this is not a human unit -----//
- if( !unitInfo->race_id &&
- unitInfo->nation_unit_count_array[info.viewing_nation_recno-1] > 0 )
- {
- unitTypeCount++;
- }
- if( recNo && unitTypeCount==recNo )
- return unitId;
- }
- err_when( recNo ); // the recNo is not found, it is out of range
- return unitTypeCount;
- }
- //----------- End of static function unit_filter -----------//
- //-------- Begin of static function put_unit_rec --------//
- //
- static void put_unit_rec(int recNo, int x, int y, int refreshFlag)
- {
- int unitId = unit_filter(recNo);
- int unitCount;
- char* str;
- UnitInfo* unitInfo;
- Nation* nationPtr = nation_array[info.viewing_nation_recno];
- int rc = unit_filter(recNo);
- switch( rc )
- {
- //------- count human units -------//
- case -1:
- str = "Human General";
- unitCount = nationPtr->total_general_count;
- break;
- default:
- unitInfo = unit_res[rc];
- str = unitInfo->name;
- unitCount = unitInfo->nation_unit_count_array[ info.viewing_nation_recno-1 ];
- }
- //---------- display info --------//
- x+=3;
- y+=3;
- font_san.put( x , y, str );
- font_san.put( x+320, y, m.format(unitCount,1) );
- }
- //----------- End of static function put_unit_rec -----------//
|