int do_unloadmenu(_unit *u) { static _button b[3]; static int first = 1; static int oldmx, oldmy; if (first == 1) { oldmx = mouse_x; oldmy = mouse_y; if (u->load[0].loaded == 1) { b[0].init(502, 2, 135, 28, unit_name(u->load[0].type).c_str()); } else { b[0].init(502, 2, 135, 28, "-"); } if (u->load[1].loaded == 1) { b[1].init(502, 32, 135, 28, unit_name(u->load[1].type).c_str()); } else { b[1].init(502, 32, 135, 28, "-"); } b[2].init(502, 62, 135, 28, "Cancel"); position_mouse(570, 15); //set_mouse_range(500, 0, 640, 92); first = 0; } buffer_menuback(500, 0, 639, 92, DGREY, GREY, LGREY, 0.8); b[0].check(); b[1].check(); b[2].check(); if ((b[0].clicked()) && (b[0].get_text() != "-")) { //set_mouse_range(0, 0, 639, 479); position_mouse(oldmx, oldmy); first = 1; return 0; } if ((b[1].clicked()) && (b[1].get_text() != "-")) { //set_mouse_range(0, 0, 639, 479); position_mouse(oldmx, oldmy); first = 1; return 1; } if (b[2].clicked()) { //set_mouse_range(0, 0, 639, 479); position_mouse(oldmx, oldmy); first = 1; return 2; } return -1; }
//--------- Begin of function Unit::disp_basic_info ---------// // void Unit::disp_basic_info(int dispY1, int refreshFlag) { //------- display the name of the unit --------// if( refreshFlag == INFO_REPAINT ) { int dispName = unit_id == UNIT_CARAVAN || unit_res[unit_id]->unit_class == UNIT_CLASS_SHIP; // only display names for caravans and ships as their names are not displayed in the other part of the interface vga_util.d3_panel_up( INFO_X1, dispY1, INFO_X2, dispY1+21 ); if( nation_recno ) { int dispTitle = is_own() || nation_recno==0; // only display title for own units or independent units (which is for rebel leader only) if( dispName ) font_san.center_put( INFO_X1+21, dispY1, INFO_X2-2, dispY1+21, unit_name(dispTitle) ); vga_util.d3_panel_down( INFO_X1+3, dispY1+3, INFO_X1+20, dispY1+18 ); //------- display the nation color box -------// char *nationPict = image_button.get_ptr("V_COLCOD"); vga_front.put_bitmap_remap(INFO_X1+3, dispY1+2, nationPict, game.get_color_remap_table(nation_recno, 0) ); } else { if( dispName ) font_san.center_put( INFO_X1, dispY1, INFO_X2-2, dispY1+21, unit_name() ); } } dispY1+=23; //-------- display the hit points bar --------// if( refreshFlag == INFO_REPAINT ) { vga_util.d3_panel_up( INFO_X1, dispY1, INFO_X2, dispY1+27 ); if( nation_recno == nation_array.player_recno && can_resign()) { button_resign.paint( INFO_X1+4, dispY1+1, "V_X-U", "V_X-D" ); button_resign.set_help_code( "RESIGN" ); } } //-------- display hit points in numbers --------// disp_hit_point(dispY1); }
int do_unitmenu(int type, int tx, int ty, int pturn) { const int x = 160, y = 70; static bool first = true; static bool ok[MAX_UNITS]; //each ok[] corresponds to a unit type static _button items[15]; //maximum number of buttons possible at once is 15 static _button pos[9]; static int lastitem, unittype, buildpos; static bool limit, buildable[9]; bool drewbuildpos; char tempchar[30]; int i, j, bx, by; DyBytes data; if (first) { limit = false; i = 0; while (i < 9) { bx = tx + (i % 3) - 1; by = ty + (i / 3) - 1; buildable[i] = true; if ((bx < 0) || (bx >= worldmap.l)) buildable[i] = false; if ((by < 0) || (by >= worldmap.h)) buildable[i] = false; if (any_unit_here(bx, by) != -1) buildable[i] = false; i++; } buildpos = random_buildpos(&buildable[0]); i = 0; while (i < NUM_UNITS) { ok[i] = false; switch(type) { case BASE: if (unitstats[i].basetype == LAND) ok[i] = true; break; case AIRPORT: if (unitstats[i].basetype == AIR) ok[i] = true; break; case PORT: if (unitstats[i].basetype == SEA) ok[i] = true; break; } if (!unitstats[i].isarmy[player[pturn].number]) { //if the player's army can't build this unit ok[i] = false; } if (unitstats[i].techlevel > var.techlevel) { ok[i] = false; } i++; } if (player[pturn].units_in_play() >= 50) //if the player cannot make more units { i = 0; while (i < NUM_UNITS) { ok[i] = false; i++; } buffer_textout_ex(normal, "Unit Limit Reached", 50, 290, BLACK); limit = true; } i = 0; j = 0; while (i < NUM_UNITS) { if (ok[i]) { items[j].init(x + 30, y + 78 + (20 * j), 100, 15, unit_name(i)); j++; } i++; } items[j].init(x + 8, y + 10, 22, 22, ""); //close button lastitem = j; position_mouse(220, 195); j = 0; while (j < 3) { i = 0; while (i < 3) { pos[i + j * 3].init(x + 80 + 19 * i, y + 10 + 19 * j, 18, 18); i++; } j++; } first = false; } buffer_draw_sprite(glb.bmp(35), x, y, 0.9); if (!limit) { i = 0; while (i < 9) { if (buildable[i]) { pos[i].check(); if (pos[i].clicked()) { buildpos = i; } } else { buffer_rectfill(x + 80 + (i % 3) * 19, y + 10 + (i / 3) * 19, x + 98 + (i % 3) * 19, y + 28 + (i / 3) * 19, makecol(128, 0, 0), 0.75); } i++; } } drewbuildpos = false; j = 0; i = 0; while ((i < lastitem) && (!limit)) { items[i].check(); if (items[i].mouseover() == 1) { j = 1; unittype = unit_type(items[i].get_text()); buffer_textout_centre_ex(med, unit_name(unittype), x + 225, y + 35, BLACK, 0.7); sprintf(tempchar, "Price: %-1d", unit_price(unittype, player[pturn].number)); if (unit_price(unittype, player[pturn].number) <= player[pturn].cash) { buffer_textout_centre_ex(normal, tempchar, x + 225, y + 55, BLACK); } else { buffer_textout_centre_ex(normal, tempchar, x + 225, y + 55, RED); } bigunits.draw(unittype, x + 175, y + 95); multiline_textout_ex(normal, unitstats[unittype].description, x + 160, y + 215, 130, BLACK); bx = tx + (buildpos % 3) - 1; by = ty + (buildpos / 3) - 1; if ((any_unit_here(bx, by) == -1) && (bx >= 0) && (bx < worldmap.l) && (by >= 0) && (by < worldmap.h) && (moves_needed(unitstats[unittype].movetype, bx, by, pturn) < 99)) { //if the selected unit can be built on the selected tile buffer_rectfill(x + 80 + (buildpos % 3) * 19, y + 10 + (buildpos / 3) * 19, x + 98 + (buildpos % 3) * 19, y + 28 + (buildpos / 3) * 19, GREEN, 0.75); } else { buffer_rectfill(x + 80 + (buildpos % 3) * 19, y + 10 + (buildpos / 3) * 19, x + 98 + (buildpos % 3) * 19, y + 28 + (buildpos / 3) * 19, RED, 0.75); } drewbuildpos = true; } if (items[i].clicked()) { if (player[pturn].cash >= unit_price(unittype, player[pturn].number)) { bx = tx + (buildpos % 3) - 1; by = ty + (buildpos / 3) - 1; if (moves_needed(unitstats[unittype].movetype, bx, by, pturn) < 99) { if ((bx >= 0) && (bx < worldmap.l) && (by >= 0) && (by < worldmap.h) && (any_unit_here(bx, by) == -1)) { if (!global.netgame) { player[pturn].cash -= unit_price(unittype, player[pturn].number); player[pturn].create_unit(unittype, bx, by, pturn); player[pturn].stats.produced++; player[pturn].stats.spent += unit_price(unittype, player[pturn].number); } else { if (!net.server) { //if it's not the network host, it just sends a request for a new unit here data.clear(); data.addByte(NET_CLIENT_NEWUNIT); data.addByte(unittype); data.addByte(bx); data.addByte(by); send_datablob(net.thread, &data); } else { player[pturn].cash -= unit_price(unittype, player[pturn].number); player[pturn].create_unit(unittype, bx, by, pturn); player[pturn].stats.spent += unit_price(unittype, player[pturn].number); player[pturn].stats.produced++; data.clear(); data.addByte(NET_PLAYERCASH); data.addByte(pturn); data.appendVariable(player[pturn].cash); broadcast_datablob(&data); data.clear(); data.addByte(NET_NEWUNIT); data.addByte(pturn); data.addByte(unittype); data.addByte(bx); data.addByte(by); broadcast_datablob(&data); } } position_mouse(var.oldmx, var.oldmy); first = true; return 1; } } } } i++; } if ((!limit) && (!drewbuildpos)) { buffer_rectfill(x + 80 + (buildpos % 3) * 19, y + 10 + (buildpos / 3) * 19, x + 98 + (buildpos % 3) * 19, y + 28 + (buildpos / 3) * 19, WHITE, 0.75); } if (limit) { //the 50-unit limit has been hit buffer_textout_ex(normal, "Unit Limit Reached", x + 160, y + 215, RED); } items[lastitem].check(); if (items[lastitem].clicked()) //cancel button { //set_mouse_range(0, 0, 639, 479); position_mouse(var.oldmx, var.oldmy); first = true; return -1; } return 0; }
//--------- Begin of function Unit::disp_unit_profile ---------// // // <int> dispY1 - the top y coordination of the info area // <int> refreshFlag // void Unit::disp_unit_profile(int dispY1, int refreshFlag) { //--------- set help parameters --------// int x=INFO_X1+4; if( mouse.in_area(x, dispY1+3, x+UNIT_LARGE_ICON_WIDTH-1, dispY1+UNIT_LARGE_ICON_HEIGHT+2) ) help.set_unit_help( unit_id, rank_id, x, dispY1+3, x+UNIT_LARGE_ICON_WIDTH-1, dispY1+UNIT_LARGE_ICON_HEIGHT+2 ); //-----------------------------------------// if( refreshFlag != INFO_REPAINT ) // only display in repaint mode return; //-----------------------------------------// const char *str=NULL; if( race_id ) { if( rank_id == RANK_KING ) { str = _("King"); } else if( rank_id == RANK_GENERAL ) { // ##### patch begin Gilbert 17/2 #####// if( unit_mode == UNIT_MODE_REBEL ) str = _("Rebel Leader"); else str = _("General"); // ##### patch end Gilbert 17/2 #####// } else if( unit_mode == UNIT_MODE_DEFEND_TOWN ) { str = _("Defending Villager"); } else if( unit_mode == UNIT_MODE_REBEL ) { str = _("Rebel"); } else if( unit_res[unit_id]->unit_class == UNIT_CLASS_GOD ) { str = _("Greater Being"); } else { if( should_show_info() ) { switch( skill.skill_id ) { case SKILL_LEADING: str = _("Soldier"); break; case SKILL_CONSTRUCTION: str = _("Construction Worker"); break; case SKILL_MINING: str = _("Miner"); break; case SKILL_MFT: str = _("Worker"); break; case SKILL_RESEARCH: str = _("Scientist"); break; case SKILL_SPYING: str = _("Spy"); break; default: str = _("Peasant"); break; } } else //--- don't display too much info on enemy units ---// { if( skill.skill_id == SKILL_LEADING ) str = _("Soldier"); else if( is_civilian() ) str = _("Civilian"); } } } //---------------- paint the panel --------------// vga_util.d3_panel_up( INFO_X1, dispY1, INFO_X2, dispY1+44); vga_front.put_bitmap( x, dispY1+3, unit_res[unit_id]->get_large_icon_ptr(rank_id) ); //--------------------------------------// x += UNIT_LARGE_ICON_WIDTH; if( str ) { font_san.center_put( x, dispY1+4, INFO_X2-2, dispY1+21, str ); font_san.center_put( x, dispY1+22, INFO_X2-2, dispY1+40, unit_name(0) ); // 0-without title } else { font_san.center_put( x, dispY1, INFO_X2-2, dispY1+44, unit_name() ); // non-human units } }
/// pretty-print field information from a log structure void AP_Logger::dump_structure_field(const struct LogStructure *logstructure, const char *label, const uint8_t fieldnum) { ::fprintf(stderr, " %s (%s)*(%f)\n", label, unit_name(logstructure->units[fieldnum]), multiplier_name(logstructure->multipliers[fieldnum])); }