247 lines
8.7 KiB
C++
Raw Normal View History

2013-12-30 17:41:15 -05:00
//****************************************************************************
2012-08-14 18:00:48 -04:00
// Model: game.qm
2013-10-10 20:01:51 -04:00
// File: ./missile.cpp
2012-08-14 18:00:48 -04:00
//
2013-10-10 20:01:51 -04:00
// This code has been generated by QM tool (see state-machine.com/qm).
// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
2012-08-14 18:00:48 -04:00
//
2013-10-10 20:01:51 -04:00
// This program is open source software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
2013-12-30 17:41:15 -05:00
//****************************************************************************
2014-04-13 21:35:34 -04:00
//${.::missile.cpp} ..........................................................
2012-08-14 18:00:48 -04:00
#include "qp_port.h"
#include "bsp.h"
#include "game.h"
//Q_DEFINE_THIS_FILE
2013-12-30 17:41:15 -05:00
namespace GAME {
2014-04-13 21:35:34 -04:00
//${AOs::Missile} ............................................................
2013-12-30 17:41:15 -05:00
class Missile : public QP::QMActive {
2012-08-14 18:00:48 -04:00
private:
uint8_t m_x;
uint8_t m_y;
uint8_t m_exp_ctr;
public:
Missile();
protected:
static QP::QState initial(Missile * const me, QP::QEvt const * const e);
2013-12-30 17:41:15 -05:00
static QP::QState armed (Missile * const me, QP::QEvt const * const e);
static QP::QMState const armed_s;
static QP::QState flying (Missile * const me, QP::QEvt const * const e);
static QP::QMState const flying_s;
static QP::QState exploding (Missile * const me, QP::QEvt const * const e);
static QP::QState exploding_e(Missile * const me);
static QP::QMState const exploding_s;
2012-08-14 18:00:48 -04:00
};
2013-10-10 20:01:51 -04:00
2013-12-30 17:41:15 -05:00
} // namespace GAME
namespace GAME {
// local objects -------------------------------------------------------------
2012-08-14 18:00:48 -04:00
static Missile l_missile; // the sole instance of the Missile active object
// Public-scope objects ------------------------------------------------------
QP::QActive * const AO_Missile = &l_missile; // opaque pointer
2013-12-30 17:41:15 -05:00
} // namespace GAME
2012-08-14 18:00:48 -04:00
// Active object definition --------------------------------------------------
2013-12-30 17:41:15 -05:00
namespace GAME {
2014-04-13 21:35:34 -04:00
//${AOs::Missile} ............................................................
//${AOs::Missile::Missile} ...................................................
2013-12-30 17:41:15 -05:00
Missile::Missile()
: QMActive(Q_STATE_CAST(&Missile::initial))
{}
2012-08-14 18:00:48 -04:00
2014-04-13 21:35:34 -04:00
//${AOs::Missile::SM} ........................................................
2012-08-14 18:00:48 -04:00
QP::QState Missile::initial(Missile * const me, QP::QEvt const * const e) {
2014-04-13 21:35:34 -04:00
static QP::QMTranActTable const tatbl_ = { // transition-action table
&armed_s,
{
Q_ACTION_CAST(0) // zero terminator
}
};
// ${AOs::Missile::SM::initial}
2012-08-14 18:00:48 -04:00
me->subscribe( TIME_TICK_SIG);
QS_OBJ_DICTIONARY(&l_missile); // object dictionary for Missile object
QS_FUN_DICTIONARY(&Missile::initial); // dictionaries for Missile HSM
QS_FUN_DICTIONARY(&Missile::armed);
QS_FUN_DICTIONARY(&Missile::flying);
QS_FUN_DICTIONARY(&Missile::exploding);
QS_SIG_DICTIONARY(MISSILE_FIRE_SIG, &l_missile); // local signals
QS_SIG_DICTIONARY(HIT_WALL_SIG, &l_missile);
QS_SIG_DICTIONARY(DESTROYED_MINE_SIG, &l_missile);
2014-04-13 21:35:34 -04:00
return QM_TRAN_INIT(&tatbl_);
2012-08-14 18:00:48 -04:00
}
2014-04-13 21:35:34 -04:00
//${AOs::Missile::SM::armed} .................................................
2013-12-30 17:41:15 -05:00
QP::QMState const Missile::armed_s = {
2014-04-13 21:35:34 -04:00
static_cast<QP::QMState const *>(0), // superstate (top)
2013-12-30 17:41:15 -05:00
Q_STATE_CAST(&Missile::armed),
2014-04-13 21:35:34 -04:00
Q_ACTION_CAST(0), // no entry action
Q_ACTION_CAST(0), // no exit action
Q_ACTION_CAST(0) // no intitial tran.
2013-12-30 17:41:15 -05:00
};
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::armed}
2012-08-14 18:00:48 -04:00
QP::QState Missile::armed(Missile * const me, QP::QEvt const * const e) {
2013-10-10 20:01:51 -04:00
QP::QState status_;
2012-08-14 18:00:48 -04:00
switch (e->sig) {
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::armed::MISSILE_FIRE}
2012-08-14 18:00:48 -04:00
case MISSILE_FIRE_SIG: {
2014-04-13 21:35:34 -04:00
static QP::QMTranActTable const tatbl_ = { // transition-action table
&flying_s,
{
Q_ACTION_CAST(0) // zero terminator
}
};
2012-08-14 18:00:48 -04:00
me->m_x = Q_EVT_CAST(ObjectPosEvt)->x;
me->m_y = Q_EVT_CAST(ObjectPosEvt)->y;
2014-04-13 21:35:34 -04:00
status_ = QM_TRAN(&tatbl_);
2012-08-14 18:00:48 -04:00
break;
}
default: {
2013-12-30 17:41:15 -05:00
status_ = QM_SUPER();
2012-08-14 18:00:48 -04:00
break;
}
}
2013-10-10 20:01:51 -04:00
return status_;
2012-08-14 18:00:48 -04:00
}
2014-04-13 21:35:34 -04:00
//${AOs::Missile::SM::flying} ................................................
2013-12-30 17:41:15 -05:00
QP::QMState const Missile::flying_s = {
2014-04-13 21:35:34 -04:00
static_cast<QP::QMState const *>(0), // superstate (top)
2013-12-30 17:41:15 -05:00
Q_STATE_CAST(&Missile::flying),
2014-04-13 21:35:34 -04:00
Q_ACTION_CAST(0), // no entry action
Q_ACTION_CAST(0), // no exit action
Q_ACTION_CAST(0) // no intitial tran.
2013-12-30 17:41:15 -05:00
};
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::flying}
2012-08-14 18:00:48 -04:00
QP::QState Missile::flying(Missile * const me, QP::QEvt const * const e) {
2013-10-10 20:01:51 -04:00
QP::QState status_;
2012-08-14 18:00:48 -04:00
switch (e->sig) {
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::flying::TIME_TICK}
2012-08-14 18:00:48 -04:00
case TIME_TICK_SIG: {
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::flying::TIME_TICK::[me->m_x+GAME_~]}
2012-08-14 18:00:48 -04:00
if (me->m_x + GAME_MISSILE_SPEED_X < GAME_SCREEN_WIDTH) {
me->m_x += GAME_MISSILE_SPEED_X;
// tell the Tunnel to draw the Missile and test for wall hits
ObjectImageEvt *oie = Q_NEW(ObjectImageEvt, MISSILE_IMG_SIG);
oie->x = me->m_x;
oie->y = me->m_y;
oie->bmp = MISSILE_BMP;
AO_Tunnel->POST(oie, me);
2013-12-30 17:41:15 -05:00
status_ = QM_HANDLED();
2012-08-14 18:00:48 -04:00
}
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::flying::TIME_TICK::[else]}
2012-08-14 18:00:48 -04:00
else {
2014-04-13 21:35:34 -04:00
static QP::QMTranActTable const tatbl_ = { // transition-action table
&armed_s,
{
Q_ACTION_CAST(0) // zero terminator
}
};
status_ = QM_TRAN(&tatbl_);
2012-08-14 18:00:48 -04:00
}
break;
}
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::flying::HIT_WALL}
2012-08-14 18:00:48 -04:00
case HIT_WALL_SIG: {
2014-04-13 21:35:34 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[2];
} const tatbl_ = { // transition-action table
&exploding_s,
{
Q_ACTION_CAST(&Missile::exploding_e), // entry
Q_ACTION_CAST(0) // zero terminator
}
2013-12-30 17:41:15 -05:00
};
2014-04-13 21:35:34 -04:00
status_ = QM_TRAN(&tatbl_);
2012-08-14 18:00:48 -04:00
break;
}
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::flying::DESTROYED_MINE}
2012-08-14 18:00:48 -04:00
case DESTROYED_MINE_SIG: {
2014-04-13 21:35:34 -04:00
static QP::QMTranActTable const tatbl_ = { // transition-action table
&armed_s,
{
Q_ACTION_CAST(0) // zero terminator
}
};
2012-08-14 18:00:48 -04:00
AO_Ship->POST(e, me);
2014-04-13 21:35:34 -04:00
status_ = QM_TRAN(&tatbl_);
2012-08-14 18:00:48 -04:00
break;
}
default: {
2013-12-30 17:41:15 -05:00
status_ = QM_SUPER();
2012-08-14 18:00:48 -04:00
break;
}
}
2013-10-10 20:01:51 -04:00
return status_;
2012-08-14 18:00:48 -04:00
}
2014-04-13 21:35:34 -04:00
//${AOs::Missile::SM::exploding} .............................................
2013-12-30 17:41:15 -05:00
QP::QMState const Missile::exploding_s = {
2014-04-13 21:35:34 -04:00
static_cast<QP::QMState const *>(0), // superstate (top)
2013-12-30 17:41:15 -05:00
Q_STATE_CAST(&Missile::exploding),
2014-04-13 21:35:34 -04:00
Q_ACTION_CAST(&Missile::exploding_e),
Q_ACTION_CAST(0), // no exit action
Q_ACTION_CAST(0) // no intitial tran.
2013-12-30 17:41:15 -05:00
};
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::exploding}
2013-12-30 17:41:15 -05:00
QP::QState Missile::exploding_e(Missile * const me) {
me->m_exp_ctr = 0U;
return QM_ENTRY(&exploding_s);
}
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::exploding}
2012-08-14 18:00:48 -04:00
QP::QState Missile::exploding(Missile * const me, QP::QEvt const * const e) {
2013-10-10 20:01:51 -04:00
QP::QState status_;
2012-08-14 18:00:48 -04:00
switch (e->sig) {
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::exploding::TIME_TICK}
2012-08-14 18:00:48 -04:00
case TIME_TICK_SIG: {
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::exploding::TIME_TICK::[(me->m_x>=GAM~]}
2012-08-14 18:00:48 -04:00
if ((me->m_x >= GAME_SPEED_X) && (me->m_exp_ctr < 15U)) {
++me->m_exp_ctr; // advance the explosion counter
me->m_x -= GAME_SPEED_X; // move the explosion by one step
// tell the Tunnel to render the current stage of Explosion
ObjectImageEvt *oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG);
oie->x = me->m_x + 3U; // x-pos of explosion
oie->y = (int8_t)((int)me->m_y - 4U); // y-pos
oie->bmp = EXPLOSION0_BMP + (me->m_exp_ctr >> 2);
AO_Tunnel->POST(oie, me);
2013-12-30 17:41:15 -05:00
status_ = QM_HANDLED();
2012-08-14 18:00:48 -04:00
}
2014-04-13 21:35:34 -04:00
// ${AOs::Missile::SM::exploding::TIME_TICK::[else]}
2012-08-14 18:00:48 -04:00
else {
2014-04-13 21:35:34 -04:00
static QP::QMTranActTable const tatbl_ = { // transition-action table
&armed_s,
{
Q_ACTION_CAST(0) // zero terminator
}
};
status_ = QM_TRAN(&tatbl_);
2012-08-14 18:00:48 -04:00
}
break;
}
default: {
2013-12-30 17:41:15 -05:00
status_ = QM_SUPER();
2012-08-14 18:00:48 -04:00
break;
}
}
2013-10-10 20:01:51 -04:00
return status_;
2012-08-14 18:00:48 -04:00
}
} // namespace GAME