//--------------------------- Render ------------------------------------- // //------------------------------------------------------------------------ void Raven_Bot::Render() { //when a bot is hit by a projectile this value is set to a constant user //defined value which dictates how long the bot should have a thick red //circle drawn around it (to indicate it's been hit) The circle is drawn //as long as this value is positive. (see Render) m_iNumUpdatesHitPersistant--; if (isDead() || isSpawning()) return; gdi->BluePen(); m_vecBotVBTrans = WorldTransform(m_vecBotVB, Pos(), Facing(), Facing().Perp(), Scale()); gdi->ClosedShape(m_vecBotVBTrans); //draw the head (gdi->*(m_pTeam->GetPen()))(); gdi->Circle(Pos(), 6.0 * Scale().x); //render the bot's weapon m_pWeaponSys->RenderCurrentWeapon(); //render a thick red circle if the bot gets hit by a weapon if (m_bHit) { gdi->ThickRedPen(); gdi->HollowBrush(); gdi->Circle(m_vPosition, BRadius()+1); if (m_iNumUpdatesHitPersistant <= 0) { m_bHit = false; } } gdi->TransparentText(); gdi->TextColor(0,255,0); if (UserOptions->m_bShowBotIDs) { gdi->TextAtPos(Pos().x -10, Pos().y-20, ttos(ID())); } if (UserOptions->m_bShowBotHealth) { gdi->TextAtPos(Pos().x-40, Pos().y-5, "H:"+ ttos(Health())); } if (UserOptions->m_bShowScore) { gdi->TextAtPos(Pos().x-40, Pos().y+10, "Scr:"+ ttos(Score())); } }
//--------------------------- Possess ----------------------------------------- // // this is called to allow a human player to control the bot //----------------------------------------------------------------------------- void Raven_Bot::TakePossession() { if ( !(isSpawning() || isDead())) { m_bPossessed = true; debug_con << "Player Possesses bot " << this->ID() << ""; } }
//--------------------------- HandleMessage ----------------------------------- //----------------------------------------------------------------------------- bool Raven_Bot::HandleMessage(const Telegram& msg) { //first see if the current goal accepts the message if (GetBrain()->HandleMessage(msg)) return true; //handle any messages not handles by the goals switch(msg.Msg) { case Msg_TakeThatMF: //just return if already dead or spawning if (isDead() || isSpawning()) return true; //the extra info field of the telegram carries the amount of damage ReduceHealth(DereferenceToType<int>(msg.ExtraInfo)); //if this bot is now dead let the shooter know if (isDead()) { Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY, ID(), msg.Sender, Msg_YouGotMeYouSOB, NO_ADDITIONAL_INFO); } return true; case Msg_YouGotMeYouSOB: IncrementScore(); //the bot this bot has just killed should be removed as the target m_pTargSys->ClearTarget(); return true; case Msg_GunshotSound: //add the source of this sound to the bot's percepts GetSensoryMem()->UpdateWithSoundSource((Raven_Bot*)msg.ExtraInfo); return true; case Msg_UserHasRemovedBot: { Raven_Bot* pRemovedBot = (Raven_Bot*)msg.ExtraInfo; GetSensoryMem()->RemoveBotFromMemory(pRemovedBot); //if the removed bot is the target, make sure the target is cleared if (pRemovedBot == GetTargetSys()->GetTarget()) { GetTargetSys()->ClearTarget(); } return true; } case Msg_IWasKilledAndIHadWeapons: { GraveMarkers::GraveRecord* pGrave = (GraveMarkers::GraveRecord*)msg.ExtraInfo; GetSensoryMem()->AddGraveToMemory(pGrave); return true; } default: return false; } }
int main() { initializeGraphics(); MouseType mouseObject = IDLE; int cursorXLocation = 10; int cursorYLocation = 10; // These control building & unit logic GameEntity* buildingsContainer = NULL; GameEntity* unitsContainer = NULL; uint16_t population = 0; // This controls population count uint16_t frame = 0; // This counts frames uint16_t unitSpawnDelay = 0; // This controls the delay between unit spawns while (true) { FlipBuffers(); // Flip buffers ClearScreen8(SAND_COLOR); // Clear screen render(buildingsContainer,unitsContainer); // Render all buildings and units animatePowerPlant(frame); // Animate the power plant animateBarracks(frame); // Animate the barracks if(mouseObject!=IDLE) // If there has been some mouse action ... { if(isMovement(mouseObject)) // ... and it is movement ... { move(cursorXLocation,cursorYLocation,mouseObject); // ... movet the mouse. } else if(isPlacement(mouseObject)) // ... if it is placement ... { place(cursorXLocation,cursorYLocation,mouseObject,buildingsContainer); // ... attempt placement. } else if(isSpawning(mouseObject) && unitSpawnDelay==0 && population!=POP_CAP) // ... if it is a unit and it's not to soon after the last unit was trained and population cap has not been reached ... { spawn(unitsContainer,buildingsContainer); // place the unit population++; // increase population unitSpawnDelay = UNIT_SPAWN_COOLDOWN_PERIOD; // start cooldown timer } } drawCursor(cursorXLocation,cursorYLocation); // Draw the cursor mouseObject = updatedMouseType(); // Update the mouse WaitVSync(); // Sync frame = (frame == 100) ? 0 : frame+1; // Reset frame count every 100 frames, else increase by one if(unitSpawnDelay!=0) // If there is a cooldown timer in action ... unitSpawnDelay--; // ... update it! } // We are environmentaly concious, so we clean after ourselves delete buildingsContainer; delete unitsContainer; return 0; }