//------- Begin of function FirmHarbor::think_build_ship -----------// // void FirmHarbor::think_build_ship() { if( build_unit_id ) // if it's currently building a ship return; if( !can_build_ship() ) // full, cannot build anymore return; Nation* ownNation = nation_array[nation_recno]; if( !ownNation->ai_should_spend( 50+ownNation->pref_use_marine/4 ) ) return; //---------------------------------------------// // // For Transport, in most cases, an AI will just // need one to two. // // For Caravel and Galleon, the AI will build as many // as the harbor can hold if any of the human players // has more ships than the AI has. // //---------------------------------------------// int buildId=0, rc=0; int enemyShipCount = ownNation->max_human_battle_ship_count(); // return the no. of ships of the enemy that is strongest on the sea if( unit_res[UNIT_GALLEON]->get_nation_tech_level(nation_recno) > 0 ) { buildId = UNIT_GALLEON; if( ownNation->ai_ship_count < 2 + (ownNation->pref_use_marine>50) ) rc = 1; else rc = enemyShipCount > ownNation->ai_ship_count; } else if( unit_res[UNIT_CARAVEL]->get_nation_tech_level(nation_recno) > 0 ) { buildId = UNIT_CARAVEL; if( ownNation->ai_ship_count < 2 + (ownNation->pref_use_marine>50) ) rc = 1; else rc = enemyShipCount > ownNation->ai_ship_count; } else { buildId = UNIT_TRANSPORT; if( ownNation->ai_ship_count < 2 ) rc = 1; } //---------------------------------------------// if( buildId && rc ) build_ship( buildId, COMMAND_AI ); }
void create_ship(region * r, unit * u, const struct ship_type *newtype, int want, order * ord) { ship *sh; int msize; const construction *cons = newtype->construction; order *new_order; if (!eff_skill(u, SK_SHIPBUILDING, r)) { cmistake(u, ord, 100, MSG_PRODUCE); return; } if (besieged(u)) { cmistake(u, ord, 60, MSG_PRODUCE); return; } /* check if skill and material for 1 size is available */ if (eff_skill(u, cons->skill, r) < cons->minskill) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_build_skill_low", "value", cons->minskill)); return; } msize = maxbuild(u, cons); if (msize == 0) { cmistake(u, ord, 88, MSG_PRODUCE); return; } if (want > 0) want = _min(want, msize); else want = msize; sh = new_ship(newtype, r, u->faction->locale); if (leave(u, false)) { if (fval(u_race(u), RCF_CANSAIL)) { u_set_ship(u, sh); } } new_order = create_order(K_MAKE, u->faction->locale, "%s %i", LOC(u->faction->locale, parameters[P_SHIP]), sh->no); replace_order(&u->orders, ord, new_order); free_order(new_order); build_ship(u, sh, want); }
void continue_ship(region * r, unit * u, int want) { const construction *cons; ship *sh; int msize; if (!eff_skill(u, SK_SHIPBUILDING, r)) { cmistake(u, u->thisorder, 100, MSG_PRODUCE); return; } /* Die Schiffsnummer bzw der Schiffstyp wird eingelesen */ sh = getship(r); if (!sh) sh = u->ship; if (!sh) { cmistake(u, u->thisorder, 20, MSG_PRODUCE); return; } cons = sh->type->construction; assert(cons->improvement == NULL); /* sonst ist construction::size nicht ship_type::maxsize */ if (sh->size == cons->maxsize && !sh->damage) { cmistake(u, u->thisorder, 16, MSG_PRODUCE); return; } if (eff_skill(u, cons->skill, r) < cons->minskill) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_build_skill_low", "value", cons->minskill)); return; } msize = maxbuild(u, cons); if (msize == 0) { cmistake(u, u->thisorder, 88, MSG_PRODUCE); return; } if (want > 0) want = _min(want, msize); else want = msize; build_ship(u, sh, want); }
//--------- Begin of function FirmHarbor::process_queue ---------// void FirmHarbor::process_queue() { if(build_queue_count>0) { build_ship(build_queue_array[0], COMMAND_AUTO); // remove the queue no matter build_ship success or not misc.del_array_rec( build_queue_array, build_queue_count, sizeof(build_queue_array[0]), 1 ); build_queue_count--; if( firm_array.selected_recno == firm_recno ) { disable_refresh = 1; info.disp(); disable_refresh = 0; } } }