void LifeForm::fire()
{
    Basic::Number* hdgObj = new Basic::Number(getHeadingR());
    Basic::Number* pitchObj = new Basic::Number(lookAngle * Basic::Angle::D2RCC);
    StoresMgr* mgr = getStoresManagement();
    if (mgr != nullptr) {
        if (getSimulation() != nullptr) {
            if (weaponSel == LF_MISSILE) {
                mgr->setGunSelected(false);
                Missile* missile = mgr->getNextMissile();
                if (missile != nullptr) {
                    missile->setSlotInitPitch(pitchObj);
                    missile->setSlotInitHeading(hdgObj);
                    missile->reset();
                    Missile* msl = mgr->releaseOneMissile();
                    if (msl != nullptr) {
                        if (tgtAquired && tgtPlayer != nullptr) msl->setTargetPlayer(tgtPlayer, true);
                    }
                }
            }
            else if (weaponSel == LF_GUN) {
                mgr->setGunSelected(true);
                Gun* myGun = mgr->getGun();
                if (myGun != nullptr) {
                    myGun->setGunArmed(true);
                    Basic::Number* num = new Basic::Number(lookAngle * Basic::Angle::D2RCC);
                    myGun->setSlotPitch(num);
                    num->unref();
                    myGun->fireControl(true);
                }
           }
        }
    }
    hdgObj->unref();
    pitchObj->unref();
}
void TestStateMachine02::stateFunc13(const LCreal)
{
   if (getMode() != RTN_STATE) {
      std::cout << "call(CALL_02,arg=13)";
      Basic::Number* arg = new Basic::Integer(13);
      call(CALL_02, arg);
      arg->unref();
   }
   else {
      std::cout << "Returned from call; ";
      const Basic::Boolean* arg = dynamic_cast<const Basic::Boolean*>( getArgument() );
      if (arg != 0) {
         std::cout << "arg(" << arg->getBoolean() << "); ";
      }
      std::cout << "next()";
      next();
   }
}
void TestStateMachine03::stateFunc13(const LCreal)
{
   switch (getSubstate()) {

      case INIT_STATE : {
         std::cout << "nextSubstate()";
         nextSubstate();
         break;
      }

      case 1 : {
         if (getMode() != RTN_STATE) {
            std::cout << "call(CALL_02,arg=13)";
            Basic::Number* arg = new Basic::Integer(13);
            call(CALL_02, arg);
            arg->unref();
         }
         else {
            std::cout << "Returned from call; ";
            const Basic::Boolean* arg = dynamic_cast<const Basic::Boolean*>( getArgument() );
            if (arg != nullptr) {
               std::cout << "arg(" << arg->getBoolean() << "); ";
            }
            std::cout << "nextSubstate()";
            nextSubstate();
         }
         break;
      }

      case 2 : {
         std::cout << "next()";
         next();
         break;
      }

   }
}
void TestStateMachine01::anyStateFunc(const LCreal)
{
   switch (getState()) {

      case INIT_STATE : {
         std::cout << "next()";
         next();
         break;
      }

      case 1 : {
         std::cout << "next()";
         next();
         break;
      }

      case 2 : {
         std::cout << "goTo(4)";
         goTo(4);
         break;
      }

      case 3 : {
         std::cout << "Should NOT be here!";
         break;
      }

      case 4 : {
         if (getMode() != RTN_STATE) {
            std::cout << "call(CALL_01)";
            call(CALL_01);
         }
         else {
            std::cout << "Returned from call(); next()";
            next();
         }
         break;
      }

      case 5 : {
         std::cout << "goTo(99)";
         goTo(99);
         break;
      }

      case 11 : {
         std::cout << "next()";
         next();
         break;
      }

      case 12 : {
         std::cout << "next()";
         next();
         break;
      }

      case 13 : {
         if (getMode() != RTN_STATE) {
            std::cout << "call(CALL_02,arg=13)";
            Basic::Number* arg = new Basic::Integer(13);
            call(CALL_02, arg);
            arg->unref();
         }
         else {
            std::cout << "Returned from call; ";
            const Basic::Boolean* arg = dynamic_cast<const Basic::Boolean*>( getArgument() );
            if (arg != nullptr) {
               std::cout << "arg(" << arg->getBoolean() << "); ";
            }
            std::cout << "next()";
            next();
         }
         break;
      }

      case 14 : {
         std::cout << "next()";
         next();
         break;
      }

      case 15 : {
         std::cout << "rtn()";
         rtn();
         break;
      }

      case 21 : {
         const Basic::Number* arg = dynamic_cast<const Basic::Number*>( getArgument() );
         if (arg != nullptr) {
            std::cout << "arg(" << arg->getReal() << "); ";
         }

         std::cout << "next()";
         next();
         break;
      }

      case 22 : {
         std::cout << "next()";
         next();
         break;
      }

      case 23 : {
         std::cout << "rtn(arg=true)";
         Basic::Boolean* arg = new Basic::Boolean(true);
         rtn(arg);
         arg->unref();
         break;
      }

      case 99 : {
         if (getMode() == NEW_STATE) {
            std::cout << "Finished;";
         }
         break;
      }

   };
}