From 86fbbef3d74d2d4c7ed530981df20129c68d7839 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 22 Aug 2010 10:49:43 +0100 Subject: [PATCH] Stub interfaces for industry and cargo --- include/ICargo.hpp | 36 ++++++++++++++++++++++++++++++++++++ include/IIndustry.hpp | 34 ++++++++++++++++++++++++++++++++++ include/IRollingStock.hpp | 6 +++++- include/IScenery.hpp | 2 ++ include/IStation.hpp | 5 ----- src/Building.cpp | 6 ++++++ src/Engine.cpp | 6 ++++++ src/Train.cpp | 8 ++++---- src/Tree.cpp | 6 ++++++ src/Waggon.cpp | 6 ++++++ 10 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 include/ICargo.hpp create mode 100644 include/IIndustry.hpp diff --git a/include/ICargo.hpp b/include/ICargo.hpp new file mode 100644 index 0000000..a768f5d --- /dev/null +++ b/include/ICargo.hpp @@ -0,0 +1,36 @@ +// +// Copyright (C) 2010 Nick Gasson +// +// This program 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, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 this program. If not, see . +// + +#ifndef INC_ICARGO_HPP +#define INC_ICARGO_HPP + +#include "Platform.hpp" + +enum CargoType { + COAL +}; + +// A quantity of cargo loaded on a truck or waiting at a station +struct ICargo { + virtual ~ICargo() {} + + virtual CargoType type() const = 0; +}; + +typedef shared_ptr ICargoPtr; + +#endif diff --git a/include/IIndustry.hpp b/include/IIndustry.hpp new file mode 100644 index 0000000..6a4d0ca --- /dev/null +++ b/include/IIndustry.hpp @@ -0,0 +1,34 @@ +// +// Copyright (C) 2010 Nick Gasson +// +// This program 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, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 this program. If not, see . +// + +#ifndef INC_IINDUSTRY_HPP +#define INC_IINDUSTRY_HPP + +#include "Platform.hpp" +#include "ICargo.hpp" + +// Industries produce and consume cargo +struct IIndustry { + virtual ~IIndustry() {} + + virtual CargoType produces() const = 0; + virtual CargoType consumes() const = 0; +}; + +typedef shared_ptr IIndustryPtr; + +#endif diff --git a/include/IRollingStock.hpp b/include/IRollingStock.hpp index 614200e..9254b84 100644 --- a/include/IRollingStock.hpp +++ b/include/IRollingStock.hpp @@ -1,5 +1,5 @@ // -// Copyright (C) 2009 Nick Gasson +// Copyright (C) 2009-2010 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ #include "Platform.hpp" #include "IController.hpp" #include "Maths.hpp" +#include "ICargo.hpp" // Interface for various powered and unpowered parts of the train struct IRollingStock { @@ -43,6 +44,9 @@ struct IRollingStock { // Return the mass of the vehicle in tons virtual double mass() const = 0; + + // The cargo currently carried, if any + virtual ICargoPtr cargo() const = 0; }; typedef shared_ptr IRollingStockPtr; diff --git a/include/IScenery.hpp b/include/IScenery.hpp index 6664d25..683da32 100644 --- a/include/IScenery.hpp +++ b/include/IScenery.hpp @@ -21,6 +21,7 @@ #include "Platform.hpp" #include "IXMLSerialisable.hpp" #include "IMesh.hpp" +#include "IIndustry.hpp" // Static scenery such as trees struct IScenery : IXMLSerialisable { @@ -32,6 +33,7 @@ struct IScenery : IXMLSerialisable { virtual void merge(IMeshBufferPtr buf) = 0; virtual const string& name() const = 0; virtual Point size() const = 0; + virtual IIndustryPtr industry() const = 0; }; typedef shared_ptr ISceneryPtr; diff --git a/include/IStation.hpp b/include/IStation.hpp index aae5df7..e4b77d2 100644 --- a/include/IStation.hpp +++ b/include/IStation.hpp @@ -24,11 +24,6 @@ #include -// The different types of cargo that may be carried -enum Cargo { - COAL -}; - // A station occupies one of more track segments and supplies and // accepts a set of cargo // The information about which track segments it actually occupies diff --git a/src/Building.cpp b/src/Building.cpp index a52c19f..cda3102 100644 --- a/src/Building.cpp +++ b/src/Building.cpp @@ -36,6 +36,7 @@ public: void set_position(float x, float y, float z); void merge(IMeshBufferPtr buf); Point size() const; + IIndustryPtr industry() const; // IXMLSerialisable interface xml::element to_xml() const; @@ -78,6 +79,11 @@ Point Building::size() const max(static_cast(round(dim.z)), 1)); } +IIndustryPtr Building::industry() const +{ + return IIndustryPtr(); +} + void Building::set_position(float x, float y, float z) { position = make_vector(x, y, z); diff --git a/src/Engine.cpp b/src/Engine.cpp index 8f6ae3a..e8f3d92 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -70,6 +70,7 @@ public: double mass() const { return my_mass; } IControllerPtr controller() { return shared_from_this(); } float length() const { return model->dimensions().x; } + ICargoPtr cargo() const; // IController interface void act_on(Action an_action); @@ -229,6 +230,11 @@ void Engine::update(int delta, double gravity) #endif } +ICargoPtr Engine::cargo() const +{ + return ICargoPtr(); +} + // User interface to the engine void Engine::act_on(Action an_action) { diff --git a/src/Train.cpp b/src/Train.cpp index 3ae3679..e2351a8 100644 --- a/src/Train.cpp +++ b/src/Train.cpp @@ -1,5 +1,5 @@ // -// Copyright (C) 2009 Nick Gasson +// Copyright (C) 2009-2010 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -33,17 +33,17 @@ class Train : public ITrain { public: Train(IMapPtr a_map); - + + // ITrain interface void render() const; void update(int a_delta); - Vector front() const; ITrackSegmentPtr track_segment() const; track::Direction direction() const; track::Position tile() const { return engine().travel_token.position; } - double speed() const { return parts.front().vehicle->speed(); } IControllerPtr controller() { return parts.front().vehicle->controller(); } + private: // The different parts of the train are on different track segments struct Part : boost::equality_comparable { diff --git a/src/Tree.cpp b/src/Tree.cpp index 1164e85..090d664 100644 --- a/src/Tree.cpp +++ b/src/Tree.cpp @@ -41,6 +41,7 @@ public: const string& name() const { return name_; } void merge(IMeshBufferPtr buf); Point size() const; + IIndustryPtr industry() const; // IXMLCallback interface void text(const string& local_name, const string& content); @@ -75,6 +76,11 @@ Tree::Tree(IResourcePtr res) delete parser_state; } +IIndustryPtr Tree::industry() const +{ + return IIndustryPtr(); +} + void Tree::text(const string& local_name, const string& content) { if (local_name == "model") diff --git a/src/Waggon.cpp b/src/Waggon.cpp index 835613a..5cd768f 100644 --- a/src/Waggon.cpp +++ b/src/Waggon.cpp @@ -39,6 +39,7 @@ public: double speed() const { return 0.0; } double mass() const { return 1.0; } float length() const { return model->dimensions().x; } + ICargoPtr cargo() const; // IXMLCallback interface void text(const string& local_name, const string& a_string); @@ -59,6 +60,11 @@ Waggon::Waggon(IResourcePtr a_res) parser->parse(resource->xml_file_name(), *this); } +ICargoPtr Waggon::cargo() const +{ + return ICargoPtr(); +} + // Load information from the XML file void Waggon::text(const string& local_name, const string& a_string) { -- 2.39.2