diff options
author | Stijn Buys <ingar@osirion.org> | 2009-01-25 11:59:24 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2009-01-25 11:59:24 +0000 |
commit | afb56bf384bbc585f242978b6b5366c474c5c7f7 (patch) | |
tree | 9f2d7e006b30ea0be8ebc9f15253b493ef65192f | |
parent | 443a8dc2b49be6e1fa668f43a12bf5f886a1bdcd (diff) |
make a player pay for ships,
add prize money to the race
-rw-r--r-- | src/game/base/racetrack.cc | 12 | ||||
-rw-r--r-- | src/game/base/ship.cc | 7 | ||||
-rw-r--r-- | src/game/base/shipdealer.cc | 23 |
3 files changed, 35 insertions, 7 deletions
diff --git a/src/game/base/racetrack.cc b/src/game/base/racetrack.cc index b543c9c..e818414 100644 --- a/src/game/base/racetrack.cc +++ b/src/game/base/racetrack.cc @@ -192,8 +192,18 @@ void RaceTrack::frame(float seconds) } else { std::stringstream msgstr; - msgstr << "^BRace completed in " << core::server()->time() - track_racestart << " seconds!"; + msgstr << "^BRace completed in " << core::server()->time() - track_racestart << " seconds!"; core::server()->broadcast(msgstr.str()); + + // prize money + unsigned long the_prize = (unsigned long) floorf(10000.0f / (core::server()->time() - track_racestart)); + player->add_credits(the_prize); + msgstr.clear(); + msgstr.str(""); + msgstr << "You receive " << the_prize << " credits." << std::endl; + player->send(msgstr.str()); + player->sound("game/buy"); + reset(); } } diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index c48bf7a..edfc949 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -27,8 +27,11 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable(owner, ship_enttype) { set_modelname(shipmodel->modelname()); - set_name(shipmodel->name() + ": <^B" + owner->name() + "^N>"); - set_label(shipmodel->label()); + set_name(shipmodel->name()); + + std::string str(aux::text_strip(owner->name())); + aux::to_label(str); + set_label(str); entity_moduletypeid = ship_enttype; diff --git a/src/game/base/shipdealer.cc b/src/game/base/shipdealer.cc index 83bc0dc..5aced0b 100644 --- a/src/game/base/shipdealer.cc +++ b/src/game/base/shipdealer.cc @@ -102,6 +102,7 @@ void ShipDealer::func_buy(core::Player *player, const std::string &args) } if (!Game::g_devel->value()) { + if (!shipdealer) { player->send("No ship dealer available"); return; @@ -111,6 +112,16 @@ void ShipDealer::func_buy(core::Player *player, const std::string &args) player->send("Ship dealer does not sell the " + shipmodel->name()); return; } + + // check price + if (shipmodel->price() > player->credits()) { + std::stringstream msgstr; + msgstr << "You require " << (shipmodel->price() - player->credits()) << " additional credits to buy the " << shipmodel->name(); + player->send(msgstr.str()); + return; + } + + player->add_credits(-shipmodel->price()); } // player has only ship for now @@ -132,10 +143,14 @@ void ShipDealer::func_buy(core::Player *player, const std::string &args) player->set_control(ship); } - player->send("^BPurchased " + aux::article(shipmodel->name())); - player->sound("game/buy-ship"); - - + // send the ship purchased message + std::stringstream msgstr; + msgstr << "^BPurchased " << aux::article(shipmodel->name()); + if (!Game::g_devel->value()) { + msgstr << " for " << shipmodel->price() << " credits"; + } + player->send(msgstr.str()); + player->sound("game/buy-ship"); } |