src/ai/NoAI/NoAI.cpp
author rubidium
Thu, 15 Mar 2007 13:50:58 +0000
branchnoai
changeset 9405 df6f3b4b0038
parent 9390 4042c17c8055
permissions -rw-r--r--
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     1
/* $Id$ */
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     2
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     3
/** @file NoAI.cpp a simple C++ AI that will never be an AI */
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     4
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     5
#include "NoAI.hpp"
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     6
9390
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents: 9384
diff changeset
     7
static FNoAI iFNoAI; ///< Tell the AI-core that we have an AI with which we like to play.
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents: 9384
diff changeset
     8
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     9
/* virtual */ void NoAI::GameLoop()
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    10
{
9384
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    11
	if (this->GetTick() == 1) {
9405
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    12
		if (!this->company.SetCompanyName("NoAI")) {
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    13
			char name[32];
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    14
			snprintf(name, lengthof(name), "NoAI %d", this->base.Random());
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    15
			this->company.SetCompanyName(name);
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    16
		}
9384
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    17
		printf("Map size: %d by %d, %d tiles\n", this->map.GetMapSizeX(),
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    18
				this->map.GetMapSizeY(), this->map.GetMapSize());
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    19
	}
9374
61379e9b2393 (svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents: 9361
diff changeset
    20
9405
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    21
	if (this->GetTick() < 10) {
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    22
		char *cargo_label = this->cargo.GetCargoLabel(this->GetTick());
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    23
		printf("%s is %sfreight and the income is %d per 20 tiles in 10 days\n",
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    24
				cargo_label, this->cargo.IsFreight(this->GetTick()) ? "" : "not ",
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    25
				this->cargo.GetCargoIncome(20, 10, this->GetTick()));
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    26
		free(cargo_label);
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    27
	}
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    28
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    29
	if (this->GetTick() < this->industry.GetMaxIndustryID()) {
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    30
		if (this->industry.IsValidIndustry(this->GetTick())) {
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    31
			char *industry_name = this->industry.GetName(this->GetTick());
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    32
			TileIndex t = this->industry.GetLocation(this->GetTick());
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    33
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    34
			printf("Industry %s [%d of %d] at (%d, %d)\n",
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    35
					industry_name, this->GetTick(), this->industry.GetIndustryCount(),
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    36
					this->map.GetTileX(t), this->map.GetTileY(t));
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    37
		}
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    38
	}
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    39
9374
61379e9b2393 (svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents: 9361
diff changeset
    40
	if (this->GetTick() % 10 == 0) {
61379e9b2393 (svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents: 9361
diff changeset
    41
		char *company_name = this->company.GetCompanyName();
9384
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    42
		printf("%s has loaned %d\n", company_name, this->company.GetLoanAmount());
9374
61379e9b2393 (svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents: 9361
diff changeset
    43
		free(company_name);
61379e9b2393 (svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents: 9361
diff changeset
    44
	}
61379e9b2393 (svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents: 9361
diff changeset
    45
61379e9b2393 (svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents: 9361
diff changeset
    46
	if (this->GetTick() % 14 == 0) {
9376
7c12a15c945a (svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents: 9374
diff changeset
    47
		uint level = (this->company.GetMaxLoanAmount() / this->company.GetLoanInterval()) + 1;
7c12a15c945a (svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents: 9374
diff changeset
    48
		this->company.SetLoanAmount(this->base.RandomRange(level) * this->company.GetLoanInterval());
9374
61379e9b2393 (svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents: 9361
diff changeset
    49
	}
9384
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    50
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    51
	if (this->GetTick() % 13 == 0) {
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    52
		TownID town_id = this->base.RandomRange(this->town.GetMaxTownID());
9405
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents: 9390
diff changeset
    53
		if (this->town.IsValidTown(town_id)) {
9384
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    54
			char *town_name = this->town.GetName(town_id);
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    55
			TileIndex t = this->town.GetLocation(town_id);
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    56
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    57
			printf("Town %s [%d of %d] at (%d, %d) with %d inhabitants\n",
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    58
					town_name, town_id, this->town.GetTownCount(),
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    59
					this->map.GetTileX(t), this->map.GetTileY(t),
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    60
					this->town.GetPopulation(town_id));
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    61
		}
188a770476e0 (svn r9174) [NoAI] -Codechange: call all functions that are provided by the AI wrappers, so it can later be used for regression testing.
rubidium
parents: 9376
diff changeset
    62
	}
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    63
}