123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- #include <OINFO.h>
- #include <OUNIT.h>
- #include <OGAME.h>
- #include <OFONT.h>
- #include <ONATION.h>
- #include <ORAWRES.h>
- #include <ORACERES.h>
- #include <OTOWNRES.h>
- #include <OWORLD.h>
- #include <OF_MINE.h>
- #include <OF_MARK.h>
- #include <OF_FACT.h>
- void FirmFactory::process_ai()
- {
- if( info.game_date%15==firm_recno%15 )
- {
- if( think_change_production() )
- return;
- }
-
- if( info.game_date%15==firm_recno%15 )
- {
- if( worker_count < MAX_WORKER )
- ai_recruit_worker();
- }
-
- if( info.game_date%30==firm_recno%30 )
- think_build_market();
-
- if( info.game_date%30==firm_recno%30 )
- think_inc_productivity();
- }
- int FirmFactory::think_build_market()
- {
- if( no_neighbor_space )
- return 0;
- Nation* nationPtr = nation_array[nation_recno];
-
- if( !nationPtr->can_ai_build(FIRM_MARKET) )
- return 0;
-
-
-
-
-
- if( nationPtr->is_build_action_exist(FIRM_MARKET, center_x, center_y) )
- return 0;
-
- FirmMarket* firmPtr;
- for(int i=0; i<linked_firm_count; i++)
- {
- err_when(!linked_firm_array[i] || firm_array.is_deleted(linked_firm_array[i]));
- firmPtr = (FirmMarket*) firm_array[linked_firm_array[i]];
- if( firmPtr->firm_id!=FIRM_MARKET )
- continue;
-
- if( firmPtr->nation_recno == nation_recno &&
- ((FirmMarket*)firmPtr)->is_retail_market )
- {
- return 0;
- }
- }
-
- short buildXLoc, buildYLoc;
- if( !nationPtr->find_best_firm_loc(FIRM_MARKET, loc_x1, loc_y1, buildXLoc, buildYLoc) )
- {
- no_neighbor_space = 1;
- return 0;
- }
- nationPtr->add_action(buildXLoc, buildYLoc, loc_x1, loc_y1, ACTION_AI_BUILD_FIRM, FIRM_MARKET);
- return 1;
- }
- int FirmFactory::think_inc_productivity()
- {
-
-
-
-
-
-
-
- if( stock_qty > max_stock_qty * 0.1 && production_30days() > 30 )
- return 0;
-
-
-
-
-
-
- if( raw_stock_qty < max_raw_stock_qty * 0.2 )
- return 0;
- return think_hire_inn_unit();
- }
- int FirmFactory::think_change_production()
- {
- if( cur_month_production + last_month_production > 0 ||
- raw_stock_qty > 0 )
- {
- return 0;
- }
- if( info.game_date < setup_date + 30 )
- return 0;
-
- #define MIN_FACTORY_IMPORT_STOCK_QTY 20
- Firm* firmPtr;
- int curRating, bestRating=0, bestProductId=0, bestIsOwn=0;
- for(int i=0; i<linked_firm_count; i++)
- {
-
-
- firmPtr = firm_array[linked_firm_array[i]];
-
- if( firmPtr->firm_id!=FIRM_MINE && firmPtr->firm_id!=FIRM_MARKET )
- continue;
-
- if( linked_firm_enable_array[i] == LINK_DE )
- toggle_firm_link( i+1, 1, COMMAND_AI );
- if( linked_firm_enable_array[i] != LINK_EE )
- continue;
- curRating=0;
-
- if( firmPtr->firm_id == FIRM_MINE )
- {
- FirmMine* firmMine = (FirmMine*) firmPtr;
- if( firmMine->stock_qty >= MIN_FACTORY_IMPORT_STOCK_QTY )
- {
- curRating = (int) firmMine->stock_qty;
- if( curRating > bestRating )
- {
- if( firmPtr->nation_recno == nation_recno || !bestIsOwn )
- {
- bestRating = curRating;
- bestProductId = firmMine->raw_id;
- bestIsOwn = firmPtr->nation_recno == nation_recno;
- }
- }
- }
- }
-
- else if( firmPtr->firm_id == FIRM_MARKET )
- {
- FirmMarket* firmMarket = (FirmMarket*) firmPtr;
- MarketGoods* marketGoods = firmMarket->market_goods_array;
- for( int j=0 ; j<MAX_MARKET_GOODS ; j++, marketGoods++ )
- {
- if( marketGoods->raw_id &&
- marketGoods->stock_qty >= MIN_FACTORY_IMPORT_STOCK_QTY )
- {
- curRating = (int) marketGoods->stock_qty;
- if( curRating > bestRating )
- {
- if( firmPtr->nation_recno == nation_recno || !bestIsOwn )
- {
- bestRating = curRating;
- bestProductId = marketGoods->raw_id;
- bestIsOwn = firmPtr->nation_recno == nation_recno;
- }
- }
- }
- }
- }
- }
-
- if( bestProductId )
- {
- set_production(bestProductId);
- return 1;
- }
- else
- {
- if( info.game_date > setup_date + 60 )
- {
- ai_del_firm();
- return 1;
- }
- }
- return 0;
- }
- int FirmFactory::ai_has_excess_worker()
- {
-
- if( worker_count > 4 )
- {
- return stock_qty > max_stock_qty * (float) 0.9 &&
- production_30days() < productivity*25;
- }
- return 0;
- }
|