//------------------------------------------------------------------------------
// setSlotEventMap() - this sets the list of the eventId's we want generated
// when a button is activated.  For example, if you hold the top button until
// the timer alarms out, instead of sending an event of 2 (top button id), it
// will map that event to this one and will send that to the display to be
// processed.
//------------------------------------------------------------------------------
bool SolenoidSwitch::setSlotEventMap(const Basic::PairStream* const x)
{
    if (x != nullptr) {
        if (x->entries() != 3) std::cout << "SolenoidSwitch::setSlotEventMap() - Need 3 eventIds for the button, will not send eventIds for the ones without it" << std::endl;
        int count = 0;
        const Basic::List::Item* item = x->getFirstItem();
        while (item != nullptr && count < 3) {
            Basic::Pair* pair = (Basic::Pair*)item->getValue();
            Basic::Number* num = dynamic_cast<Basic::Number*>(pair->object());
            if (num != nullptr) eventMap[count] = num->getInt();
            count++;
            item = item->getNext();
        }
        //for (int i = 0; i < NUM_BUTTONS; i++) std::cout << "EVENT ID #" << i << " = " << eventMap[i] << std::endl;
    }
    return true;
}
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();
   }
}
Esempio n. 3
0
// set our slot values via a pairstream
bool ColorRotary::setSlotValues(const Basic::PairStream* const newStream)
{
    bool ok = false;
    numVals = 0;
    if (newStream != nullptr) {
        Basic::PairStream* a = newStream->clone();
        Basic::List::Item* item = a->getFirstItem();
        while (item != nullptr) {
            Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
            if (pair != nullptr) {
                Basic::Number* n = dynamic_cast<Basic::Number*>(pair->object());
                if (n != nullptr) {
                    myValues[numVals] = n->getReal();
                    numVals++;
                }
            }
            item = item->getNext();
        }
        ok = true;
        a->unref();
    }
    return ok;
}
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 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 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;
      }

   };
}