Elaztek Developer Hub
Blamite Game Engine - blam!  00453.06.08.26.0624.blamite
The core library for the Blamite Game Engine.
drop.hpp
Go to the documentation of this file.
1 #include "../console.h"
2 
3 #include <OGRE/OgreItem.h>
4 #include <Strings/components/resources/strings/strings.h>
5 
13 
15 {
22  {
23  public:
25  {
26  name = "drop";
27  description = "drops the named tag e.g. objects/vehicles/banshee/banshee.vehicle";
28  aliases = {"spawn", "summon", "create", "drop_safe"};
29 
31  }
32 
33  BlamResult Execute(std::vector<std::string> arguments)
34  {
35  if (arguments.size() == 0)
36  {
37  return BlamResult::Error_Command_WrongArgumentCount;
38  }
39 
40  std::string tag_path = arguments.at(0);
42 
43  if (!tag)
44  {
45  BlamResult load_result = Blam::Content::Tags::LoadTagFromFile(tag_path);
46 
47  if (load_result == BlamResult::Error_FileNotFound)
48  {
49  Blam::Logger::LogEventForce("couldn't load tag '" + tag_path + "' to place", WSV_ERROR);
50  Blam::Logger::LogEventForce("tag '" + tag_path + "' does not exist");
51  return BlamResult::Success_OK;
52  }
53  else if (BR_FAILED(load_result))
54  {
55  Blam::Logger::LogEventForce("couldn't load tag '" + tag_path + "' to place", WSV_ERROR);
56  Blam::Logger::LogEventForce("tag '" + tag_path + "' load result was " + std::to_string(load_result)
57  + ": " + ERROR_TEXT(load_result));
58  return BlamResult::Success_OK;
59  }
60 
61  tag = Blam::Content::Tags::GetTagData(tag_path);
62  }
63 
64  if (!tag)
65  {
66  Blam::Logger::LogEventForce("couldn't load tag '" + tag_path + "' to place", WSV_ERROR);
67  Blam::Logger::LogEventForce("tag '" + tag_path + "' does not exist");
68  return BlamResult::Success_OK;
69  }
70 
72 
73  if (!world_state)
74  {
75  Blam::Logger::LogEventForce("cannot place: world state not ready", WSV_ERROR);
76  return BlamResult::Success_OK;
77  }
78 
79  BlamWorldObject_Tag* object = world_state->CreateTagObject(tag, false);
80 
81  if (object && object->ValidateTagData())
82  {
83  world_state->AddObject(object);
84  BlamVector3 pos = Blam::Rendering::GetMousePosition3D();
85 
87  {
88  pos.x = 0;
89  pos.y = 0;
90  pos.z = 1;
91  }
92 
93  object->SetPosition(pos);
94  Blam::Logger::LogEventForce("placed '" + tag_path + "'");
95  }
96  else
97  {
98  if (object) delete object;
100 
101  if (tag_class)
102  {
103  Blam::Logger::LogEventForce("don't know how to place tags of type '" + tag_class->class_name_long + "'", BlamLogLevel::Error);
104  }
105  else
106  {
107  Blam::Logger::LogEventForce("don't know how to place tags of type '" + tag->tag_class + "'", BlamLogLevel::Error);
108  Blam::Logger::LogEventForce("tried to lookup tag class with short name '" + tag->tag_class + "', but result was nullptr", BlamLogLevel::Error);
109  }
110  }
111 
112  return BlamResult::Success_OK;
113  }
114  };
115 }
Blam::World::GetWorldState
BLAM BlamWorldState * GetWorldState()
Retrieves the current world state.
Definition: world.cpp:56
object
Definition: object.h:27
tag_io.h
BlamWorldState::AddObject
void AddObject(BlamWorldObject *object)
Definition: BlamWorldState.cpp:107
BlamConsoleCommand::description
std::string description
An optional description of the command. Shown when using the classify command.
Definition: console.h:36
Blam::Rendering::GetMousePosition3D
BLAM BlamVector3 GetMousePosition3D()
Definition: ogre.cpp:757
logger.h
keyboard.h
Blam::Director::Use2DCamera
BLAM bool Use2DCamera()
Definition: director.cpp:74
BlamConsoleCommand
Class used to represent a console command.
Definition: console.h:33
Blam::Content::Tags::LoadTagFromFile
BLAM BlamResult LoadTagFromFile(std::string tag_path, bool reload_if_already_loaded=true)
Loads a tag from the engine's tag directory (default is '.
Definition: tag_io.cpp:319
Blam::Content::Tags::GetTagClass
BLAM_EXT_API BlamTagClass * GetTagClass(std::string id)
Retrieves a tag class that matches the given string.
Definition: tagclass.cpp:72
director.h
Blam::Resources::Console::DropCommand::DropCommand
DropCommand()
Definition: drop.hpp:24
rendering.h
BlamWorldState::CreateTagObject
BlamWorldObject_Tag * CreateTagObject(BlamTagData *tag_data, bool add_to_world=true)
Definition: BlamWorldState.cpp:258
BlamWorldObject_Tag
Class representing a tag-based world object.
Definition: world_objects.h:278
Blam::Resources::Console::DropCommand
Class for the drop command.
Definition: drop.hpp:21
BlamTagClass::class_name_long
std::string class_name_long
The longer class name. Typically shown alongside short name for user-friendliness.
Definition: tags.h:205
BlamConsoleCommand::name
std::string name
The name of the console command.
Definition: console.h:35
Blam::Resources::Console::DropCommand::Execute
BlamResult Execute(std::vector< std::string > arguments)
Called upon command execution.
Definition: drop.hpp:33
Blam::Content::Tags::GetTagData
BLAM BlamTagData * GetTagData(std::string tag_path)
Retrieves information for a given tag.
Definition: tags.cpp:81
BlamConsoleCommand::type
BlamCommandType type
The type of command this is. See #Blam::Resources::Console::BlamCommandType for more information.
Definition: console.h:40
Blam::Logger::LogEventForce
BLAM void LogEventForce(std::string message)
Forcibly logs a message to the log and/or console.
Definition: aliases.cpp:262
tagclass.h
tags.h
BlamConsoleCommand::aliases
std::vector< std::string > aliases
A list of aliases for the command. Executing any of these instead of the command name will behave the...
Definition: console.h:38
BlamTagData
Class used to contain and access tag data.
Definition: tags.h:125
Blam::Resources::Console
Namespace for things relating to the debug console.
Definition: abort.hpp:5
BlamWorldState
Class representing a world state.
Definition: world_objects.h:715
BlamTagClass
Class representing a tag class.
Definition: tags.h:202
BlamCommandType::Builtin
@ Builtin
A command that is hard-coded into the engine.
BlamTagData::tag_class
std::string tag_class
The tag's short class name.
Definition: tags.h:146