Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../../stdafx.h"
00013 #include "script_cargo.hpp"
00014 #include "../../cargotype.h"
00015 #include "../../economy_func.h"
00016 #include "../../core/bitmath_func.hpp"
00017
00018 bool ScriptCargo::IsValidCargo(CargoID cargo_type)
00019 {
00020 return (cargo_type < NUM_CARGO && ::CargoSpec::Get(cargo_type)->IsValid());
00021 }
00022
00023 bool ScriptCargo::IsValidTownEffect(TownEffect towneffect_type)
00024 {
00025 return (towneffect_type >= (TownEffect)TE_BEGIN && towneffect_type < (TownEffect)TE_END);
00026 }
00027
00028 char *ScriptCargo::GetCargoLabel(CargoID cargo_type)
00029 {
00030 if (!IsValidCargo(cargo_type)) return NULL;
00031 const CargoSpec *cargo = ::CargoSpec::Get(cargo_type);
00032
00033
00034
00035 char *cargo_label = MallocT<char>(sizeof(cargo->label) + 1);
00036 for (uint i = 0; i < sizeof(cargo->label); i++) {
00037 cargo_label[i] = GB(cargo->label, (uint8)(sizeof(cargo->label) - i - 1) * 8, 8);
00038 }
00039 cargo_label[sizeof(cargo->label)] = '\0';
00040 return cargo_label;
00041 }
00042
00043 bool ScriptCargo::IsFreight(CargoID cargo_type)
00044 {
00045 if (!IsValidCargo(cargo_type)) return false;
00046 const CargoSpec *cargo = ::CargoSpec::Get(cargo_type);
00047 return cargo->is_freight;
00048 }
00049
00050 bool ScriptCargo::HasCargoClass(CargoID cargo_type, CargoClass cargo_class)
00051 {
00052 if (!IsValidCargo(cargo_type)) return false;
00053 return ::IsCargoInClass(cargo_type, (::CargoClass)cargo_class);
00054 }
00055
00056 ScriptCargo::TownEffect ScriptCargo::GetTownEffect(CargoID cargo_type)
00057 {
00058 if (!IsValidCargo(cargo_type)) return TE_NONE;
00059
00060 return (ScriptCargo::TownEffect)::CargoSpec::Get(cargo_type)->town_effect;
00061 }
00062
00063 Money ScriptCargo::GetCargoIncome(CargoID cargo_type, uint32 distance, uint32 days_in_transit)
00064 {
00065 if (!IsValidCargo(cargo_type)) return -1;
00066 return ::GetTransportedGoodsIncome(1, distance, Clamp(days_in_transit * 2 / 5, 0, 255), cargo_type);
00067 }