src/ai/api/ai_industry.cpp
author truelight
Sun, 19 Aug 2007 13:31:04 +0000
branchnoai
changeset 9698 1d50fe99b7e9
parent 9650 7e5e1a7ecbff
child 9710 ba44f8c1fd52
permissions -rw-r--r--
(svn r10939) [NoAI] -Add: added AITileList valuator Water
[NoAI] -Add: added AITile::IsWater
/* $Id$ */

/** @file ai_industry.cpp handles the query-related of the AIIndustry class */

#include "ai_industry.hpp"
#include "ai_cargo.hpp"
#include "../../industry.h"
#include "../../strings.h"
#include "../../variables.h" /* For SetDParam */
#include "table/strings.h"

IndustryID AIIndustry::GetMaxIndustryID()
{
	return ::GetMaxIndustryIndex();
}

int32 AIIndustry::GetIndustryCount()
{
	return ::GetNumIndustries();
}

/* static */ bool AIIndustry::IsValidIndustry(IndustryID industry_id)
{
	return ::IsValidIndustryID(industry_id);
}

char *AIIndustry::GetName(IndustryID industry_id)
{
	if (!this->IsValidIndustry(industry_id)) return NULL;
	static const int len = 64;
	char *industry_name = MallocT<char>(len);

	SetDParam(0, industry_id);
	GetString(industry_name, STR_INDUSTRY, &industry_name[len - 1]);

	return industry_name;
}

/* static */ int32 AIIndustry::GetProduction(IndustryID industry_id, CargoID cargo_id)
{
	if (!AIIndustry::IsValidIndustry(industry_id)) return -1;
	if (!AICargo::IsValidCargo(cargo_id)) return -1;

	const Industry *i = ::GetIndustry(industry_id);
	const IndustrySpec *indsp = GetIndustrySpec(i->type);

	if (indsp->produced_cargo[0] == cargo_id) return i->this_month_production[0];
	if (indsp->produced_cargo[1] == cargo_id) return i->this_month_production[1];
	return -1;
}

/* static */ TileIndex AIIndustry::GetLocation(IndustryID industry_id)
{
	if (!AIIndustry::IsValidIndustry(industry_id)) return INVALID_TILE;
	return ::GetIndustry(industry_id)->xy;
}