| 1 | /*************************************************************************** |
| 2 | agentrobber.cpp - description |
| 3 | ------------------- |
| 4 | begin : nov 29th, 2005 |
| 5 | copyright : (C) 2005-2008 by Duong Khang NGUYEN |
| 6 | email : neoneurone @ gmail com |
| 7 | author : Victor STINNER |
| 8 | |
| 9 | $Id: agentrobber.cpp 375 2008-10-28 14:47:15Z neoneurone $ |
| 10 | ***************************************************************************/ |
| 11 | |
| 12 | /*************************************************************************** |
| 13 | * * |
| 14 | * This program is free software; you can redistribute it and/or modify * |
| 15 | * it under the terms of the GNU General Public License as published by * |
| 16 | * the Free Software Foundation; either version 2 of the License, or * |
| 17 | * any later version. * |
| 18 | * * |
| 19 | ***************************************************************************/ |
| 20 | |
| 21 | |
| 22 | #include "agentrobber.h" |
| 23 | #include "kernel.h" |
| 24 | #include "message.h" |
| 25 | |
| 26 | |
| 27 | /*=====================================================================*/ |
| 28 | AgentRobber::AgentRobber |
| 29 | ( |
| 30 | Kernel& kernel, |
| 31 | Environment& env, |
| 32 | int x, int y |
| 33 | ): |
| 34 | Agent(kernel, env, x, y, ROLE_ROBBER) |
| 35 | { |
| 36 | this->born(); // Warning: see superclass |
| 37 | |
| 38 | // OpenCity's specifics |
| 39 | this->SetGraphicCode( OC_VEHICLE_ROBBER ); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | /*=====================================================================*/ |
| 44 | AgentRobber::~AgentRobber() |
| 45 | { |
| 46 | if (m_agent_state != AGENT_DIE) |
| 47 | this->die(); // Warning: see superclass |
| 48 | } |
| 49 | |
| 50 | |
| 51 | /*=====================================================================*/ |
| 52 | void |
| 53 | AgentRobber::processMessage() |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | |
| 58 | /*=====================================================================*/ |
| 59 | void |
| 60 | AgentRobber::born() |
| 61 | { |
| 62 | Agent::born(); |
| 63 | m_kernel.registerRole(this, ROLE_ROBBER); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | /*=====================================================================*/ |
| 68 | void |
| 69 | AgentRobber::live() |
| 70 | { |
| 71 | static bool first = true; |
| 72 | |
| 73 | if (first) { |
| 74 | sendMessage( ROLE_POLICE, Message( MSG_NEW_ROBBER ) << 10 << 5); |
| 75 | first = false; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | |
| 80 | /*=====================================================================*/ |
| 81 | void |
| 82 | AgentRobber::die() |
| 83 | { |
| 84 | Agent::die(); |
| 85 | m_kernel.unregisterRole(this, this->getRole()); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | /*=====================================================================*/ |
| 90 | void |
| 91 | AgentRobber::output (std::ostream& os) const |
| 92 | { |
| 93 | os << "AgentRobber " << getId(); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 |