(svn r23630) -Add: a Goal GUI to show your current goals
parent
102c7ae60e
commit
ccf9b01f5d
@ -0,0 +1,120 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file goal.cpp Handling of goals. */
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "company_func.h"
|
||||
#include "industry.h"
|
||||
#include "town.h"
|
||||
#include "news_func.h"
|
||||
#include "ai/ai.hpp"
|
||||
#include "station_base.h"
|
||||
#include "cargotype.h"
|
||||
#include "strings_func.h"
|
||||
#include "window_func.h"
|
||||
#include "goal_base.h"
|
||||
#include "core/pool_func.hpp"
|
||||
#include "core/random_func.hpp"
|
||||
#include "game/game.hpp"
|
||||
#include "command_func.h"
|
||||
#include "company_base.h"
|
||||
#include "string_func.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
GoalID _new_goal_id;
|
||||
|
||||
GoalPool _goal_pool("Goal");
|
||||
INSTANTIATE_POOL_METHODS(Goal)
|
||||
|
||||
/**
|
||||
* Create a new goal.
|
||||
* @param tile unused.
|
||||
* @param flags type of operation
|
||||
* @param p1 various bitstuffed elements
|
||||
* - p1 = (bit 0 - 7) - GoalType of destination.
|
||||
* - p1 = (bit 8 - 15) - Company for which this goal is.
|
||||
* @param p2 GoalTypeID of destination.
|
||||
* @param text Text of the goal.
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdCreateGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
if (!Goal::CanAllocateItem()) return CMD_ERROR;
|
||||
|
||||
GoalType type = (GoalType)GB(p1, 0, 8);
|
||||
CompanyID company = (CompanyID)GB(p1, 8, 8);
|
||||
|
||||
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
||||
if (StrEmpty(text)) return CMD_ERROR;
|
||||
if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR;
|
||||
|
||||
switch (type) {
|
||||
case GT_NONE:
|
||||
if (p2 != 0) return CMD_ERROR;
|
||||
break;
|
||||
|
||||
case GT_TILE:
|
||||
if (!IsValidTile(p2)) return CMD_ERROR;
|
||||
break;
|
||||
|
||||
case GT_INDUSTRY:
|
||||
if (!Industry::IsValidID(p2)) return CMD_ERROR;
|
||||
break;
|
||||
|
||||
case GT_TOWN:
|
||||
if (!Town::IsValidID(p2)) return CMD_ERROR;
|
||||
break;
|
||||
|
||||
case GT_COMPANY:
|
||||
if (!Company::IsValidID(p2)) return CMD_ERROR;
|
||||
break;
|
||||
|
||||
default: return CMD_ERROR;
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
Goal *g = new Goal();
|
||||
g->type = type;
|
||||
g->dst = p2;
|
||||
g->company = company;
|
||||
g->text = strdup(text);
|
||||
|
||||
InvalidateWindowData(WC_GOALS_LIST, 0);
|
||||
|
||||
_new_goal_id = g->index;
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a goal.
|
||||
* @param tile unused.
|
||||
* @param flags type of operation
|
||||
* @param p1 GoalID to remove.
|
||||
* @param p2 unused.
|
||||
* @param text unused.
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdRemoveGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
||||
if (!Goal::IsValidID(p1)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
Goal *g = Goal::Get(p1);
|
||||
delete g;
|
||||
|
||||
InvalidateWindowData(WC_GOALS_LIST, 0);
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file goal_base.h Goal base class. */
|
||||
|
||||
#ifndef GOAL_BASE_H
|
||||
#define GOAL_BASE_H
|
||||
|
||||
#include "cargo_type.h"
|
||||
#include "company_type.h"
|
||||
#include "goal_type.h"
|
||||
#include "core/pool_type.hpp"
|
||||
|
||||
typedef Pool<Goal, GoalID, 1, MAX_COMPANIES> GoalPool;
|
||||
extern GoalPool _goal_pool;
|
||||
|
||||
/** Struct about subsidies, offered and awarded */
|
||||
struct Goal : GoalPool::PoolItem<&_goal_pool> {
|
||||
CompanyByte company; ///< Goal is for a specific company; INVALID_COMPANY if it is global
|
||||
GoalTypeByte type; ///< Type of the goal
|
||||
GoalTypeID dst; ///< Index of type
|
||||
char *text; ///< Text of the goal.
|
||||
|
||||
/**
|
||||
* We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
|
||||
*/
|
||||
FORCEINLINE Goal() { }
|
||||
|
||||
/**
|
||||
* (Empty) destructor has to be defined else operator delete might be called with NULL parameter
|
||||
*/
|
||||
FORCEINLINE ~Goal() { free(this->text); }
|
||||
};
|
||||
|
||||
#define FOR_ALL_GOALS_FROM(var, start) FOR_ALL_ITEMS_FROM(Goal, goal_index, var, start)
|
||||
#define FOR_ALL_GOALS(var) FOR_ALL_GOALS_FROM(var, 0)
|
||||
|
||||
#endif /* GOAL_BASE_H */
|
@ -0,0 +1,253 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file goal_gui.cpp GUI for goals. */
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "industry.h"
|
||||
#include "town.h"
|
||||
#include "window_gui.h"
|
||||
#include "strings_func.h"
|
||||
#include "date_func.h"
|
||||
#include "viewport_func.h"
|
||||
#include "gfx_func.h"
|
||||
#include "gui.h"
|
||||
#include "goal_base.h"
|
||||
#include "core/geometry_func.hpp"
|
||||
|
||||
#include "widgets/goal_widget.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
struct GoalListWindow : Window {
|
||||
Scrollbar *vscroll;
|
||||
|
||||
GoalListWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
||||
{
|
||||
this->CreateNestedTree(desc);
|
||||
this->vscroll = this->GetScrollbar(WID_GL_SCROLLBAR);
|
||||
this->FinishInitNested(desc, window_number);
|
||||
this->OnInvalidateData(0);
|
||||
}
|
||||
|
||||
virtual void OnClick(Point pt, int widget, int click_count)
|
||||
{
|
||||
if (widget != WID_GL_PANEL) return;
|
||||
|
||||
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GL_PANEL, WD_FRAMERECT_TOP);
|
||||
int num = 0;
|
||||
const Goal *s;
|
||||
FOR_ALL_GOALS(s) {
|
||||
if (s->company == INVALID_COMPANY) {
|
||||
y--;
|
||||
if (y == 0) {
|
||||
this->HandleClick(s);
|
||||
return;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
if (num == 0) {
|
||||
y--; // "None"
|
||||
if (y < 0) return;
|
||||
}
|
||||
|
||||
y -= 2; // "Company specific goals:"
|
||||
if (y < 0) return;
|
||||
|
||||
FOR_ALL_GOALS(s) {
|
||||
if (s->company != INVALID_COMPANY) {
|
||||
y--;
|
||||
if (y == 0) {
|
||||
this->HandleClick(s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleClick(const Goal *s)
|
||||
{
|
||||
/* determine dst coordinate for goal and try to scroll to it */
|
||||
TileIndex xy;
|
||||
switch (s->type) {
|
||||
case GT_NONE: return;
|
||||
case GT_COMPANY: return;
|
||||
|
||||
case GT_TILE:
|
||||
if (!IsValidTile(s->dst)) return;
|
||||
xy = s->dst;
|
||||
break;
|
||||
|
||||
case GT_INDUSTRY:
|
||||
if (!Industry::IsValidID(s->dst)) return;
|
||||
xy = Industry::Get(s->dst)->location.tile;
|
||||
break;
|
||||
|
||||
case GT_TOWN:
|
||||
if (!Town::IsValidID(s->dst)) return;
|
||||
xy = Town::Get(s->dst)->xy;
|
||||
break;
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
if (_ctrl_pressed) {
|
||||
ShowExtraViewPortWindow(xy);
|
||||
} else {
|
||||
ScrollMainWindowToTile(xy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of lines in this window.
|
||||
* @return the number of lines
|
||||
*/
|
||||
uint CountLines()
|
||||
{
|
||||
/* Count number of (non) awarded goals */
|
||||
uint num_global = 0;
|
||||
uint num_company = 0;
|
||||
const Goal *s;
|
||||
FOR_ALL_GOALS(s) {
|
||||
if (s->company == INVALID_COMPANY) {
|
||||
num_global++;
|
||||
} else {
|
||||
num_company++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Count the 'none' lines */
|
||||
if (num_global == 0) num_global = 1;
|
||||
if (num_company == 0) num_company = 1;
|
||||
|
||||
/* Global, company and an empty line before the accepted ones. */
|
||||
return 3 + num_global + num_company;
|
||||
}
|
||||
|
||||
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
||||
{
|
||||
if (widget != WID_GL_PANEL) return;
|
||||
Dimension d = maxdim(GetStringBoundingBox(STR_GOALS_GLOBAL_TITLE), GetStringBoundingBox(STR_GOALS_COMPANY_TITLE));
|
||||
|
||||
resize->height = d.height;
|
||||
|
||||
d.height *= 5;
|
||||
d.width += padding.width + WD_FRAMERECT_RIGHT + WD_FRAMERECT_LEFT;
|
||||
d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
||||
*size = maxdim(*size, d);
|
||||
}
|
||||
|
||||
virtual void DrawWidget(const Rect &r, int widget) const
|
||||
{
|
||||
if (widget != WID_GL_PANEL) return;
|
||||
|
||||
YearMonthDay ymd;
|
||||
ConvertDateToYMD(_date, &ymd);
|
||||
|
||||
int right = r.right - WD_FRAMERECT_RIGHT;
|
||||
int y = r.top + WD_FRAMERECT_TOP;
|
||||
int x = r.left + WD_FRAMERECT_LEFT;
|
||||
|
||||
int pos = -this->vscroll->GetPosition();
|
||||
const int cap = this->vscroll->GetCapacity();
|
||||
|
||||
/* Section for drawing the global goals */
|
||||
if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_GLOBAL_TITLE);
|
||||
pos++;
|
||||
|
||||
uint num = 0;
|
||||
const Goal *s;
|
||||
FOR_ALL_GOALS(s) {
|
||||
if (s->company == INVALID_COMPANY) {
|
||||
if (IsInsideMM(pos, 0, cap)) {
|
||||
/* Display the goal */
|
||||
SetDParamStr(0, s->text);
|
||||
DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT);
|
||||
}
|
||||
pos++;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
if (num == 0) {
|
||||
if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE);
|
||||
pos++;
|
||||
}
|
||||
|
||||
/* Section for drawing the company goals */
|
||||
pos++;
|
||||
if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_COMPANY_TITLE);
|
||||
pos++;
|
||||
num = 0;
|
||||
|
||||
FOR_ALL_GOALS(s) {
|
||||
if (s->company != INVALID_COMPANY) {
|
||||
if (IsInsideMM(pos, 0, cap)) {
|
||||
/* Display the goal */
|
||||
SetDParamStr(0, s->text);
|
||||
DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT);
|
||||
}
|
||||
pos++;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
if (num == 0) {
|
||||
if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnResize()
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_GL_PANEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Some data on this window has become invalid.
|
||||
* @param data Information about the changed data.
|
||||
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
|
||||
*/
|
||||
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
||||
{
|
||||
if (!gui_scope) return;
|
||||
this->vscroll->SetCount(this->CountLines());
|
||||
}
|
||||
};
|
||||
|
||||
static const NWidgetPart _nested_goals_list_widgets[] = {
|
||||
NWidget(NWID_HORIZONTAL),
|
||||
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
|
||||
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GOALS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
||||
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
|
||||
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
|
||||
EndContainer(),
|
||||
NWidget(NWID_HORIZONTAL),
|
||||
NWidget(WWT_PANEL, COLOUR_BROWN, WID_GL_PANEL), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetResize(1, 1), SetScrollbar(WID_GL_SCROLLBAR), EndContainer(),
|
||||
NWidget(NWID_VERTICAL),
|
||||
NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_GL_SCROLLBAR),
|
||||
NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
};
|
||||
|
||||
static const WindowDesc _goals_list_desc(
|
||||
WDP_AUTO, 500, 127,
|
||||
WC_GOALS_LIST, WC_NONE,
|
||||
0,
|
||||
_nested_goals_list_widgets, lengthof(_nested_goals_list_widgets)
|
||||
);
|
||||
|
||||
|
||||
void ShowGoalsList()
|
||||
{
|
||||
AllocateWindowDescFront<GoalListWindow>(&_goals_list_desc, 0);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file goal_type.h basic types related to goals */
|
||||
|
||||
#ifndef GOAL_TYPE_H
|
||||
#define GOAL_TYPE_H
|
||||
|
||||
/** Types of goal destinations */
|
||||
enum GoalType {
|
||||
GT_NONE, ///< Destination is not linked
|
||||
GT_TILE, ///< Destination is a tile
|
||||
GT_INDUSTRY, ///< Destination is an industry
|
||||
GT_TOWN, ///< Destination is a town
|
||||
GT_COMPANY, ///< Destination is a company
|
||||
};
|
||||
typedef SimpleTinyEnumT<GoalType, byte> GoalTypeByte; ///< The GoalType packed into a byte for savegame purposes.
|
||||
|
||||
typedef uint32 GoalTypeID; ///< Contains either tile, industry ID, town ID or company ID (or INVALID_GOALTYPE)
|
||||
static const GoalTypeID INVALID_GOALTYPE = 0xFFFFFFFF; ///< Invalid/unknown index of GoalType
|
||||
|
||||
typedef uint16 GoalID; ///< ID of a goal
|
||||
struct Goal;
|
||||
|
||||
extern GoalID _new_goal_id;
|
||||
|
||||
#endif /* GOAL_TYPE_H */
|
@ -0,0 +1,45 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file goal_sl.cpp Code handling saving and loading of goals */
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include "../goal_base.h"
|
||||
|
||||
#include "saveload.h"
|
||||
|
||||
static const SaveLoad _goals_desc[] = {
|
||||
SLE_VAR(Goal, company, SLE_UINT16),
|
||||
SLE_VAR(Goal, type, SLE_UINT16),
|
||||
SLE_VAR(Goal, dst, SLE_UINT32),
|
||||
SLE_STR(Goal, text, SLE_STR, 0),
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
static void Save_GOAL()
|
||||
{
|
||||
Goal *s;
|
||||
FOR_ALL_GOALS(s) {
|
||||
SlSetArrayIndex(s->index);
|
||||
SlObject(s, _goals_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_GOAL()
|
||||
{
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
Goal *s = new (index) Goal();
|
||||
SlObject(s, _goals_desc);
|
||||
}
|
||||
}
|
||||
|
||||
extern const ChunkHandler _goal_chunk_handlers[] = {
|
||||
{ 'GOAL', Save_GOAL, Load_GOAL, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
};
|
@ -0,0 +1,36 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
|
||||
|
||||
#include "../script_goal.hpp"
|
||||
#include "../template/template_goal.hpp.sq"
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptGoal, ST_GS>() { return "GSGoal"; }
|
||||
|
||||
void SQGSGoal_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptGoal, ST_GS> SQGSGoal("GSGoal");
|
||||
SQGSGoal.PreRegister(engine);
|
||||
SQGSGoal.AddConstructor<void (ScriptGoal::*)(), 1>(engine, "x");
|
||||
|
||||
SQGSGoal.DefSQConst(engine, ScriptGoal::GOAL_INVALID, "GOAL_INVALID");
|
||||
SQGSGoal.DefSQConst(engine, ScriptGoal::GT_NONE, "GT_NONE");
|
||||
SQGSGoal.DefSQConst(engine, ScriptGoal::GT_TILE, "GT_TILE");
|
||||
SQGSGoal.DefSQConst(engine, ScriptGoal::GT_INDUSTRY, "GT_INDUSTRY");
|
||||
SQGSGoal.DefSQConst(engine, ScriptGoal::GT_TOWN, "GT_TOWN");
|
||||
SQGSGoal.DefSQConst(engine, ScriptGoal::GT_COMPANY, "GT_COMPANY");
|
||||
|
||||
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::IsValidGoal, "IsValidGoal", 2, ".i");
|
||||
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::New, "New", 5, ".i.ii");
|
||||
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::Remove, "Remove", 2, ".i");
|
||||
|
||||
SQGSGoal.PostRegister(engine);
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file script_goal.cpp Implementation of ScriptGoal. */
|
||||
|
||||
#include "../../stdafx.h"
|
||||
#include "script_goal.hpp"
|
||||
#include "script_error.hpp"
|
||||
#include "script_industry.hpp"
|
||||
#include "script_map.hpp"
|
||||
#include "script_town.hpp"
|
||||
#include "../script_instance.hpp"
|
||||
#include "../../command_type.h"
|
||||
#include "../../settings_type.h"
|
||||
#include "../../openttd.h"
|
||||
#include "../../network/network.h"
|
||||
#include "../../goal_base.h"
|
||||
#include "../../string_func.h"
|
||||
|
||||
/* static */ bool ScriptGoal::IsValidGoal(GoalID goal_id)
|
||||
{
|
||||
return ::Goal::IsValidID(goal_id);
|
||||
}
|
||||
|
||||
/* static */ ScriptGoal::GoalID ScriptGoal::New(ScriptCompany::CompanyID company, const char *goal, GoalType type, uint32 destination)
|
||||
{
|
||||
EnforcePrecondition(GOAL_INVALID, !StrEmpty(goal));
|
||||
EnforcePrecondition(GOAL_INVALID, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
|
||||
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));
|
||||
|
||||
uint8 c = company;
|
||||
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
|
||||
|
||||
if (!ScriptObject::DoCommand(0, type | (c << 8), destination, CMD_CREATE_GOAL, goal, &ScriptInstance::DoCommandReturnGoalID)) return GOAL_INVALID;
|
||||
|
||||
/* In case of test-mode, we return GoalID 0 */
|
||||
return (ScriptGoal::GoalID)0;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptGoal::Remove(GoalID goal_id)
|
||||
{
|
||||
EnforcePrecondition(false, IsValidGoal(goal_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, goal_id, 0, CMD_REMOVE_GOAL);
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file script_goal.hpp Everything to manipulate the current running goal. */
|
||||
|
||||
#ifndef SCRIPT_GOAL_HPP
|
||||
#define SCRIPT_GOAL_HPP
|
||||
|
||||
#include "script_object.hpp"
|
||||
#include "script_company.hpp"
|
||||
#include "../../goal_type.h"
|
||||
|
||||
/**
|
||||
* Class that handles some goal related functions.
|
||||
* @api game
|
||||
*/
|
||||
class ScriptGoal : public ScriptObject {
|
||||
public:
|
||||
/**
|
||||
* The goal IDs.
|
||||
*/
|
||||
enum GoalID {
|
||||
/* Note: these values represent part of the in-game GoalID enum */
|
||||
GOAL_INVALID = ::INVALID_GOALTYPE, ///< An invalid goal id.
|
||||
};
|
||||
|
||||
/**
|
||||
* Goal types that can be given to a goal.
|
||||
*/
|
||||
enum GoalType {
|
||||
/* Note: these values represent part of the in-game GoalType enum */
|
||||
GT_NONE = ::GT_NONE, ///< Destination is not linked.
|
||||
GT_TILE = ::GT_TILE, ///< Destination is a tile.
|
||||
GT_INDUSTRY = ::GT_INDUSTRY, ///< Destination is an industry.
|
||||
GT_TOWN = ::GT_TOWN, ///< Destination is a town.
|
||||
GT_COMPANY = ::GT_COMPANY, ///< Destination is a company.
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether this is a valid goalID.
|
||||
* @param goal_id The GoalID to check.
|
||||
* @return True if and only if this goal is valid.
|
||||
*/
|
||||
static bool IsValidGoal(GoalID goal_id);
|
||||
|
||||
/**
|
||||
* Create a new goal.
|
||||
* @param company The company to create the goal for, or ScriptCompany::COMPANY_INVALID for all.
|
||||
* @param goal The goal to add to the GUI.
|
||||
* @param type The type of the goal.
|
||||
* @param destination The destination of the #type type.
|
||||
* @return The new GoalID, or GOAL_INVALID if it failed.
|
||||
* @pre goal != NULL.
|
||||
* @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID.
|
||||
*/
|
||||
static GoalID New(ScriptCompany::CompanyID company, const char *goal, GoalType type, uint32 destination);
|
||||
|
||||
/**
|
||||
* Remove a goal from the list.
|
||||
* @param goal_id The goal to remove.
|
||||
* @return True if the action succeeded.
|
||||
* @pre IsValidGoal(goal_id).
|
||||
*/
|
||||
static bool Remove(GoalID goal_id);
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_GOAL_HPP */
|
@ -0,0 +1,27 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
|
||||
|
||||
#include "../script_goal.hpp"
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow enums to be used as Squirrel parameters */
|
||||
template <> inline ScriptGoal::GoalID GetParam(ForceType<ScriptGoal::GoalID>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptGoal::GoalID)tmp; }
|
||||
template <> inline int Return<ScriptGoal::GoalID>(HSQUIRRELVM vm, ScriptGoal::GoalID res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
template <> inline ScriptGoal::GoalType GetParam(ForceType<ScriptGoal::GoalType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptGoal::GoalType)tmp; }
|
||||
template <> inline int Return<ScriptGoal::GoalType>(HSQUIRRELVM vm, ScriptGoal::GoalType res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
|
||||
/* Allow ScriptGoal to be used as Squirrel parameter */
|
||||
template <> inline ScriptGoal *GetParam(ForceType<ScriptGoal *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptGoal *)instance; }
|
||||
template <> inline ScriptGoal &GetParam(ForceType<ScriptGoal &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptGoal *)instance; }
|
||||
template <> inline const ScriptGoal *GetParam(ForceType<const ScriptGoal *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptGoal *)instance; }
|
||||
template <> inline const ScriptGoal &GetParam(ForceType<const ScriptGoal &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptGoal *)instance; }
|
||||
template <> inline int Return<ScriptGoal *>(HSQUIRRELVM vm, ScriptGoal *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "Goal", res, NULL, DefSQDestructorCallback<ScriptGoal>, true); return 1; }
|
||||
} // namespace SQConvert
|
@ -0,0 +1,22 @@
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file goal_widget.h Types related to the goal widgets. */
|
||||
|
||||
#ifndef WIDGETS_GOAL_WIDGET_H
|
||||
#define WIDGETS_GOAL_WIDGET_H
|
||||
|
||||
/** Widgets of the #GoalListWindow class. */
|
||||
enum GoalListWidgets {
|
||||
WID_GL_PANEL, ///< Panel of the window.
|
||||
WID_GL_SCROLLBAR, ///< Scrollbar of the panel.
|
||||
};
|
||||
|
||||
#endif /* WIDGETS_GOAL_WIDGET_H */
|
Loading…
Reference in New Issue