00001
00002
00003
00004
00005
00006
00007
00009
00020 #include <iostream>
00021
00022 #include "defs.h"
00023 #include "utils.h"
00024 #include "shop.h"
00025
00026 #include "audio.h"
00027 #include "video.h"
00028 #include "input.h"
00029 #include "system.h"
00030 #include "global.h"
00031 #include "mode_manager.h"
00032
00033 using namespace std;
00034 using namespace hoa_audio;
00035 using namespace hoa_video;
00036 using namespace hoa_input;
00037 using namespace hoa_system;
00038 using namespace hoa_global;
00039 using namespace hoa_mode_manager;
00040 using namespace hoa_shop::private_shop;
00041
00042 namespace hoa_shop {
00043
00044 bool SHOP_DEBUG = false;
00045
00046 namespace private_shop {
00047
00048 ShopMode* current_shop = NULL;
00049
00050 }
00051
00052 ShopMode::ShopMode() {
00053 if (SHOP_DEBUG)
00054 cout << "SHOP: ShopMode constructor invoked" << endl;
00055
00056 _purchases_cost = 0;
00057 _sales_revenue = 0;
00058
00059 mode_type = MODE_MANAGER_SHOP_MODE;
00060 private_shop::current_shop = this;
00061 _state = SHOP_STATE_ACTION;
00062
00063 if (VideoManager->CaptureScreen(_saved_screen) == false) {
00064 if (SHOP_DEBUG)
00065 cerr << "SHOP ERROR: Failed to capture saved screen" << endl;
00066 }
00067 }
00068
00069
00070
00071 ShopMode::~ShopMode() {
00072 if (SHOP_DEBUG)
00073 cout << "SHOP: ShopMode destructor invoked" << endl;
00074
00075 VideoManager->DeleteImage(_saved_screen);
00076
00077 for (uint32 i = 0; i < _all_objects.size(); i++) {
00078 delete(_all_objects[i]);
00079 }
00080 _all_objects.clear();
00081
00082 private_shop::current_shop = NULL;
00083 }
00084
00085
00086
00087 void ShopMode::Reset() {
00088
00089 VideoManager->SetCoordSys(0, 1024, 0, 768);
00090 if (VideoManager->SetFont("default") == false)
00091 cerr << "SHOP ERROR: failed to set font" << endl;
00092 VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, 0);
00093 VideoManager->SetTextColor(Color::white);
00094
00095
00096 _all_objects.clear();
00097 _all_objects.push_back(new GlobalItem(1));
00098 _all_objects.push_back(new GlobalWeapon(10001));
00099 _all_objects.push_back(new GlobalWeapon(10002));
00100 _all_objects.push_back(new GlobalArmor(20002));
00101 _all_objects.push_back(new GlobalArmor(30002));
00102 _all_objects.push_back(new GlobalArmor(40002));
00103 _all_objects.push_back(new GlobalArmor(50001));
00104
00105
00106 _all_objects_quantities.clear();
00107 for (uint32 ctr = 0; ctr < _all_objects.size(); ctr++) {
00108 _all_objects_quantities.push_back(0);
00109 }
00110
00111 std::map<uint32, GlobalObject*>* inv = GlobalManager->GetInventory();
00112 std::map<uint32, GlobalObject*>::iterator iter;
00113
00114 _sell_objects_quantities.clear();
00115 for (iter = inv->begin(); iter != inv->end(); iter++) {
00116 _sell_objects_quantities.push_back(0);
00117 }
00118
00119 _action_window.UpdateFinanceText();
00120
00121 _list_window.RefreshList();
00122
00123 _sell_window.UpdateSellList();
00124 _sell_window.object_list.SetSelection(0);
00125
00126 SoundDescriptor snd;
00127 _shop_sounds["confirm"] = SoundDescriptor();
00128 _shop_sounds["cancel"] = SoundDescriptor();
00129 _shop_sounds["coins"] = SoundDescriptor();
00130 _shop_sounds["bump"] = SoundDescriptor();
00131
00132 _shop_sounds["confirm"].LoadSound("snd/confirm.wav");
00133 _shop_sounds["cancel"].LoadSound("snd/cancel.wav");
00134 _shop_sounds["coins"].LoadSound("snd/coins.wav");
00135 _shop_sounds["bump"].LoadSound("snd/bump.wav");
00136 }
00137
00138
00139
00140 void ShopMode::Update() {
00141 switch (_state) {
00142 case SHOP_STATE_ACTION:
00143 _action_window.Update();
00144 break;
00145 case SHOP_STATE_LIST:
00146 _list_window.Update();
00147 break;
00148 case SHOP_STATE_SELL:
00149 _sell_window.Update();
00150 break;
00151 case SHOP_STATE_CONFIRM:
00152 _confirm_window.Update();
00153 break;
00154 default:
00155 if (SHOP_DEBUG)
00156 cerr << "SHOP WARNING: invalid shop state: " << _state << ", reseting to initial state" << endl;
00157 _state = SHOP_STATE_ACTION;
00158 return;
00159 }
00160 }
00161
00162
00163
00164 void ShopMode::Draw() {
00165
00166
00167 int32 width = VideoManager->GetWidth();
00168 int32 height = VideoManager->GetHeight();
00169 VideoManager->SetCoordSys (0.0f, static_cast<float>(width), 0.0f, static_cast<float>(height));
00170
00171 VideoManager->Move(0,0);
00172 VideoManager->DrawImage(_saved_screen);
00173
00174
00175 VideoManager->SetCoordSys (0.0f, 1024.0f, 0.0f, 768.0f);
00176
00177 _action_window.Draw();
00178 _info_window.Draw();
00179 _sell_window.Draw();
00180 _list_window.Draw();
00181 _confirm_window.Draw();
00182 }
00183
00184
00185
00186 void ShopMode::AddObject(uint32 object_id) {
00187 if (object_id == 0 || object_id > 60000) {
00188 if (SHOP_DEBUG)
00189 cerr << "SHOP WARNING: attempted to add object with invalid id: " << object_id << endl;
00190 return;
00191 }
00192
00193 if (_object_map.find(object_id) != _object_map.end()) {
00194 if (SHOP_DEBUG)
00195 cerr << "SHOP WARNING: attempted to add object that was already in the object list: " << object_id << endl;
00196 return;
00197 }
00198
00199 _object_map.insert(make_pair(object_id, 0));
00200 }
00201
00202 uint32 ShopMode::GetTotalRemaining() {
00203 return GlobalManager->GetDrunes() - _purchases_cost + _sales_revenue;
00204 }
00205
00206 }