343 lines
12 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: ./mine1.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
//${.::mine1.cpp} ............................................................
2012-08-14 18:00:48 -04:00
#include "qp_port.h"
#include "bsp.h"
#include "game.h"
Q_DEFINE_THIS_FILE
// encapsulated delcaration of the Mine1 HSM ---------------------------------
2013-12-30 17:41:15 -05:00
namespace GAME {
2014-04-13 21:35:34 -04:00
//${AOs::Mine1} ..............................................................
2013-12-30 17:41:15 -05:00
class Mine1 : public QP::QMsm {
2012-08-14 18:00:48 -04:00
private:
uint8_t m_x;
uint8_t m_y;
uint8_t m_exp_ctr;
public:
2013-12-30 17:41:15 -05:00
Mine1()
: QMsm(Q_STATE_CAST(&initial))
2013-12-30 17:41:15 -05:00
{}
2012-08-14 18:00:48 -04:00
protected:
static QP::QState initial(Mine1 * const me, QP::QEvt const * const e);
2013-12-30 17:41:15 -05:00
static QP::QState unused (Mine1 * const me, QP::QEvt const * const e);
static QP::QMState const unused_s;
static QP::QState used (Mine1 * const me, QP::QEvt const * const e);
static QP::QState used_x(Mine1 * const me);
static QP::QMState const used_s;
static QP::QState exploding (Mine1 * const me, QP::QEvt const * const e);
static QP::QState exploding_e(Mine1 * const me);
static QP::QMState const exploding_s;
static QP::QState planted (Mine1 * const me, QP::QEvt const * const e);
static QP::QMState const planted_s;
2012-08-14 18:00:48 -04:00
};
2013-12-30 17:41:15 -05:00
} // namespace GAME
namespace GAME {
2013-10-10 20:01:51 -04:00
2012-08-14 18:00:48 -04:00
// local objects -------------------------------------------------------------
static Mine1 l_mine1[GAME_MINES_MAX]; // a pool of type-1 mines
//............................................................................
2013-12-30 17:41:15 -05:00
QP::QMsm *Mine1_getInst(uint8_t id) {
2012-08-14 18:00:48 -04:00
Q_REQUIRE(id < GAME_MINES_MAX);
return &l_mine1[id];
}
// helper function to provide the ID of this mine ............................
static inline uint8_t MINE_ID(Mine1 const * const me) {
return static_cast<uint8_t>(me - l_mine1);
}
2013-12-30 17:41:15 -05:00
} // namespace GAME
2012-08-14 18:00:48 -04:00
// Mine1 class definition ----------------------------------------------------
2013-12-30 17:41:15 -05:00
namespace GAME {
2014-04-13 21:35:34 -04:00
//${AOs::Mine1} ..............................................................
2012-08-14 18:00:48 -04:00
2014-04-13 21:35:34 -04:00
//${AOs::Mine1::SM} ..........................................................
2012-08-14 18:00:48 -04:00
QP::QState Mine1::initial(Mine1 * const me, QP::QEvt const * const e) {
2014-04-13 21:35:34 -04:00
static QP::QMTranActTable const tatbl_ = { // transition-action table
&unused_s,
{
Q_ACTION_CAST(0) // zero terminator
}
};
// ${AOs::Mine1::SM::initial}
2012-08-14 18:00:48 -04:00
static bool dict_sent = false;
if (!dict_sent) {
dict_sent = true;
QS_OBJ_DICTIONARY(&l_mine1[0]); // obj. dictionaries for Mine1 pool
QS_OBJ_DICTIONARY(&l_mine1[1]);
QS_OBJ_DICTIONARY(&l_mine1[2]);
QS_OBJ_DICTIONARY(&l_mine1[3]);
QS_OBJ_DICTIONARY(&l_mine1[4]);
QS_FUN_DICTIONARY(&Mine1::initial);// fun. dictionaries for Mine1 HSM
QS_FUN_DICTIONARY(&Mine1::unused);
QS_FUN_DICTIONARY(&Mine1::used);
QS_FUN_DICTIONARY(&Mine1::planted);
QS_FUN_DICTIONARY(&Mine1::exploding);
}
// local signals
QS_SIG_DICTIONARY(MINE_PLANT_SIG, me);
QS_SIG_DICTIONARY(MINE_DISABLED_SIG, me);
QS_SIG_DICTIONARY(MINE_RECYCLE_SIG, me);
QS_SIG_DICTIONARY(SHIP_IMG_SIG, me);
QS_SIG_DICTIONARY(MISSILE_IMG_SIG, me);
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::Mine1::SM::unused} ..................................................
2013-12-30 17:41:15 -05:00
QP::QMState const Mine1::unused_s = {
2014-04-13 21:35:34 -04:00
static_cast<QP::QMState const *>(0), // superstate (top)
Q_STATE_CAST(&unused),
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::Mine1::SM::unused}
2012-08-14 18:00:48 -04:00
QP::QState Mine1::unused(Mine1 * 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::Mine1::SM::unused::MINE_PLANT}
2012-08-14 18:00:48 -04:00
case MINE_PLANT_SIG: {
2014-04-13 21:35:34 -04:00
static QP::QMTranActTable const tatbl_ = { // transition-action table
&planted_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::Mine1::SM::used} ....................................................
2013-12-30 17:41:15 -05:00
QP::QMState const Mine1::used_s = {
2014-04-13 21:35:34 -04:00
static_cast<QP::QMState const *>(0), // superstate (top)
Q_STATE_CAST(&used),
2014-04-13 21:35:34 -04:00
Q_ACTION_CAST(0), // no entry action
Q_ACTION_CAST(&used_x),
2014-04-13 21:35:34 -04:00
Q_ACTION_CAST(0) // no intitial tran.
2013-12-30 17:41:15 -05:00
};
2014-04-13 21:35:34 -04:00
// ${AOs::Mine1::SM::used}
2013-12-30 17:41:15 -05:00
QP::QState Mine1::used_x(Mine1 * const me) {
// tell the Tunnel that this mine is becoming disabled
MineEvt *mev = Q_NEW(MineEvt, MINE_DISABLED_SIG);
mev->id = MINE_ID(me);
AO_Tunnel->POST(mev, me);
return QM_EXIT(&used_s);
}
2014-04-13 21:35:34 -04:00
// ${AOs::Mine1::SM::used}
2012-08-14 18:00:48 -04:00
QP::QState Mine1::used(Mine1 * 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::Mine1::SM::used::MINE_RECYCLE}
2012-08-14 18:00:48 -04:00
case MINE_RECYCLE_SIG: {
2014-04-13 21:35:34 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[2];
} const tatbl_ = { // transition-action table
&unused_s,
{
Q_ACTION_CAST(&used_x), // exit
2014-04-13 21:35:34 -04:00
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;
}
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::Mine1::SM::used::exploding} .........................................
2013-12-30 17:41:15 -05:00
QP::QMState const Mine1::exploding_s = {
2014-04-13 21:35:34 -04:00
&Mine1::used_s, // superstate
Q_STATE_CAST(&exploding),
Q_ACTION_CAST(&exploding_e),
2014-04-13 21:35:34 -04:00
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::Mine1::SM::used::exploding}
2013-12-30 17:41:15 -05:00
QP::QState Mine1::exploding_e(Mine1 * const me) {
me->m_exp_ctr = 0U;
return QM_ENTRY(&exploding_s);
}
2014-04-13 21:35:34 -04:00
// ${AOs::Mine1::SM::used::exploding}
2012-08-14 18:00:48 -04:00
QP::QState Mine1::exploding(Mine1 * 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::Mine1::SM::used::exploding::TIME_TICK}
2012-08-14 18:00:48 -04:00
case TIME_TICK_SIG: {
2014-04-13 21:35:34 -04:00
// ${AOs::Mine1::SM::used::exploding::TIME_TICK::[stillonscreen?]}
2012-08-14 18:00:48 -04:00
if ((me->m_x >= GAME_SPEED_X) && (me->m_exp_ctr < 15)) {
++me->m_exp_ctr; // advance the explosion counter
me->m_x -= GAME_SPEED_X; // move explosion by 1 step
// tell the Game to render the current stage of Explosion
ObjectImageEvt *oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG);
oie->x = me->m_x + 1U; // x of explosion
oie->y = (int8_t)((int)me->m_y - 4 + 2); // y of explosion
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::Mine1::SM::used::exploding::TIME_TICK::[else]}
2012-08-14 18:00:48 -04:00
else {
2014-04-13 21:35:34 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[2];
} const tatbl_ = { // transition-action table
&unused_s,
{
Q_ACTION_CAST(&used_x), // exit
2014-04-13 21:35:34 -04:00
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;
}
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::Mine1::SM::used::planted} ...........................................
2013-12-30 17:41:15 -05:00
QP::QMState const Mine1::planted_s = {
2014-04-13 21:35:34 -04:00
&Mine1::used_s, // superstate
Q_STATE_CAST(&planted),
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::Mine1::SM::used::planted}
2012-08-14 18:00:48 -04:00
QP::QState Mine1::planted(Mine1 * 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::Mine1::SM::used::planted::TIME_TICK}
2012-08-14 18:00:48 -04:00
case TIME_TICK_SIG: {
2014-04-13 21:35:34 -04:00
// ${AOs::Mine1::SM::used::planted::TIME_TICK::[me->m_x>=GAME~]}
2012-08-14 18:00:48 -04:00
if (me->m_x >= GAME_SPEED_X) {
me->m_x -= GAME_SPEED_X; // move the mine 1 step
// tell the Tunnel to draw the Mine
ObjectImageEvt *oie = Q_NEW(ObjectImageEvt, MINE_IMG_SIG);
oie->x = me->m_x;
oie->y = me->m_y;
oie->bmp = MINE1_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::Mine1::SM::used::planted::TIME_TICK::[else]}
2012-08-14 18:00:48 -04:00
else {
2014-04-13 21:35:34 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[2];
} const tatbl_ = { // transition-action table
&unused_s,
{
Q_ACTION_CAST(&used_x), // exit
2014-04-13 21:35:34 -04:00
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::Mine1::SM::used::planted::SHIP_IMG}
2012-08-14 18:00:48 -04:00
case SHIP_IMG_SIG: {
uint8_t x = Q_EVT_CAST(ObjectImageEvt)->x;
uint8_t y = Q_EVT_CAST(ObjectImageEvt)->y;
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
2014-04-13 21:35:34 -04:00
// ${AOs::Mine1::SM::used::planted::SHIP_IMG::[collisionwith~]}
2012-08-14 18:00:48 -04:00
if (do_bitmaps_overlap(MINE1_BMP, me->m_x, me->m_y, bmp, x, y)) {
2014-04-13 21:35:34 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[2];
} const tatbl_ = { // transition-action table
&unused_s,
{
Q_ACTION_CAST(&used_x), // exit
2014-04-13 21:35:34 -04:00
Q_ACTION_CAST(0) // zero terminator
}
2013-12-30 17:41:15 -05:00
};
2012-08-14 18:00:48 -04:00
static MineEvt const mine1_hit(HIT_MINE_SIG, 1U);
AO_Ship->POST(&mine1_hit, me);
// go straight to 'disabled' and let the Ship do
// the exploding
2014-04-13 21:35:34 -04:00
status_ = QM_TRAN(&tatbl_);
2012-08-14 18:00:48 -04:00
}
else {
2013-12-30 17:41:15 -05:00
status_ = QM_UNHANDLED();
2012-08-14 18:00:48 -04:00
}
break;
}
2014-04-13 21:35:34 -04:00
// ${AOs::Mine1::SM::used::planted::MISSILE_IMG}
2012-08-14 18:00:48 -04:00
case MISSILE_IMG_SIG: {
uint8_t x = Q_EVT_CAST(ObjectImageEvt)->x;
uint8_t y = Q_EVT_CAST(ObjectImageEvt)->y;
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
2014-04-13 21:35:34 -04:00
// ${AOs::Mine1::SM::used::planted::MISSILE_IMG::[collisionwith~]}
2012-08-14 18:00:48 -04:00
if (do_bitmaps_overlap(MINE1_BMP, me->m_x, me->m_y, bmp, x, y)) {
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(&exploding_e), // entry
2014-04-13 21:35:34 -04:00
Q_ACTION_CAST(0) // zero terminator
}
2013-12-30 17:41:15 -05:00
};
2012-08-14 18:00:48 -04:00
static ScoreEvt const mine1_destroyed(DESTROYED_MINE_SIG, 25U);
AO_Missile->POST(&mine1_destroyed, me);
2014-04-13 21:35:34 -04:00
status_ = QM_TRAN(&tatbl_);
2012-08-14 18:00:48 -04:00
}
else {
2013-12-30 17:41:15 -05:00
status_ = QM_UNHANDLED();
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