void CampaignEastWest::plot_d1_create_game() { // reduce cash (~nation_array)->cash = (~nation_array)->cash / 4; // reduce mineral if the mine is owned by the player for( int i = 1; i <= site_array.size(); ++i ) { if( site_array.is_deleted(i) ) continue; Site *sitePtr = site_array[i]; if( sitePtr->site_type == SITE_RAW && sitePtr->has_mine ) { Location *locPtr = world.get_loc(sitePtr->map_x_loc, sitePtr->map_y_loc); err_when( !locPtr->is_firm() ); Firm *firmPtr = firm_array[locPtr->firm_recno()]; if( firmPtr->is_own() ) { sitePtr->reserve_qty = sitePtr->reserve_qty / 10; if( firmPtr->cast_to_FirmMine() ) { firmPtr->cast_to_FirmMine()->reserve_qty = (float)sitePtr->reserve_qty; } else if( firmPtr->cast_to_FirmMonsterAlchemy() ) { firmPtr->cast_to_FirmMonsterAlchemy()->reserve_qty = (float)sitePtr->reserve_qty; } } } } }
//--------- Begin of function UnitCaravan::disp_stop ---------// // void UnitCaravan::disp_stop(int dispY1, int refreshFlag) { int y = INFO_Y1 + 94; int i, j; for( i = 0; i < MAX_STOP_FOR_CARAVAN; ++i, y += 70 ) { TradeStop *tradeStop = stop_array+i; button_go_stop[i].create( INFO_X1+17, y+2, INFO_X1+167, y+35, i_button_go_stop, ButtonCustomPara( this, tradeStop->firm_recno ) ); button_go_stop[i].set_help_code( "CGOSTOP" ); button_set_stop[i].create( INFO_X1+169, y+2, INFO_X1+215, y+20, i_button_set_stop, ButtonCustomPara( NULL, 0 ) ); button_set_stop[i].set_help_code( "CSETSTOP" ); button_cancel_stop[i].create( INFO_X1+169, y+21, INFO_X1+215, y+39, i_button_cancel_stop, ButtonCustomPara( NULL, 0 ) ); button_cancel_stop[i].set_help_code( "CDELSTOP" ); button_reset_stop[i].create( INFO_X1+169, y+42, INFO_X1+215, y+60, i_button_reset_stop, ButtonCustomPara( NULL, 0 ) ); button_reset_stop[i].set_help_code( "CCLRSEL" ); for( j = 0; j < MAX_GOODS_SELECT_BUTTON; ++j ) button_select_array[i][j].create( INFO_X1+17+carv_gdd_x[j], y+34, INFO_X1+17+carv_gdd_x[j+1]-1, y+61, i_disp_caravan_select_button, ButtonCustomPara( NULL, j ), 0 ); button_go_stop[i].custom_para = ButtonCustomPara( this, tradeStop->firm_recno ); button_go_stop[i].paint(); button_set_stop[i].paint(); button_cancel_stop[i].paint(); button_reset_stop[i].paint(); Firm *firmPtr = NULL; if( !firm_array.is_deleted(tradeStop->firm_recno)) firmPtr = firm_array[tradeStop->firm_recno]; for( j = 0; j < MAX_GOODS_SELECT_BUTTON; ++j ) { // display quantity on the firm int rawId = j+FIRST_GOODS_SELECT_BUTTON-PICK_UP_RAW_FIRST+1; if( rawId < 1 || rawId > MAX_RAW ) rawId = 0; int productId = j+FIRST_GOODS_SELECT_BUTTON-PICK_UP_PRODUCT_FIRST+1; if( productId < 1 || productId > MAX_PRODUCT ) productId = 0; int stock = -1; if( firmPtr ) { if( firmPtr->cast_to_FirmMarket() ) { MarketGoods *marketGoods; if( rawId ) { marketGoods = firmPtr->cast_to_FirmMarket()->market_raw_array(rawId); err_when( marketGoods && marketGoods->raw_id != rawId ); } else if( productId ) { marketGoods = firmPtr->cast_to_FirmMarket()->market_product_array(productId); err_when( marketGoods && marketGoods->product_raw_id != productId ); } else { err_here(); marketGoods = NULL; } if( marketGoods ) stock = (int) marketGoods->stock_qty; } else if( firmPtr->cast_to_FirmMine() ) { if( rawId && firmPtr->cast_to_FirmMine()->raw_id == rawId ) { stock = (int) firmPtr->cast_to_FirmMine()->stock_qty; } } else if( firmPtr->cast_to_FirmFactory() ) { if( productId && firmPtr->cast_to_FirmFactory()->product_raw_id == productId ) { stock = (int) firmPtr->cast_to_FirmFactory()->stock_qty; } //else if( rawId && firmPtr->cast_to_FirmFactory()->product_raw_id == rawId ) //{ // stock = (int) firmPtr->cast_to_FirmFactory()->raw_stock_qty; //} } } if( stock >= 0 ) { // display button button_select_array[i][j].enable_flag = 1; button_select_array[i][j].paint( tradeStop->pick_up_array[j] ); } else { button_select_array[i][j].enable_flag = 0; button_select_array[i][j].pushed_flag = tradeStop->pick_up_array[j]; } } } }
//--------- Begin of function UnitArray::draw_dot ---------// // // Draw 2x2 tiny squares on map window representing the location of the unit ---// // // [int] filterUnitClassId - if given, only display units whose type is filterUnitClassId // void UnitArray::draw_dot(int filterUnitClassId) { int i, j, mapX, mapY; short nationColor; int vgaBufPitch = vga_back.buf_pitch(); short playerNationRecno = nation_array.player_recno; short lineFromX, lineFromY, lineToX, lineToY; short unexploredColor = vga_back.translate_color(UNEXPLORED_COLOR); short nationColorArray[MAX_NATION+1]; for( int n = 0; n < MAX_NATION+1; ++n ) nationColorArray[n] = vga_back.translate_color(nation_array.nation_color_array[n]); // ##### begin Gilbert 2/11 ######// short excitedColorArray[MAX_NATION+1]; //[excitedColorCount]; short slowExcitedColorArray[MAX_NATION+1]; //[excitedColorCount]; for( i = 0; i <= MAX_NATION; ++i ) { if( i == 0 || !nation_array.is_deleted(i) ) { short *remapTable = game.get_color_remap_table(i, 0); excitedColorArray[i] = remapTable[0xe0 + (sys.frame_count % 4)]; slowExcitedColorArray[i] = remapTable[0xe0 + (sys.frame_count % 8)/2]; } else { excitedColorArray[i] = slowExcitedColorArray[i] = vga_back.translate_color(V_WHITE); } } // ##### end Gilbert 2/11 ######// int arraySize = size(); //------------- set boundary of anim_line to mini-map ------------// short animLineBoundX1 = anim_line.bound_x1; short animLineBoundY1 = anim_line.bound_y1; short animLineBoundX2 = anim_line.bound_x2; short animLineBoundY2 = anim_line.bound_y2; anim_line.bound_x1 = MAP_X1; anim_line.bound_y1 = MAP_Y1; anim_line.bound_x2 = MAP_X2; anim_line.bound_y2 = MAP_Y2; // #### begin Gilbert 29/1 ########// int showAttackerPath = nation_array.player_recno && god_res[GOD_JAPANESE]->nation_prayer_count(nation_array.player_recno); int playerNation = nation_array.player_recno; // #### end Gilbert 29/1 ########// for(i=1; i<=arraySize; i++) { register Unit *unitPtr = (Unit*)get_ptr(i); if( !unitPtr || !unitPtr->is_visible() || unitPtr->is_stealth() ) continue; int lineColor = TRANSPARENT_CODE; if( !unitPtr->selected_flag ) // if the unit is currently selected, ignore the filters { if( filterUnitClassId && unit_res[unitPtr->unit_id]->unit_class != filterUnitClassId ) continue; // draw only caravan in trade mode if( world.map_matrix->map_mode == MAP_MODE_TRADE && unitPtr->unit_id != UNIT_CARAVAN ) continue; // filter selected nation if( world.map_matrix->filter_nation_flag && world.map_matrix->filter_nation_recno != unitPtr->nation_recno ) continue; } //---------------- draw unit path in mini_map ------------// if( (config.show_unit_path & 2) && unitPtr->selected_flag && (config.show_ai_info || !playerNation || unitPtr->is_nation(playerNation)) && unitPtr->cur_action != SPRITE_IDLE) { if( unitPtr->mobile_type == UNIT_SEA ) lineColor = V_WHITE; else lineColor = V_BLACK; } // ------ show unit targeting our nation ----------// else if( showAttackerPath && unitPtr->cur_order.mode == UNIT_ATTACK && unitPtr->cur_action != SPRITE_ATTACK // if already attack, not need to show path && !base_obj_array.is_deleted(unitPtr->cur_order.para) && base_obj_array[unitPtr->cur_order.para]->nation_recno == playerNation ) { lineColor = VGA_RED; } if( lineColor != TRANSPARENT_CODE ) { //-----------------------------------------------------------// if(unitPtr->cur_x_loc()!=unitPtr->go_x_loc() || unitPtr->cur_y_loc()!=unitPtr->go_y_loc()) { lineToX = world.map_matrix->calc_loc_pos_x(unitPtr->go_x_loc(), unitPtr->go_y_loc()) + MAP_X1; lineToY = world.map_matrix->calc_loc_pos_y(unitPtr->go_x_loc(), unitPtr->go_y_loc()) + MAP_Y1; lineFromX = world.map_matrix->calc_loc_pos_x(unitPtr->next_x_loc(), unitPtr->next_y_loc()) + MAP_X1; lineFromY = world.map_matrix->calc_loc_pos_y(unitPtr->next_x_loc(), unitPtr->next_y_loc()) + MAP_Y1; vga_back.line(lineFromX, lineFromY, lineToX, lineToY, lineColor); } //-----------------------------------------------------------// if( unitPtr->cur_path && unitPtr->cur_path_result_id > 0 ) { int locFromX, locFromY, locToX, locToY; locFromX = unitPtr->go_x_loc(); locFromY = unitPtr->go_y_loc(); for( j=unitPtr->cur_path_result_id ; j>0 ; j-- ) { PathResult* pathResult = unitPtr->cur_path + j - 1; locToX = pathResult->loc_x; locToY = pathResult->loc_y; lineFromX = world.map_matrix->calc_loc_pos_x(locFromX, locFromY) + MAP_X1; lineFromY = world.map_matrix->calc_loc_pos_y(locFromX, locFromY) + MAP_Y1; lineToX = world.map_matrix->calc_loc_pos_x(locToX, locToY) + MAP_X1; lineToY = world.map_matrix->calc_loc_pos_y(locToX, locToY) + MAP_Y1; vga_back.line(lineFromX, lineFromY, lineToX, lineToY, lineColor); locFromX = locToX; locFromY = locToY; } } } } //---------------- restore boundary setting of anim_line --------------// anim_line.bound_x1 = animLineBoundX1; anim_line.bound_y1 = animLineBoundY1; anim_line.bound_x2 = animLineBoundX2; anim_line.bound_y2 = animLineBoundY2; for(i=1; i<=arraySize; i++) { // #### begin Gilbert 3/11 ######// int dotSize; { // minimize register variable at one time register Unit *unitPtr = (Unit*)get_ptr(i); if( !unitPtr || !unitPtr->is_visible() || unitPtr->is_stealth()) continue; if( !unitPtr->selected_flag ) // if the unit is currently selected, ignore the filters { // draw only caravan in trade mode if( world.map_matrix->map_mode == MAP_MODE_TRADE && unitPtr->unit_id != UNIT_CARAVAN ) continue; if( filterUnitClassId && unit_res[unitPtr->unit_id]->unit_class != filterUnitClassId ) continue; // filter selected nation if( world.map_matrix->filter_nation_flag && world.map_matrix->filter_nation_recno != unitPtr->nation_recno ) continue; } //---------------------------------// if( world.map_matrix->map_mode != MAP_MODE_TRADE ) { if( unitPtr->cur_action == SPRITE_ATTACK ) nationColor = excitedColorArray[unitPtr->nation_recno]; else if( unitPtr->selected_flag ) nationColor = slowExcitedColorArray[unitPtr->nation_recno]; else nationColor = nationColorArray[unitPtr->nation_recno]; } else { // if selected firm is mine, factory or market, // caravan linked to it flashes err_when( MAX_STOP_FOR_CARAVAN != 2 ); // current code check only two stops Firm *firmPtr; if( firm_array.selected_recno && (firmPtr = firm_array[firm_array.selected_recno]) && (firmPtr->cast_to_FirmMine() || firmPtr->cast_to_FirmFactory() || firmPtr->cast_to_FirmMarket()) && ( ((UnitCaravan *)unitPtr)->stop_array[0].firm_recno == firm_array.selected_recno || ((UnitCaravan *)unitPtr)->stop_array[1].firm_recno == firm_array.selected_recno) ) { nationColor = slowExcitedColorArray[unitPtr->nation_recno]; } else { nationColor = nationColorArray[unitPtr->nation_recno]; } } mapX = world.map_matrix->calc_loc_pos_x(unitPtr->cur_x_loc(), unitPtr->cur_y_loc()) + MAP_X1; mapY = world.map_matrix->calc_loc_pos_y(unitPtr->cur_x_loc(), unitPtr->cur_y_loc()) + MAP_Y1; dotSize = unitPtr->mobile_type == UNIT_LAND ? 2 : 3; } { // minimize register variable at one time register short *writePtr = vga_back.buf_ptr(mapX, mapY); if( dotSize == 2 ) { if( writePtr[0] != unexploredColor ) writePtr[0] = nationColor; if( writePtr[1] != unexploredColor ) writePtr[1] = nationColor; if( writePtr[vgaBufPitch] != unexploredColor ) writePtr[vgaBufPitch] = nationColor; if( writePtr[vgaBufPitch+1] != unexploredColor ) writePtr[vgaBufPitch+1] = nationColor; } else if( dotSize == 3 ) { if( writePtr[-vgaBufPitch-1] != unexploredColor ) writePtr[-vgaBufPitch-1] = nationColor; if( writePtr[-vgaBufPitch] != unexploredColor ) writePtr[-vgaBufPitch] = nationColor; if( writePtr[-vgaBufPitch+1] != unexploredColor ) writePtr[-vgaBufPitch+1] = nationColor; if( writePtr[-1] != unexploredColor ) writePtr[-1] = nationColor; if( writePtr[0] != unexploredColor ) writePtr[0] = nationColor; if( writePtr[1] != unexploredColor ) writePtr[1] = nationColor; if( writePtr[vgaBufPitch-1] != unexploredColor ) writePtr[vgaBufPitch-1] = nationColor; if( writePtr[vgaBufPitch] != unexploredColor ) writePtr[vgaBufPitch] = nationColor; if( writePtr[vgaBufPitch+1] != unexploredColor ) writePtr[vgaBufPitch+1] = nationColor; } } // #### end Gilbert 3/11 ######// } //end for }
//--------- Begin of function Nation::seek_mine --------// // // <short&> xLoc, yLoc - reference vars for returning the building // location. // <short&> refXLoc, refYLoc - reference vars for returning the exact // location of the raw material. // // return: <int> >0 the raw id. of the site. // ==0 no suitable site found. // int Nation::seek_mine(short& xLoc, short& yLoc, short& refXLoc, short& refYLoc) { err_when( site_array.untapped_raw_count < 0 ); if( site_array.untapped_raw_count==0 ) return 0; int raw_kind_mined[MAX_RAW], i; Firm *firmPtr; FirmMine *minePtr; //-----------------------------------------------------------------// // count each kind of raw material that is being mined //-----------------------------------------------------------------// memset(raw_kind_mined, 0, sizeof(int)*MAX_RAW); for(i=0; i<ai_mine_count; i++) { firmPtr = firm_array[ai_mine_array[i]]; minePtr = firmPtr->cast_to_FirmMine(); if( minePtr->raw_id>=1 && minePtr->raw_id<=MAX_RAW ) raw_kind_mined[minePtr->raw_id-1]++; } //-------------------- define parameters ----------------------// FirmInfo *firmInfo = firm_res[FIRM_MINE]; Location *locPtr, *siteLocPtr; Site *sitePtr; Town *townPtr; int nearSite[MAX_RAW], minDist[MAX_RAW], townWithMine[MAX_RAW]; short buildXLoc[MAX_RAW], buildYLoc[MAX_RAW]; short dist; int canBuild, connected, allHave; int j, k, siteId; int effectiveDis = world.effective_distance(FIRM_MINE,0); memset(townWithMine, 0, sizeof(int)*MAX_RAW); memset(nearSite, 0, sizeof(int)*MAX_RAW); memset(buildXLoc, 0, sizeof(short)*MAX_RAW); memset(buildYLoc, 0, sizeof(short)*MAX_RAW); for(i=0; i<MAX_RAW; i++) minDist[i] = 0x7FFFFF; //--------------------------------------------// // scan for the site array //--------------------------------------------// for(i=site_array.size(); i>0; i--) { if(site_array.is_deleted(i)) continue; sitePtr = site_array[i]; if( sitePtr->site_type != SITE_RAW ) continue; siteLocPtr = world.get_loc(sitePtr->map_x_loc, sitePtr->map_y_loc); if(!siteLocPtr->can_build_firm()) continue; siteId = sitePtr->object_id - 1; err_when(siteId<0 || siteId>MAX_RAW); if(townWithMine[siteId]) continue; // a site connected to town is found before //--------------------------------------------// // continue if action to this site already exist //--------------------------------------------// if(is_action_exist(-1, -1, sitePtr->map_x_loc, sitePtr->map_y_loc, ACTION_AI_BUILD_FIRM, FIRM_MINE)) continue; for(j=0; j<ai_town_count; j++) { townPtr = town_array[ai_town_array[j]]; locPtr = world.get_loc(townPtr->loc_x1, townPtr->loc_y1); //-********* codes to move to other territory ***********-// if(siteLocPtr->region_id!=locPtr->region_id) continue; // not on the same territory dist = m.points_distance(sitePtr->map_x_loc, sitePtr->map_y_loc, townPtr->center_x, townPtr->center_y); //-------------------------------------------------------------------------// // check whether a mine is already connected to this town, if so, use it //-------------------------------------------------------------------------// for(connected=0, k=townPtr->linked_firm_count-1; k>=0; k--) { err_when(!townPtr->linked_firm_array[k] || firm_array.is_deleted(townPtr->linked_firm_array[k])); firmPtr = firm_array[townPtr->linked_firm_array[k]]; if(firmPtr->nation_recno==nation_recno && firmPtr->firm_id==FIRM_MINE) { connected++; break; } } //-------------------------------------------------------------------------// // calculate the minimum distance from own towns //-------------------------------------------------------------------------// if(dist<minDist[siteId] || (connected && dist<=effectiveDis)) { //------ can build or not ----------// canBuild = 0; for(int ix=sitePtr->map_x_loc-firmInfo->loc_width+1; ix<=sitePtr->map_x_loc && !canBuild; ix++) { if(ix<0 || ix>=MAX_WORLD_X_LOC) continue; for(int iy=sitePtr->map_y_loc-firmInfo->loc_height+1; iy<=sitePtr->map_y_loc && !canBuild; iy++) { if(iy<0 || iy>=MAX_WORLD_Y_LOC) continue; if(world.can_build_firm(ix, iy, FIRM_MINE)) { canBuild++; buildXLoc[siteId] = ix; buildYLoc[siteId] = iy; break; } } } if(canBuild) { nearSite[siteId] = i; minDist[siteId] = dist; if(connected && dist<=effectiveDis) townWithMine[siteId]++; } } } for(allHave=1, j=0; j<MAX_RAW; j++) { if(!townWithMine[j])//if(!nearSite[j]) { allHave = 0; break; } } if(allHave) break; // sites of each raw material have been found } //---------------------------------------------------------------------------// // determine which raw material is the best choice to build // Note: a better sorting algorithm should be used if there are many kind of // raw material //---------------------------------------------------------------------------// int weight, pos; // weight is the such kind of material mined, pos is the position in the array int siteRecno = 0; // siteRecno is the recno of site to build int withoutThisRaw = 0; // withoutThisRaw shows that this raw material is strongly recommended int closestDist=0x7FFFFF; for(pos=-1, weight=0x7FFFFF, j=0 ;j<MAX_RAW; j++) { if(!nearSite[j]) continue; // no such kind of raw material if(!raw_kind_mined[j]) // no such kind of material and there is a possible site { if(withoutThisRaw) { if(minDist[j]<closestDist) // more than one kind of material we don't have { siteRecno = nearSite[j]; closestDist = minDist[j]; pos = j; } } else { siteRecno = nearSite[j]; closestDist = minDist[j]; withoutThisRaw++; pos = j; } } else if(!withoutThisRaw && weight>raw_kind_mined[j]) // scan for the kind of material with least num of this site { weight = raw_kind_mined[j]; pos = j; } } if(!siteRecno && pos>=0) siteRecno = nearSite[pos]; if(siteRecno) { sitePtr = site_array[siteRecno]; xLoc = buildXLoc[pos]; yLoc = buildYLoc[pos]; refXLoc = sitePtr->map_x_loc; refYLoc = sitePtr->map_y_loc; err_when((xLoc-refXLoc)>=firm_res[FIRM_MINE]->loc_width || (yLoc-refYLoc)>=firm_res[FIRM_MINE]->loc_height); //--------------------------------------------------------------// // do some adjustment such that the firm will be built far away // from other firms by at least one step. //--------------------------------------------------------------// seek_best_build_mine_location(xLoc, yLoc, sitePtr->map_x_loc, sitePtr->map_y_loc); err_when((xLoc-refXLoc)>=firm_res[FIRM_MINE]->loc_width || (yLoc-refYLoc)>=firm_res[FIRM_MINE]->loc_height); return sitePtr->object_id; // the raw id. } return 0; }