/*.$file${.::mine2.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ /* * Model: game.qm * File: ${.::mine2.c} * * This code has been generated by QM 4.6.0 . * DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. * * 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. */ /*.$endhead${.::mine2.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ #include "qpn.h" #include "game.h" #include "bsp.h" Q_DEFINE_THIS_MODULE("mine2") /* encapsulated delcaration of the Mine2 HSM -------------------------------*/ /*.$declare${AOs::Mine2} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ /*.${AOs::Mine2} ...........................................................*/ typedef struct Mine2 { /* protected: */ QHsm super; /* private: */ uint8_t x; uint8_t y; uint8_t exp_ctr; } Mine2; /* protected: */ static QState Mine2_initial(Mine2 * const me); static QState Mine2_unused(Mine2 * const me); static QState Mine2_used(Mine2 * const me); static QState Mine2_planted(Mine2 * const me); static QState Mine2_exploding(Mine2 * const me); /*.$enddecl${AOs::Mine2} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ /* local objects -----------------------------------------------------------*/ static Mine2 l_mine2[GAME_MINES_MAX]; /* a pool of type-2 mines */ /* helper macro to provide the ID of this mine */ #define MINE_ID(me_) ((me_) - l_mine2) /* Mine2 class definition --------------------------------------------------*/ /*.$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ /*. Check for the minimum required QP version */ #if (QP_VERSION < 650U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U)) #error qpn version 6.5.0 or higher required #endif /*.$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ /*.$define${AOs::Mine2_ctor} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ /*.${AOs::Mine2_ctor} ......................................................*/ QHsm * Mine2_ctor(uint8_t id) { Mine2 *me; Q_REQUIRE(id < GAME_MINES_MAX); me = &l_mine2[id]; QHsm_ctor(&me->super, Q_STATE_CAST(&Mine2_initial)); return &me->super; } /*.$enddef${AOs::Mine2_ctor} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ /*.$define${AOs::Mine2} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ /*.${AOs::Mine2} ...........................................................*/ /*.${AOs::Mine2::SM} .......................................................*/ static QState Mine2_initial(Mine2 * const me) { /*.${AOs::Mine2::SM::initial} */ return Q_TRAN(&Mine2_unused); } /*.${AOs::Mine2::SM::unused} ...............................................*/ static QState Mine2_unused(Mine2 * const me) { QState status_; switch (Q_SIG(me)) { /*.${AOs::Mine2::SM::unused::MINE_PLANT} */ case MINE_PLANT_SIG: { me->x = (uint8_t)Q_PAR(me); me->y = (uint8_t)(Q_PAR(me) >> 8); status_ = Q_TRAN(&Mine2_planted); break; } default: { status_ = Q_SUPER(&QHsm_top); break; } } return status_; } /*.${AOs::Mine2::SM::used} .................................................*/ static QState Mine2_used(Mine2 * const me) { QState status_; switch (Q_SIG(me)) { /*.${AOs::Mine2::SM::used} */ case Q_EXIT_SIG: { /* tell the Tunnel that this mine is becoming disabled */ QACTIVE_POST(&AO_Tunnel, MINE_DISABLED_SIG, MINE_ID(me)); status_ = Q_HANDLED(); break; } /*.${AOs::Mine2::SM::used::MINE_RECYCLE} */ case MINE_RECYCLE_SIG: { status_ = Q_TRAN(&Mine2_unused); break; } default: { status_ = Q_SUPER(&QHsm_top); break; } } return status_; } /*.${AOs::Mine2::SM::used::planted} ........................................*/ static QState Mine2_planted(Mine2 * const me) { QState status_; switch (Q_SIG(me)) { /*.${AOs::Mine2::SM::used::planted::TIME_TICK} */ case TIME_TICK_SIG: { /*.${AOs::Mine2::SM::used::planted::TIME_TICK::[me->x>=GAME_SPEED_X]} */ if (me->x >= GAME_SPEED_X) { me->x -= GAME_SPEED_X; /* move the mine 1 step */ /* tell the Tunnel to draw the Mine */ QACTIVE_POST(&AO_Tunnel, MINE_IMG_SIG, (MINE2_BMP << 16) | me->x | (me->y << 8)); status_ = Q_HANDLED(); } /*.${AOs::Mine2::SM::used::planted::TIME_TICK::[else]} */ else { status_ = Q_TRAN(&Mine2_unused); } break; } /*.${AOs::Mine2::SM::used::planted::SHIP_IMG} */ case SHIP_IMG_SIG: { uint8_t x = (uint8_t)Q_PAR(me); uint8_t y = (uint8_t)(Q_PAR(me) >> 8); uint8_t bmp = (uint8_t)(Q_PAR(me) >> 16); /*.${AOs::Mine2::SM::used::planted::SHIP_IMG::[BSP_doBitmapsOverlap(MINE2_BMP,~} */ if (BSP_doBitmapsOverlap(MINE2_BMP, me->x, me->y, bmp, x, y)) { QACTIVE_POST(&AO_Ship, HIT_MINE_SIG, 2); /* go straight to 'disabled' and let the Ship do the exploding */ status_ = Q_TRAN(&Mine2_unused); } else { status_ = Q_UNHANDLED(); } break; } /*.${AOs::Mine2::SM::used::planted::MISSILE_IMG} */ case MISSILE_IMG_SIG: { uint8_t x = (uint8_t)Q_PAR(me); uint8_t y = (uint8_t)(Q_PAR(me) >> 8); uint8_t bmp = (uint8_t)(Q_PAR(me) >> 16); /*.${AOs::Mine2::SM::used::planted::MISSILE_IMG::[BSP_doBitmapsOverlap(MINE2_MISS~} */ if (BSP_doBitmapsOverlap(MINE2_MISSILE_BMP, me->x, me->y, bmp, x, y)) { /* NOTE: Mine type-2 is nastier than Mine type-1. * The type-2 mine can hit the Ship with any of its * "tentacles". However, it can be destroyed by the * Missile only by hitting its center, defined as * a smaller bitmap MINE2_MISSILE_BMP. */ /* post the score for destroying Mine type-2 */ QACTIVE_POST(&AO_Missile, DESTROYED_MINE_SIG, 45); status_ = Q_TRAN(&Mine2_exploding); } else { status_ = Q_UNHANDLED(); } break; } default: { status_ = Q_SUPER(&Mine2_used); break; } } return status_; } /*.${AOs::Mine2::SM::used::exploding} ......................................*/ static QState Mine2_exploding(Mine2 * const me) { QState status_; switch (Q_SIG(me)) { /*.${AOs::Mine2::SM::used::exploding} */ case Q_ENTRY_SIG: { me->exp_ctr = 0; status_ = Q_HANDLED(); break; } /*.${AOs::Mine2::SM::used::exploding::TIME_TICK} */ case TIME_TICK_SIG: { /*.${AOs::Mine2::SM::used::exploding::TIME_TICK::[(me->x>=GAME_SPEED_X)&&(me->exp~} */ if ((me->x >= GAME_SPEED_X) && (me->exp_ctr < 15)) { ++me->exp_ctr; /* advance the explosion counter */ me->x -= GAME_SPEED_X; /* move explosion by 1 step */ /* tell the Game to render the current stage of Explosion */ QACTIVE_POST(&AO_Tunnel, EXPLOSION_SIG, ((EXPLOSION0_BMP + (me->exp_ctr >> 2)) << 16) | (me->x + 1) | (((int)me->y - 4 + 2)) << 8); status_ = Q_HANDLED(); } /*.${AOs::Mine2::SM::used::exploding::TIME_TICK::[else]} */ else { status_ = Q_TRAN(&Mine2_unused); } break; } default: { status_ = Q_SUPER(&Mine2_used); break; } } return status_; } /*.$enddef${AOs::Mine2} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/