3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "exceptions.h"
27 #include "inventory.h"
32 class InventoryManager;
41 bool operator == (const RollbackNode &other)
43 return (name == other.name && param1 == other.param1 &&
44 param2 == other.param2 && meta == other.meta);
46 bool operator != (const RollbackNode &other) { return !(*this == other); }
48 RollbackNode() = default;
50 RollbackNode(Map *map, v3s16 p, IGameDef *gamedef);
59 TYPE_MODIFY_INVENTORY_STACK,
60 } type = TYPE_NOTHING;
64 bool actor_is_guess = false;
70 std::string inventory_location;
71 std::string inventory_list;
74 ItemStack inventory_stack;
76 RollbackAction() = default;
78 void setSetNode(v3s16 p_, const RollbackNode &n_old_,
79 const RollbackNode &n_new_)
87 void setModifyInventoryStack(const std::string &inventory_location_,
88 const std::string &inventory_list_, u32 index_,
89 bool add_, const ItemStack &inventory_stack_)
91 type = TYPE_MODIFY_INVENTORY_STACK;
92 inventory_location = inventory_location_;
93 inventory_list = inventory_list_;
94 inventory_index = index_;
96 inventory_stack = inventory_stack_;
99 // String should not contain newlines or nulls
100 std::string toString() const;
102 // Eg. flowing water level changes are not important
103 bool isImportant(IGameDef *gamedef) const;
105 bool getPosition(v3s16 *dst) const;
107 bool applyRevert(Map *map, InventoryManager *imgr, IGameDef *gamedef) const;
111 class IRollbackManager
114 virtual void reportAction(const RollbackAction &action) = 0;
115 virtual std::string getActor() = 0;
116 virtual bool isActorGuess() = 0;
117 virtual void setActor(const std::string &actor, bool is_guess) = 0;
118 virtual std::string getSuspect(v3s16 p, float nearness_shortcut,
119 float min_nearness) = 0;
121 virtual ~IRollbackManager() = default;;
122 virtual void flush() = 0;
123 // Get all actors that did something to position p, but not further than
124 // <seconds> in history
125 virtual std::list<RollbackAction> getNodeActors(v3s16 pos, int range,
126 time_t seconds, int limit) = 0;
127 // Get actions to revert <seconds> of history made by <actor>
128 virtual std::list<RollbackAction> getRevertActions(const std::string &actor,
133 class RollbackScopeActor
136 RollbackScopeActor(IRollbackManager * rollback_,
137 const std::string & actor, bool is_guess = false) :
141 old_actor = rollback->getActor();
142 old_actor_guess = rollback->isActorGuess();
143 rollback->setActor(actor, is_guess);
146 ~RollbackScopeActor()
149 rollback->setActor(old_actor, old_actor_guess);
154 IRollbackManager * rollback;
155 std::string old_actor;
156 bool old_actor_guess;