src/ai/NoAI/NoAI.cpp
author rubidium
Fri, 16 Mar 2007 22:00:07 +0000
branchnoai
changeset 9444 fd27df7ca2a0
parent 9441 03da911c8d5f
child 9449 8b688e6517d0
permissions -rw-r--r--
(svn r9260) [NoAI] -Codechange: do the AI threading properly using a mutex and condition signalling.
Note: this is pthread specific code, it needs to be ported to non POSIX platform.
/* $Id$ */

/** @file NoAI.cpp a simple C++ AI that will never be an AI */

#include "NoAI.hpp"

static FNoAI iFNoAI; ///< Tell the AI-core that we have an AI with which we like to play.

/* virtual */ void NoAI::Start()
{
	this->stop = false;
	while (!stop) {
		printf("Start NoAI %d\n", this->GetTick());
		this->Sleep(50);
	}
	return;
	if (this->GetTick() == 1) {
		if (!this->company.SetCompanyName("NoAI")) {
			char name[32];
			snprintf(name, lengthof(name), "NoAI %d", this->base.Rand());
			this->company.SetCompanyName(name);
		}
		printf("Map size: %d by %d, %d tiles\n", this->map.GetMapSizeX(),
				this->map.GetMapSizeY(), this->map.GetMapSize());
	}

	if (this->GetTick() < 10) {
		char *cargo_label = this->cargo.GetCargoLabel(this->GetTick());
		printf("%s is %sfreight and the income is %d per 20 tiles in 10 days\n",
				cargo_label, this->cargo.IsFreight(this->GetTick()) ? "" : "not ",
				this->cargo.GetCargoIncome(20, 10, this->GetTick()));
		free(cargo_label);
	}

	if (this->GetTick() < this->industry.GetMaxIndustryID()) {
		if (this->industry.IsValidIndustry(this->GetTick())) {
			char *industry_name = this->industry.GetName(this->GetTick());
			TileIndex t = this->industry.GetLocation(this->GetTick());

			printf("Industry %s [%d of %d] at (%d, %d)\n",
					industry_name, this->GetTick(), this->industry.GetIndustryCount(),
					this->map.GetTileX(t), this->map.GetTileY(t));
		}
	}

	if (this->GetTick() % 10 == 0) {
		char *company_name = this->company.GetCompanyName();
		printf("%s has loaned %d\n", company_name, this->company.GetLoanAmount());
		free(company_name);
	}

	if (this->GetTick() % 14 == 0) {
		uint level = (this->company.GetMaxLoanAmount() / this->company.GetLoanInterval()) + 1;
		this->company.SetLoanAmount(this->base.RandRange(level) * this->company.GetLoanInterval());
	}

	if (this->GetTick() % 13 == 0) {
		TownID town_id = this->base.RandRange(this->town.GetMaxTownID());
		if (this->town.IsValidTown(town_id)) {
			char *town_name = this->town.GetName(town_id);
			TileIndex t = this->town.GetLocation(town_id);

			printf("Town %s [%d of %d] at (%d, %d) with %d inhabitants\n",
					town_name, town_id, this->town.GetTownCount(),
					this->map.GetTileX(t), this->map.GetTileY(t),
					this->town.GetPopulation(town_id));
		}
	}
}

/* virtual */ void NoAI::Stop()
{
	this->stop = true;
}