Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../../stdafx.h"
00013 #include "script_goal.hpp"
00014 #include "script_error.hpp"
00015 #include "script_industry.hpp"
00016 #include "script_map.hpp"
00017 #include "script_town.hpp"
00018 #include "../script_instance.hpp"
00019 #include "../../command_type.h"
00020 #include "../../settings_type.h"
00021 #include "../../openttd.h"
00022 #include "../../network/network.h"
00023 #include "../../goal_base.h"
00024 #include "../../string_func.h"
00025
00026 bool ScriptGoal::IsValidGoal(GoalID goal_id)
00027 {
00028 return ::Goal::IsValidID(goal_id);
00029 }
00030
00031 ScriptGoal::GoalID ScriptGoal::New(ScriptCompany::CompanyID company, Text *goal, GoalType type, uint32 destination)
00032 {
00033 CCountedPtr<Text> counter(goal);
00034
00035 EnforcePrecondition(GOAL_INVALID, goal != NULL);
00036 EnforcePrecondition(GOAL_INVALID, !StrEmpty(goal->GetEncodedText()));
00037 EnforcePrecondition(GOAL_INVALID, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
00038 EnforcePrecondition(GOAL_INVALID, (type == GT_NONE && destination == 0) || (type == GT_TILE && ScriptMap::IsValidTile(destination)) || (type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(destination)) || (type == GT_TOWN && ScriptTown::IsValidTown(destination)) || (type == GT_COMPANY && ScriptCompany::ResolveCompanyID((ScriptCompany::CompanyID)destination) != ScriptCompany::COMPANY_INVALID));
00039
00040 uint8 c = company;
00041 if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
00042
00043 if (!ScriptObject::DoCommand(0, type | (c << 8), destination, CMD_CREATE_GOAL, goal->GetEncodedText(), &ScriptInstance::DoCommandReturnGoalID)) return GOAL_INVALID;
00044
00045
00046 return (ScriptGoal::GoalID)0;
00047 }
00048
00049 bool ScriptGoal::Remove(GoalID goal_id)
00050 {
00051 EnforcePrecondition(false, IsValidGoal(goal_id));
00052
00053 return ScriptObject::DoCommand(0, goal_id, 0, CMD_REMOVE_GOAL);
00054 }