1 //////////////////////////////////////////////////////////////////////////////// 2 // Copyright (C) 2004-2010 by The Allacrost Project 3 // All Rights Reserved 4 // 5 // This code is licensed under the GNU GPL version 2. It is free software 6 // and you may modify it and/or redistribute it under the terms of this license. 7 // See http://www.gnu.org/copyleft/gpl.html for details. 8 //////////////////////////////////////////////////////////////////////////////// 9 10 /** **************************************************************************** 11 *** \file battle_events.cpp 12 *** \author Jacob Rudolph, rujasu@allacrost.org 13 *** \brief Source file for battle events. 14 *** ***************************************************************************/ 15 16 #include "global.h" 17 #include "script.h" 18 #include "battle_events.h" 19 #include "battle_utils.h" 20 21 using namespace std; 22 using namespace hoa_utils; 23 using namespace hoa_global; 24 using namespace hoa_script; 25 26 namespace hoa_battle { 27 BattleEvent(uint32 id)28BattleEvent::BattleEvent(uint32 id) : _id(id), _name(NULL) { 29 if (_id == 0 || _id > 5) { 30 cerr << "BATTLE ERROR: BattleEvent constructor failed due to an invalid id assignment: " << _id << endl; 31 exit(1); 32 } 33 ReadScriptDescriptor& script_file = *(GlobalManager->GetBattleEventScript()); 34 35 if (script_file.DoesTableExist(_id) == false) { 36 cerr << "BATTLE ERROR: BattleEvent constructor failed because the table containing the " 37 << "event definition did not exist for event id: " << _id << endl; 38 exit(1); 39 } 40 41 // Load the item data from the script 42 script_file.OpenTable(_id); 43 _name = MakeUnicodeString(script_file.ReadString("name")); 44 45 if ( script_file.DoesFunctionExist("Before") 46 && script_file.DoesFunctionExist("During") 47 && script_file.DoesFunctionExist("After") ) 48 { 49 _before = new ScriptObject(); 50 *_before = script_file.ReadFunctionPointer("Before"); 51 _during = new ScriptObject(); 52 *_during = script_file.ReadFunctionPointer("During"); 53 _after = new ScriptObject(); 54 *_after = script_file.ReadFunctionPointer("After"); 55 } 56 else { 57 cerr << "BATTLE ERROR: BattleEvent constructor" << endl; 58 exit(1); 59 } 60 61 script_file.CloseTable(); 62 63 if (script_file.IsErrorDetected()) { 64 if (GLOBAL_DEBUG) { 65 cerr << "BATTLE WARNING: BattleEvent constructor incurred script reading errors. They are as follows: " << endl; 66 cerr << script_file.GetErrorMessages() << endl; 67 } 68 return; 69 } 70 } 71 ~BattleEvent()72BattleEvent::~BattleEvent() { 73 delete _before; 74 _before = NULL; 75 delete _during; 76 _during = NULL; 77 delete _after; 78 _after = NULL; 79 } 80 81 } // namespace hoa_battle 82