Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "company_func.h"
00014 #include "industry.h"
00015 #include "town.h"
00016 #include "news_func.h"
00017 #include "ai/ai.hpp"
00018 #include "station_base.h"
00019 #include "cargotype.h"
00020 #include "strings_func.h"
00021 #include "window_func.h"
00022 #include "goal_base.h"
00023 #include "core/pool_func.hpp"
00024 #include "core/random_func.hpp"
00025 #include "game/game.hpp"
00026 #include "command_func.h"
00027 #include "company_base.h"
00028 #include "string_func.h"
00029
00030 #include "table/strings.h"
00031
00032 GoalID _new_goal_id;
00033
00034 GoalPool _goal_pool("Goal");
00035 INSTANTIATE_POOL_METHODS(Goal)
00036
00037
00048 CommandCost CmdCreateGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
00049 {
00050 if (!Goal::CanAllocateItem()) return CMD_ERROR;
00051
00052 GoalType type = (GoalType)GB(p1, 0, 8);
00053 CompanyID company = (CompanyID)GB(p1, 8, 8);
00054
00055 if (_current_company != OWNER_DEITY) return CMD_ERROR;
00056 if (StrEmpty(text)) return CMD_ERROR;
00057 if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR;
00058
00059 switch (type) {
00060 case GT_NONE:
00061 if (p2 != 0) return CMD_ERROR;
00062 break;
00063
00064 case GT_TILE:
00065 if (!IsValidTile(p2)) return CMD_ERROR;
00066 break;
00067
00068 case GT_INDUSTRY:
00069 if (!Industry::IsValidID(p2)) return CMD_ERROR;
00070 break;
00071
00072 case GT_TOWN:
00073 if (!Town::IsValidID(p2)) return CMD_ERROR;
00074 break;
00075
00076 case GT_COMPANY:
00077 if (!Company::IsValidID(p2)) return CMD_ERROR;
00078 break;
00079
00080 default: return CMD_ERROR;
00081 }
00082
00083 if (flags & DC_EXEC) {
00084 Goal *g = new Goal();
00085 g->type = type;
00086 g->dst = p2;
00087 g->company = company;
00088 g->text = strdup(text);
00089
00090 InvalidateWindowData(WC_GOALS_LIST, 0);
00091
00092 _new_goal_id = g->index;
00093 }
00094
00095 return CommandCost();
00096 }
00097
00107 CommandCost CmdRemoveGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
00108 {
00109 if (_current_company != OWNER_DEITY) return CMD_ERROR;
00110 if (!Goal::IsValidID(p1)) return CMD_ERROR;
00111
00112 if (flags & DC_EXEC) {
00113 Goal *g = Goal::Get(p1);
00114 delete g;
00115
00116 InvalidateWindowData(WC_GOALS_LIST, 0);
00117 }
00118
00119 return CommandCost();
00120 }