src/ai/NoAI/NoAI.cpp
branchnoai
changeset 9441 03da911c8d5f
child 9444 fd27df7ca2a0
equal deleted inserted replaced
9440:0986434f3af8 9441:03da911c8d5f
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file NoAI.cpp a simple C++ AI that will never be an AI */
       
     4 
       
     5 #include "NoAI.hpp"
       
     6 
       
     7 static FNoAI iFNoAI; ///< Tell the AI-core that we have an AI with which we like to play.
       
     8 
       
     9 /* virtual */ void NoAI::Start()
       
    10 {
       
    11 	while (true) {
       
    12 		printf("Start NoAI %d\n", this->GetTick());
       
    13 		this->Sleep(5);
       
    14 	}
       
    15 	return;
       
    16 	if (this->GetTick() == 1) {
       
    17 		if (!this->company.SetCompanyName("NoAI")) {
       
    18 			char name[32];
       
    19 			snprintf(name, lengthof(name), "NoAI %d", this->base.Rand());
       
    20 			this->company.SetCompanyName(name);
       
    21 		}
       
    22 		printf("Map size: %d by %d, %d tiles\n", this->map.GetMapSizeX(),
       
    23 				this->map.GetMapSizeY(), this->map.GetMapSize());
       
    24 	}
       
    25 
       
    26 	if (this->GetTick() < 10) {
       
    27 		char *cargo_label = this->cargo.GetCargoLabel(this->GetTick());
       
    28 		printf("%s is %sfreight and the income is %d per 20 tiles in 10 days\n",
       
    29 				cargo_label, this->cargo.IsFreight(this->GetTick()) ? "" : "not ",
       
    30 				this->cargo.GetCargoIncome(20, 10, this->GetTick()));
       
    31 		free(cargo_label);
       
    32 	}
       
    33 
       
    34 	if (this->GetTick() < this->industry.GetMaxIndustryID()) {
       
    35 		if (this->industry.IsValidIndustry(this->GetTick())) {
       
    36 			char *industry_name = this->industry.GetName(this->GetTick());
       
    37 			TileIndex t = this->industry.GetLocation(this->GetTick());
       
    38 
       
    39 			printf("Industry %s [%d of %d] at (%d, %d)\n",
       
    40 					industry_name, this->GetTick(), this->industry.GetIndustryCount(),
       
    41 					this->map.GetTileX(t), this->map.GetTileY(t));
       
    42 		}
       
    43 	}
       
    44 
       
    45 	if (this->GetTick() % 10 == 0) {
       
    46 		char *company_name = this->company.GetCompanyName();
       
    47 		printf("%s has loaned %d\n", company_name, this->company.GetLoanAmount());
       
    48 		free(company_name);
       
    49 	}
       
    50 
       
    51 	if (this->GetTick() % 14 == 0) {
       
    52 		uint level = (this->company.GetMaxLoanAmount() / this->company.GetLoanInterval()) + 1;
       
    53 		this->company.SetLoanAmount(this->base.RandRange(level) * this->company.GetLoanInterval());
       
    54 	}
       
    55 
       
    56 	if (this->GetTick() % 13 == 0) {
       
    57 		TownID town_id = this->base.RandRange(this->town.GetMaxTownID());
       
    58 		if (this->town.IsValidTown(town_id)) {
       
    59 			char *town_name = this->town.GetName(town_id);
       
    60 			TileIndex t = this->town.GetLocation(town_id);
       
    61 
       
    62 			printf("Town %s [%d of %d] at (%d, %d) with %d inhabitants\n",
       
    63 					town_name, town_id, this->town.GetTownCount(),
       
    64 					this->map.GetTileX(t), this->map.GetTileY(t),
       
    65 					this->town.GetPopulation(town_id));
       
    66 		}
       
    67 	}
       
    68 }