void CampaignEastWest::plot_d5_create_game() { // -------- build a seat of power -------// int trial = 100; int seatCount = 1; for( ; trial > 0 && seatCount > 0; --trial ) { int townRecno; if( (townRecno = random_pick_town_with_camp( nation_array.player_recno, 8)) ) // only pick town with <= 8 links { int firmRecno; GodInfo *godInfo = god_res[town_array[townRecno]->race_id]; int knowGodBefore = godInfo->is_nation_know(nation_array.player_recno); if( !knowGodBefore ) { godInfo->enable_know(nation_array.player_recno); } if( (firmRecno = create_firm_next_to_place( town_array[townRecno], FIRM_BASE, town_array[townRecno]->race_id)) ) { // ---------- add lose condition --------// game.add_lose_condition(E_DESTROY_FIRM, 1, firmRecno ); --seatCount; } if( !knowGodBefore ) { godInfo->disable_know(nation_array.player_recno); } } } }
//------- Begin of function Town::think_build_base -------// // // Think about building seats of powre. // int Town::think_build_base() { Nation* nationPtr = nation_array[nation_recno]; if( !is_base_town ) return 0; //----- see if we have enough money to build & support the weapon ----// if( !nationPtr->ai_should_spend(50) ) return 0; if( jobless_population < MAX_BASE_PRAYER/2 || nationPtr->total_jobless_population < MAX_BASE_PRAYER ) { return 0; } //------ do a scan on the existing bases first ------// static short buildRatingArray[MAX_RACE]; memset( buildRatingArray, 0, sizeof(buildRatingArray) ); //--- increase build rating for the seats that this nation knows how to build ---// GodInfo* godInfo; int i; for( i=1 ; i<=god_res.god_count ; i++ ) { godInfo = god_res[i]; if( godInfo->is_nation_know(nation_recno) ) buildRatingArray[godInfo->race_id-1] += 100; } //--- decrease build rating for the seats that the nation currently has ---// FirmBase* firmBase; for( i=0 ; i<nationPtr->ai_base_count ; i++ ) { firmBase = (FirmBase*) firm_array[ nationPtr->ai_base_array[i] ]; buildRatingArray[ god_res[firmBase->god_id]->race_id-1 ] = 0; // only build one /* if( firmBase->prayer_count < MAX_BASE_PRAYER ) buildRatingArray[ god_res[firmBase->god_id]->race_id-1 ] = 0; else buildRatingArray[ god_res[firmBase->god_id]->race_id-1 ] -= 10; // -10 for one existing instance */ } //------ decide which is the best to build -------// int bestRating=0, bestRaceId=0; for( i=0 ; i<MAX_RACE ; i++ ) { if( buildRatingArray[i] > bestRating ) { bestRating = buildRatingArray[i]; bestRaceId = i+1; } } //------- queue building a seat of power ------// if( bestRaceId ) return ai_build_neighbor_firm(FIRM_BASE, bestRaceId); return 0; }