src/ai/api/ai_industry.cpp
branchnoai
changeset 9736 183b38e0a480
parent 9723 eee46cb39750
child 9737 ee408edf3851
equal deleted inserted replaced
9735:9f06148355f4 9736:183b38e0a480
    23 	return ::IsValidIndustryID(industry_id);
    23 	return ::IsValidIndustryID(industry_id);
    24 }
    24 }
    25 
    25 
    26 char *AIIndustry::GetName(IndustryID industry_id)
    26 char *AIIndustry::GetName(IndustryID industry_id)
    27 {
    27 {
    28 	if (!this->IsValidIndustry(industry_id)) return NULL;
    28 	if (!IsValidIndustry(industry_id)) return NULL;
    29 	static const int len = 64;
    29 	static const int len = 64;
    30 	char *industry_name = MallocT<char>(len);
    30 	char *industry_name = MallocT<char>(len);
    31 
    31 
    32 	SetDParam(0, industry_id);
    32 	::SetDParam(0, industry_id);
    33 	GetString(industry_name, STR_INDUSTRY, &industry_name[len - 1]);
    33 	::GetString(industry_name, STR_INDUSTRY, &industry_name[len - 1]);
    34 
    34 
    35 	return industry_name;
    35 	return industry_name;
    36 }
    36 }
    37 
    37 
    38 /* static */ int32 AIIndustry::GetProduction(IndustryID industry_id, CargoID cargo_id)
    38 /* static */ int32 AIIndustry::GetProduction(IndustryID industry_id, CargoID cargo_id)
    39 {
    39 {
    40 	if (!AIIndustry::IsValidIndustry(industry_id)) return -1;
    40 	if (!IsValidIndustry(industry_id)) return -1;
    41 	if (!AICargo::IsValidCargo(cargo_id)) return -1;
    41 	if (!AICargo::IsValidCargo(cargo_id)) return -1;
    42 
    42 
    43 	const Industry *i = ::GetIndustry(industry_id);
    43 	const Industry *i = ::GetIndustry(industry_id);
    44 	const IndustrySpec *indsp = GetIndustrySpec(i->type);
    44 	const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
    45 
    45 
    46 	if (indsp->produced_cargo[0] == cargo_id) return i->production_rate[0];
    46 	if (indsp->produced_cargo[0] == cargo_id) return i->production_rate[0];
    47 	if (indsp->produced_cargo[1] == cargo_id) return i->production_rate[1];
    47 	if (indsp->produced_cargo[1] == cargo_id) return i->production_rate[1];
    48 	return -1;
    48 	return -1;
    49 }
    49 }
    50 
    50 
    51 /* static */ bool AIIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id)
    51 /* static */ bool AIIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id)
    52 {
    52 {
    53 	if (!AIIndustry::IsValidIndustry(industry_id)) return false;
    53 	if (!IsValidIndustry(industry_id)) return false;
    54 	if (!AICargo::IsValidCargo(cargo_id)) return false;
    54 	if (!AICargo::IsValidCargo(cargo_id)) return false;
    55 
    55 
    56 	const Industry *i = ::GetIndustry(industry_id);
    56 	const Industry *i = ::GetIndustry(industry_id);
    57 	const IndustrySpec *indsp = GetIndustrySpec(i->type);
    57 	const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
    58 
    58 
    59 	if (indsp->accepts_cargo[0] == cargo_id) return true;
    59 	if (indsp->accepts_cargo[0] == cargo_id) return true;
    60 	if (indsp->accepts_cargo[1] == cargo_id) return true;
    60 	if (indsp->accepts_cargo[1] == cargo_id) return true;
    61 	if (indsp->accepts_cargo[2] == cargo_id) return true;
    61 	if (indsp->accepts_cargo[2] == cargo_id) return true;
    62 
    62 
    63 	return false;
    63 	return false;
    64 }
    64 }
    65 
    65 
    66 /* static */ TileIndex AIIndustry::GetLocation(IndustryID industry_id)
    66 /* static */ TileIndex AIIndustry::GetLocation(IndustryID industry_id)
    67 {
    67 {
    68 	if (!AIIndustry::IsValidIndustry(industry_id)) return INVALID_TILE;
    68 	if (!IsValidIndustry(industry_id)) return INVALID_TILE;
    69 	return ::GetIndustry(industry_id)->xy;
    69 	return ::GetIndustry(industry_id)->xy;
    70 }
    70 }