Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9869 in orxonox.OLD for trunk/src/world_entities/weapons/weapon.cc


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/weapons/weapon.cc

    r9406 r9869  
    2121#include "weapon.h"
    2222
    23 #include "fast_factory.h"
     23#include "loading/fast_factory.h"
    2424#include "world_entities/projectiles/projectile.h"
    2525
    26 #include "util/loading/resource_manager.h"
    27 #include "class_list.h"
    2826#include "util/loading/factory.h"
    2927#include "util/loading/load_param.h"
     
    3331#include "sound_source.h"
    3432#include "sound_buffer.h"
     33#include "resource_sound_buffer.h"
    3534
    3635#include "elements/glgui_energywidget.h"
    3736
    38 
     37ObjectListDefinition(Weapon);
    3938
    4039////////////////////
     
    5857{
    5958  for (int i = 0; i < WS_STATE_COUNT; i++)
    60     if (this->animation[i] && ClassList::exists(animation[i], CL_ANIMATION))  //!< @todo this should check animation3D
     59    if (this->animation[i] && Animation::objectList().exists(animation[i]))  //!< @todo this should check animation3D
    6160      delete this->animation[i];
    62   for (int i = 0; i < WA_ACTION_COUNT; i++)
    63     if (this->soundBuffers[i] != NULL && ClassList::exists(this->soundBuffers[i], CL_SOUND_BUFFER))
    64       ResourceManager::getInstance()->unload(this->soundBuffers[i]);
    65 
    66   if (ClassList::exists(this->soundSource, CL_SOUND_SOURCE))
     61
     62  if (OrxSound::SoundSource::objectList().exists(this->soundSource))
    6763    delete this->soundSource;
    6864}
     
    7369 * @returns the newly created Weapon.
    7470 */
    75 Weapon* Weapon::createWeapon(ClassID weaponID)
     71Weapon* Weapon::createWeapon(const ClassID& weaponID)
    7672{
    7773  BaseObject* createdObject = Factory::fabricate(weaponID);
    7874  if (createdObject != NULL)
    7975  {
    80     if (createdObject->isA(CL_WEAPON))
     76    if (createdObject->isA(Weapon::staticClassID()))
    8177      return dynamic_cast<Weapon*>(createdObject);
    8278    else
     
    8985}
    9086
     87Weapon* Weapon::createWeapon(const std::string& weaponName)
     88{
     89  BaseObject* createdObject = Factory::fabricate(weaponName);
     90  if (createdObject != NULL)
     91  {
     92    if (createdObject->isA(Weapon::staticClassID()))
     93      return dynamic_cast<Weapon*>(createdObject);
     94    else
     95    {
     96      delete createdObject;
     97      return NULL;
     98    }
     99  }
     100  return NULL;
     101}
     102
     103
    91104/**
    92105 * initializes the Weapon with ALL default values
     
    96109void Weapon::init()
    97110{
    98   this->setClassID(CL_WEAPON, "Weapon");
     111  this->registerObject(this, Weapon::_objectList);
    99112  this->currentState     = WS_INACTIVE;            //< Normaly the Weapon is Inactive
    100113  this->requestedAction  = WA_NONE;                //< No action is requested by default
     
    105118    this->animation[i] = NULL;                   //< No animation
    106119  }
    107   for (int i = 0; i < WA_ACTION_COUNT; i++)
    108     this->soundBuffers[i] = NULL;                  //< No Sounds
    109120
    110121  this->soundSource = new OrxSound::SoundSource(this);       //< Every Weapon has exacty one SoundSource.
     
    115126  this->defaultTarget = NULL;                      //< Nothing is Targeted by default.
    116127
    117   this->projectile = CL_NULL;                      //< No Projectile Class is Connected to this weapon
     128  this->projectile = NullClass::staticClassID();         //< No Projectile Class is Connected to this weapon
    118129  this->projectileFactory = NULL;                  //< No Factory generating Projectiles is selected.
    119130
     
    163174 * What it does, is telling the Weapon what Projectiles it can Emit.
    164175 */
    165 void Weapon::setProjectileType(ClassID projectile)
    166 {
    167   if (projectile == CL_NULL)
    168     return;
     176void Weapon::setProjectileType(const ClassID& projectile)
     177{
    169178  this->projectile = projectile;
    170179  this->projectileFactory = FastFactory::searchFastFactory(projectile);
     
    259268  if (action >= WA_ACTION_COUNT)
    260269    return;
    261   if (this->soundBuffers[action] != NULL)
    262     ResourceManager::getInstance()->unload(this->soundBuffers[action]);
    263270
    264271  else if (!soundFile.empty())
    265272  {
    266     this->soundBuffers[action] = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load(soundFile, WAV);
    267     if (this->soundBuffers[action] != NULL)
     273    this->soundBuffers[action] = OrxSound::ResourceSoundBuffer(soundFile);
     274    if (this->soundBuffers[action].loaded())
    268275    {
    269276      PRINTF(4)("Loaded sound %s to action %s.\n", soundFile.c_str(), actionToChar(action));
     
    275282  }
    276283  else
    277     this->soundBuffers[action] = NULL;
     284    this->soundBuffers[action] = OrxSound::SoundBuffer();
    278285}
    279286
     
    409416  {
    410417    case WA_SHOOT:
    411       return this->fireW();
    412       break;
     418    return this->fireW();
     419    break;
    413420    case WA_CHARGE:
    414       return this->chargeW();
    415       break;
     421    return this->chargeW();
     422    break;
    416423    case WA_RELOAD:
    417       return this->reloadW();
    418       break;
     424    return this->reloadW();
     425    break;
    419426    case WA_DEACTIVATE:
    420       return this->deactivateW();
    421       break;
     427    return this->deactivateW();
     428    break;
    422429    case WA_ACTIVATE:
    423       return this->activateW();
    424       break;
     430    return this->activateW();
     431    break;
    425432    default:
    426       PRINTF(2)("Action %s Not Implemented yet \n", Weapon::actionToChar(action));
    427       return false;
     433    PRINTF(2)("Action %s Not Implemented yet \n", Weapon::actionToChar(action));
     434    return false;
    428435  }
    429436}
     
    438445  {
    439446    // play Sound
    440     if (likely(this->soundBuffers[WA_ACTIVATE] != NULL))
     447    if (likely(this->soundBuffers[WA_ACTIVATE].loaded()))
    441448      this->soundSource->play(this->soundBuffers[WA_ACTIVATE]);
    442449    this->updateWidgets();
     
    460467    PRINTF(4)("Deactivating the Weapon %s\n", this->getCName());
    461468    // play Sound
    462     if (this->soundBuffers[WA_DEACTIVATE] != NULL)
     469    if (this->soundBuffers[WA_DEACTIVATE].loaded())
    463470      this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]);
    464471    // deactivate
     
    479486  {
    480487    // playing Sound
    481     if (this->soundBuffers[WA_CHARGE] != NULL)
     488    if (this->soundBuffers[WA_CHARGE].loaded())
    482489      this->soundSource->play(this->soundBuffers[WA_CHARGE]);
    483490
     
    504511  {
    505512    // playing Sound
    506     if (this->soundBuffers[WA_SHOOT] != NULL)
     513    if (this->soundBuffers[WA_SHOOT].loaded())
    507514      this->soundSource->play(this->soundBuffers[WA_SHOOT]);
    508515    this->updateWidgets();
     
    528535{
    529536  PRINTF(4)("Reloading Weapon %s\n", this->getCName());
    530   if (this->ammoContainer.get() != NULL &&
     537  if (!this->ammoContainer.isNull() &&
    531538      unlikely(this->energy + this->ammoContainer->getStoredEnergy() < this->minCharge))
    532539  {
     
    537544
    538545
    539   if (this->soundBuffers[WA_RELOAD] != NULL)
     546  if (this->soundBuffers[WA_RELOAD].loaded())
    540547    this->soundSource->play(this->soundBuffers[WA_RELOAD]);
    541548
    542   if (this->ammoContainer.get() != NULL)
     549  if (!this->ammoContainer.isNull())
    543550    this->ammoContainer->fillWeapon(this);
    544551  else
     
    680687  {
    681688    case WA_SHOOT:
    682       return "shoot";
    683       break;
     689    return "shoot";
     690    break;
    684691    case WA_CHARGE:
    685       return "charge";
    686       break;
     692    return "charge";
     693    break;
    687694    case WA_RELOAD:
    688       return "reload";
    689       break;
     695    return "reload";
     696    break;
    690697    case WA_ACTIVATE:
    691       return "activate";
    692       break;
     698    return "activate";
     699    break;
    693700    case WA_DEACTIVATE:
    694       return "deactivate";
    695       break;
     701    return "deactivate";
     702    break;
    696703    case WA_SPECIAL1:
    697       return "special1";
    698       break;
     704    return "special1";
     705    break;
    699706    default:
    700       return "none";
    701       break;
     707    return "none";
     708    break;
    702709  }
    703710}
     
    743750  {
    744751    case WS_SHOOTING:
    745       return "shooting";
    746       break;
     752    return "shooting";
     753    break;
    747754    case WS_CHARGING:
    748       return "charging";
    749       break;
     755    return "charging";
     756    break;
    750757    case WS_RELOADING:
    751       return "reloading";
    752       break;
     758    return "reloading";
     759    break;
    753760    case WS_ACTIVATING:
    754       return "activating";
    755       break;
     761    return "activating";
     762    break;
    756763    case WS_DEACTIVATING:
    757       return "deactivating";
    758       break;
     764    return "deactivating";
     765    break;
    759766    case WS_IDLE:
    760       return "idle";
    761       break;
     767    return "idle";
     768    break;
    762769    case WS_INACTIVE:
    763       return "inactive";
    764       break;
     770    return "inactive";
     771    break;
    765772    default:
    766       return "none";
    767       break;
    768   }
    769 }
     773    return "none";
     774    break;
     775  }
     776}
Note: See TracChangeset for help on using the changeset viewer.