git repos / saland

commit 8e333bb3

Poul Sander · 2019-07-28 15:00
8e333bb36fa3f5bab342a254fe811bde81bf8912 patch · browse files
parent c2fe186e9732f7333103d908b27ff7e3630652ca

Make "give" work with negative amounts

Changed files

M src/saland/GameConsoleCommand.cpp before
diff --git a/src/saland/GameConsoleCommand.cpp b/src/saland/GameConsoleCommand.cpp index 5be7fdd..5bb325d 100644 --- a/src/saland/GameConsoleCommand.cpp +++ b/src/saland/GameConsoleCommand.cpp
@@ -39,8 +39,21 @@ struct ConcoleCommandGiveItem : public ConsoleCommand {
error_msg += args.at(2)+ "\" into an integer";
throw std::runtime_error(error_msg);
}
+ if (quantity == 0) {
+ return std::string("Inventory not touched");
+ }
+ int prevCount = globalData.player.item_inventory[item_name];
globalData.player.item_inventory[item_name] += quantity;
- return std::string("Added ")+std::to_string(quantity)+" of "+item_name;
+ if (quantity > 0) {
+ return std::string("Added ")+std::to_string(quantity)+" of "+item_name;
+ }
+ else {
+ if (globalData.player.item_inventory[item_name] < 0) {
+ globalData.player.item_inventory[item_name] = 0;
+ }
+ return std::string("Removed ")+std::to_string(prevCount-globalData.player.item_inventory[item_name])+" of "+item_name;
+ }
+
}
virtual std::string helpMessage() const override {
@@ -48,6 +61,7 @@ struct ConcoleCommandGiveItem : public ConsoleCommand {
}
};
+
static ConcoleCommandGiveItem cc_give_item;