Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-10-20 18:24:35 +0000
committerStijn Buys <ingar@osirion.org>2012-10-20 18:24:35 +0000
commitdb69f96fbf5ac5321bdcb1e86ff07d1e35de9fec (patch)
treebc997c204e36807cc61736d971ec48d9826117b9 /src
parent75274ebd6ba90784f5aa837b7e5ea97fc6bfb720 (diff)
Added func_drop, added spacemine template.
Diffstat (limited to 'src')
-rw-r--r--src/game/base/game.cc78
-rw-r--r--src/game/base/game.h1
-rw-r--r--src/game/base/spacemine.cc62
-rw-r--r--src/game/base/spacemine.h9
-rw-r--r--src/game/base/template.cc8
-rw-r--r--src/game/base/weapon.cc9
-rw-r--r--src/game/base/weapon.h9
7 files changed, 126 insertions, 50 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 182c856..c87c9b6 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -951,6 +951,81 @@ void Game::func_buy(core::Player *player, const std::string &args)
}
}
+// drop item requests
+void Game::func_drop(core::Player *player, const std::string &args)
+{
+ // must be joined to buy items
+ if (!player->control()) {
+ player->send("^WYou need to join the game first!");
+ return;
+ }
+
+ Ship *ship = static_cast<Ship *>(player->control());
+
+ // cannot be docked to drop items
+ if (ship->state() == core::Entity::Docked) {
+ player->send("^WCan't drop items while docked!");
+ return;
+ }
+
+ // cannot drop items while jumping
+ if ((ship->state() == core::Entity::Jump) || (ship->state() == core::Entity::JumpInitiate)) {
+ player->send("^WCan not eject while hyperspace jump drive is active");
+ return;
+ }
+
+ std::istringstream is(args);
+ std::string labelstr;
+
+ if (!(is >> labelstr)) {
+ player->send("Usage: drop [label] drop an item");
+ return;
+ } else {
+ aux::to_label(labelstr);
+ }
+
+ if (labelstr.compare("mine") == 0) {
+ // drop a mine
+
+ // find a mine in inventory
+ core::Item *item = 0;
+ for (core::Inventory::Items::iterator it = ship->inventory()->items().begin(); (!item) && (it != ship->inventory()->items().end()); it++) {
+ if ((*it)->info()->type() == Weapon::infotype()) {
+ const Weapon *weapon = static_cast<const Weapon *>((*it)->info());
+
+ if (weapon->subtype() == Weapon::Mine) {
+ item = (*it);
+ }
+ }
+ }
+
+ if (!item) {
+ player->send("^WNo mines in inventory!");
+ return;
+ }
+
+ // create a spacemine entity
+ SpaceMine *spacemine = new SpaceMine(item->info());
+ spacemine->set_color(ship->color());
+ spacemine->set_color_second(ship->color_second());
+ spacemine->set_location(ship->location() + ship->axis().forward() * -1.0f * (ship->radius() + spacemine->radius()));
+ spacemine->set_axis(ship->axis());
+ spacemine->set_zone(ship->zone());
+ spacemine->set_info(item->info());
+
+ player->send(item->info()->name() + " ejected");
+ player->sound("fx/eject");
+
+ spacemine->reset();
+
+ // remove mine from inventory
+ item->set_amount(1);
+ if (item->amount() == 0) {
+ ship->inventory()->erase(item->id());
+ }
+ }
+}
+
// eject item request
void Game::func_eject(core::Player *player, const std::string &args)
{
@@ -1337,6 +1412,9 @@ Game::Game() : core::Module("Project::OSiRiON", true)
func = core::Func::add("sell", Game::func_sell);
func->set_info("[string] [string] [int] sell an item: specify type, label and amount");
+ func = core::Func::add("drop", Game::func_drop);
+ func->set_info("[label] drop an item and activate it");
+
func = core::Func::add("eject", Game::func_eject);
func->set_info("[string] [string] [int] eject an item from inventory: specify type, label and amount");
diff --git a/src/game/base/game.h b/src/game/base/game.h
index 6a17d16..1bdd5ac 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -131,6 +131,7 @@ private:
static void func_give(core::Player *player, const std::string &args);
static void func_specs(core::Player *player, const std::string &args);
static void func_eject(core::Player *player, const std::string &args);
+ static void func_drop(core::Player *player, std::string const &args);
static void func_beam(core::Player *player, const std::string &args);
/* ---- target functions ----------------------------------- */
diff --git a/src/game/base/spacemine.cc b/src/game/base/spacemine.cc
index fbbca51..af64514 100644
--- a/src/game/base/spacemine.cc
+++ b/src/game/base/spacemine.cc
@@ -11,21 +11,31 @@
namespace game
{
+const Template *SpaceMine::spacemine_template = 0;
-SpaceMine::SpaceMine() : EntityDynamic()
+SpaceMine::SpaceMine(const core::Info *info) : EntityDynamic()
{
entity_moduletypeid = spacemine_enttype;
set_name("Space mine");
set_label("spacemine");
set_flag(core::Entity::KeepAlive);
-/*
+ set_shape(core::Entity::Sphere);
+
// setting
set_radius(0);
// use template settings if available
- if (cargopod_template) {
- cargopod_template->apply(this);
+ if (spacemine_template) {
+ spacemine_template->apply(this);
+ }
+
+ // item type model overrides template
+ if (info) {
+ set_info(info);
+ set_modelname(info->modelname());
+ set_name(info->name());
+ set_label(info->label());
}
// radius fallback
@@ -36,11 +46,7 @@ SpaceMine::SpaceMine() : EntityDynamic()
set_radius(0.1f);
}
}
-*/
- // FIXME should be loaded from the Weapon Info
- set_shape(core::Entity::Sphere);
- set_modelname("maps/static/cargopod001");
- set_radius(0.10f);
+
spacemine_detonated_timestamp = 0;
// activate physics
@@ -106,44 +112,6 @@ void SpaceMine::frame(const unsigned long elapsed)
}
}
}
-
-// main 'eject mine' function
-void SpaceMine::eject(core::EntityControlable *ejector)
-{
- if (!ejector->inventory()) {
- return;
- }
-
- if ((ejector->state() == core::Entity::Jump) || (ejector->state() == core::Entity::JumpInitiate)) {
- if (ejector->owner()) {
- ejector->owner()->send("^WCan not eject while hyperspace jump drive is active!");
- }
- return;
- } else if ((ejector->state() == core::Entity::Impulse) || (ejector->state() == core::Entity::ImpulseInitiate)) {
- if (ejector->owner()) {
- ejector->owner()->send("^WCan not eject at impulse speed!");
- }
- return;
- } else if (ejector->state() != core::Entity::Normal) {
- return;
- }
-
- // create space mine
- SpaceMine *spacemine = new SpaceMine();
-
- spacemine->set_color(ejector->color());
- spacemine->set_color_second(ejector->color_second());
- spacemine->set_location(ejector->location() - ejector->axis().forward() * (ejector->radius() + spacemine->radius()));
- spacemine->set_axis(ejector->axis());
- spacemine->set_zone(ejector->zone());
-
- if (ejector->owner()) {
- ejector->owner()->send("Spacemine ejected");
- ejector->owner()->sound("fx/eject");
- }
-
- spacemine->reset();
-}
} // namespace game
diff --git a/src/game/base/spacemine.h b/src/game/base/spacemine.h
index cdb903c..632c48c 100644
--- a/src/game/base/spacemine.h
+++ b/src/game/base/spacemine.h
@@ -16,7 +16,7 @@ namespace game
class SpaceMine : public core::EntityDynamic
{
public:
- SpaceMine();
+ SpaceMine(const core::Info *info);
virtual ~SpaceMine();
virtual void upkeep(const unsigned long timestamp);
@@ -25,11 +25,14 @@ public:
virtual void frame(const unsigned long elapsed);
- static void eject(core::EntityControlable *ejector);
+ static inline void set_template (const Template *entitytemplate) {
+ spacemine_template = entitytemplate;
+ }
private:
-
unsigned long spacemine_detonated_timestamp;
+
+ static const Template *spacemine_template;
};
} // namespace game
diff --git a/src/game/base/template.cc b/src/game/base/template.cc
index fd04402..a2bf66c 100644
--- a/src/game/base/template.cc
+++ b/src/game/base/template.cc
@@ -10,6 +10,8 @@
#include "base/cargopod.h"
#include "base/navpoint.h"
#include "base/jumppoint.h"
+#include "base/cargopod.h"
+#include "base/spacemine.h"
namespace game {
@@ -168,6 +170,12 @@ bool Template::init()
con_warn << "Template 'cargopod' not found!" << std::endl;
}
+ entitytemplate = Template::find(std::string("spacemine"));
+ SpaceMine::set_template(entitytemplate);
+ if (!entitytemplate) {
+ con_warn << "Template 'spacemine' not found!" << std::endl;
+ }
+
entitytemplate = Template::find(std::string("navpoint"));
NavPoint::set_template(entitytemplate);
if (!entitytemplate) {
diff --git a/src/game/base/weapon.cc b/src/game/base/weapon.cc
index 8be9f9a..59384e2 100644
--- a/src/game/base/weapon.cc
+++ b/src/game/base/weapon.cc
@@ -154,16 +154,19 @@ bool Weapon::init()
if (weaponsini.got_section("mine")) {
weapon = new Weapon();
weapon->set_stackable(true);
+ weapon->set_subtype(Mine);
count++;
} else if (weaponsini.got_section("cannon")) {
weapon = new Weapon();
weapon->set_stackable(false);
+ weapon->set_subtype(Cannon);
count++;
} else if (weaponsini.got_section("turret")) {
weapon = new Weapon();
weapon->set_stackable(false);
+ weapon->set_subtype(Turret);
count++;
} else if (weaponsini.got_section()) {
@@ -210,6 +213,7 @@ Weapon::Weapon() : core::Info(weapon_infotype)
set_volume(1);
set_level(1);
set_stackable(false);
+ set_subtype(Ammo);
}
Weapon::~Weapon()
@@ -226,5 +230,10 @@ void Weapon::set_level(const int level)
weapon_level = level;
}
+void Weapon::set_subtype(const SubType subtype)
+{
+ weapon_subtype = subtype;
+}
+
} // namespace game
diff --git a/src/game/base/weapon.h b/src/game/base/weapon.h
index 247a3e7..01a135b 100644
--- a/src/game/base/weapon.h
+++ b/src/game/base/weapon.h
@@ -14,9 +14,14 @@ namespace game
class Weapon : public core::Info {
public:
+ enum SubType {Ammo = 0, Cannon = 1, Turret = 2, Mine = 3 };
+
Weapon();
~Weapon();
+ inline SubType subtype() const {
+ return weapon_subtype;
+ }
inline bool stackable() const {
return weapon_stackable;
}
@@ -29,6 +34,8 @@ public:
void set_level(const int level);
+ void set_subtype(const SubType subtype);
+
/* --- static registry functions ---------------------------------- */
static Weapon *find(const std::string & label);
@@ -49,6 +56,8 @@ private:
int weapon_level;
bool weapon_stackable;
+
+ SubType weapon_subtype;
};
} // namespace game