Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made the shops and shop events support price levels.

This permits to set a custom price depending on the shop friendshipness,
thus reducing the cost of items in the Layna village.

I also renamed the AddWare() function to AddObject() to be more consistent
with the rest of the API.
  • Loading branch information...
commit d62a02c12f29f9918588e99f303890afb1413c71 1 parent e754003
Yohann Ferreira authored
View
10 dat/maps/layna_village/layna_village_center_shop.lua
@@ -302,10 +302,12 @@ function _CreateEvents()
EventManager:RegisterEvent(event);
event = hoa_map.ShopEvent("layna: open shop");
- event:AddWare(1, 10); -- minor potion
- event:AddWare(30003, 1); -- tunic for Bronann
- event:AddWare(30004, 1); -- leather cloak for Kalya
- event:AddWare(40001, 3); -- leather cloak for Kalya
+ event:AddObject(1, 10); -- minor potion
+ event:AddObject(30003, 1); -- tunic for Bronann
+ event:AddObject(30004, 1); -- leather cloak for Kalya
+ event:AddObject(40001, 3); -- leather cloak for Kalya
+ event:SetPriceLevels(hoa_shop.ShopMode.SHOP_PRICE_VERY_GOOD, -- Flora is a good friend
+ hoa_shop.ShopMode.SHOP_PRICE_STANDARD);
EventManager:RegisterEvent(event);
View
27 src/modes/map/map_events.cpp
@@ -89,34 +89,13 @@ bool DialogueEvent::_Update() {
// ---------- ShopEvent Class Methods
// -----------------------------------------------------------------------------
-ShopEvent::ShopEvent(const std::string& event_id) :
- MapEvent(event_id, SHOP_EVENT)
-{}
-
-
-
-ShopEvent::~ShopEvent()
-{}
-
-
-void ShopEvent::AddWare(uint32 object_id, uint32 stock) {
- _wares.insert(std::make_pair(object_id, stock));
-}
-
-
-
void ShopEvent::_Start() {
ShopMode* shop = new ShopMode();
- for (std::set<std::pair<uint32, uint32> >::iterator i = _wares.begin(); i != _wares.end(); i++) {
+ for (std::set<std::pair<uint32, uint32> >::iterator i = _objects.begin(); i != _objects.end(); ++i)
shop->AddObject((*i).first, (*i).second);
- }
- ModeManager->Push(shop);
-}
-
-
-bool ShopEvent::_Update() {
- return true;
+ shop->SetPriceLevels(_buy_level, _sell_level);
+ ModeManager->Push(shop);
}
// -----------------------------------------------------------------------------
View
31 src/modes/map/map_events.h
@@ -23,6 +23,7 @@
#define __MAP_EVENTS_HEADER__
#include "modes/map/map_treasure.h"
+#include "modes/shop/shop_utils.h"
#include "engine/audio/audio_descriptor.h"
@@ -218,27 +219,45 @@ class DialogueEvent : public MapEvent {
class ShopEvent : public MapEvent {
public:
//! \param event_id The ID of this event
- ShopEvent(const std::string& event_id);
+ ShopEvent(const std::string& event_id):
+ MapEvent(event_id, SHOP_EVENT),
+ _buy_level(hoa_shop::SHOP_PRICE_STANDARD),
+ _sell_level(hoa_shop::SHOP_PRICE_STANDARD)
+ {}
- ~ShopEvent();
+ ~ShopEvent()
+ {}
- /** \brief Adds a ware to the list of objects for sale
+ /** \brief Adds an object to the list of objects for sale
*** \param object_id The ID of the GlobalObject to make available for purchase
*** \param stock The amount of the object to make available for purchase
*** \note All wares must be added before the _Start() method is called to ensure
*** that the wares actually appear in shop mode.
**/
- void AddWare(uint32 object_id, uint32 stock);
+ void AddObject(uint32 object_id, uint32 stock)
+ { _objects.insert(std::make_pair(object_id, stock)); }
+
+ //! \brief Set the shop quality levels which will handle pricing variations.
+ void SetPriceLevels(hoa_shop::SHOP_PRICE_LEVEL buy_level,
+ hoa_shop::SHOP_PRICE_LEVEL sell_level) {
+ _buy_level = buy_level;
+ _sell_level = sell_level;
+ }
protected:
//! \brief The GlobalObject IDs and stock count of all objects to be sold in the shop
- std::set<std::pair<uint32, uint32> > _wares;
+ std::set<std::pair<uint32, uint32> > _objects;
+
+ //! \brief The Shop quality levels. The more the level is, the worse it is for the player.
+ hoa_shop::SHOP_PRICE_LEVEL _buy_level;
+ hoa_shop::SHOP_PRICE_LEVEL _sell_level;
//! \brief Creates an instance of ShopMode and pushes it to the game mode stack
void _Start();
//! \brief Performs no operation (returns true)
- bool _Update();
+ bool _Update()
+ { return true; }
}; // class ShopEvent : public MapEvent
View
13 src/modes/mode_bindings.cpp
@@ -558,7 +558,8 @@ void BindModeCode() {
[
luabind::class_<ShopEvent, MapEvent>("ShopEvent")
.def(luabind::constructor<std::string>())
- .def("AddWare", &ShopEvent::AddWare)
+ .def("AddObject", &ShopEvent::AddObject)
+ .def("SetPriceLevels", &ShopEvent::SetPriceLevels)
];
luabind::module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
@@ -778,6 +779,16 @@ void BindModeCode() {
luabind::class_<ShopMode, hoa_mode_manager::GameMode>("ShopMode")
.def(luabind::constructor<>())
.def("AddObject", &ShopMode::AddObject)
+ .def("SetPriceLevels", &ShopMode::SetPriceLevels)
+
+ .enum_("constants") [
+ // Price levels
+ luabind::value("SHOP_PRICE_VERY_GOOD", SHOP_PRICE_VERY_GOOD),
+ luabind::value("SHOP_PRICE_GOOD", SHOP_PRICE_GOOD),
+ luabind::value("SHOP_PRICE_STANDARD", SHOP_PRICE_STANDARD),
+ luabind::value("SHOP_PRICE_POOR", SHOP_PRICE_POOR),
+ luabind::value("SHOP_PRICE_VERY_POOR", SHOP_PRICE_VERY_POOR)
+ ]
];
} // End using shop mode namespaces
View
2  src/modes/shop/shop_utils.h
@@ -19,6 +19,8 @@
#ifndef __SHOP_UTILS_HEADER__
#define __SHOP_UTILS_HEADER__
+#include "common/global/global_utils.h"
+
#include "common/gui/textbox.h"
#include "common/gui/option.h"
Please sign in to comment.
Something went wrong with that request. Please try again.