|
From: <be...@us...> - 2017-03-11 19:05:52
|
Revision: 1019
http://sourceforge.net/p/freesynd/code/1019
Author: benblan
Date: 2017-03-11 19:05:49 +0000 (Sat, 11 Mar 2017)
Log Message:
-----------
- Fix some compilation warnings
- When player agents shoot on a vehicle, the driver is ejected
Modified Paths:
--------------
freesynd/trunk/NEWS
freesynd/trunk/src/ia/actions.cpp
freesynd/trunk/src/ia/behaviour.cpp
freesynd/trunk/src/ia/behaviour.h
freesynd/trunk/src/menus/gameplaymenu.cpp
freesynd/trunk/src/model/vehicle.cpp
freesynd/trunk/src/pedactions.cpp
Modified: freesynd/trunk/NEWS
===================================================================
--- freesynd/trunk/NEWS 2017-02-25 15:21:49 UTC (rev 1018)
+++ freesynd/trunk/NEWS 2017-03-11 19:05:49 UTC (rev 1019)
@@ -17,6 +17,7 @@
----------
* Trains now moves and player agents can get on/off
* Persuaded peds follow their leader in cars and trains
+ * When player agents shoot on a vehicle, the driver is ejected
Known issues with this release
------------------------------
Modified: freesynd/trunk/src/ia/actions.cpp
===================================================================
--- freesynd/trunk/src/ia/actions.cpp 2017-02-25 15:21:49 UTC (rev 1018)
+++ freesynd/trunk/src/ia/actions.cpp 2017-03-11 19:05:49 UTC (rev 1019)
@@ -761,10 +761,8 @@
}
bool FireWeaponAction::doExecute(int elapsed, Mission *pMission, PedInstance *pPed) {
- if (shootType_ == ShootAction::kShootActionSingleShoot) {
- if (!pPed->isUsingWeapon()) {
- setSucceeded();
- }
+ if (!pPed->isUsingWeapon()) {
+ setSucceeded();
}
return true;
Modified: freesynd/trunk/src/ia/behaviour.cpp
===================================================================
--- freesynd/trunk/src/ia/behaviour.cpp 2017-02-25 15:21:49 UTC (rev 1018)
+++ freesynd/trunk/src/ia/behaviour.cpp 2017-03-11 19:05:49 UTC (rev 1019)
@@ -120,6 +120,8 @@
doRegenerates_ = true;
}
break;
+ default:
+ break;
}
}
@@ -151,6 +153,9 @@
break;
case Behaviour::kBehvEvtPersuadotronDeactivated:
doUsePersuadotron_ = false;
+ break;
+ default:
+ break;
}
}
@@ -314,8 +319,14 @@
}
switch(evtType) {
+ case Behaviour::kBehvEvtEjectedFromVehicle:
+ // reacting to ejection from vehicle is the same as when a gun is out
+ // -> panic!
+ pCivil->destroyAllActions(true);
+ pCivil->addToDefaultActions(new WalkToDirectionAction());
case Behaviour::kBehvEvtWeaponOut:
- if (!isEnabled()) {
+ // civilian in cars do not panic
+ if (pCivil->inVehicle() == NULL && !isEnabled()) {
setEnabled(true);
status_ = kPanicStatusAlert;
}
@@ -339,6 +350,8 @@
backFromPanic_ = true;
}
break;
+ default:
+ break;
}
}
@@ -385,23 +398,17 @@
PoliceBehaviourComponent::PoliceBehaviourComponent():
BehaviourComponent(), scoutTimer_(200) {
- status_ = kPoliceStatusOnPatrol;
+ status_ = kPoliceStatusDefault;
pTarget_ = NULL;
}
void PoliceBehaviourComponent::execute(int elapsed, Mission *pMission, PedInstance *pPed) {
if (status_ == kPoliceStatusAlert && scoutTimer_.update(elapsed)) {
- PedInstance *pArmedGuy = findArmedPedNotPolice(pMission, pPed);
- if (pArmedGuy != NULL) {
- status_ = kPoliceStatusFollowAndShoot;
- followAndShootTarget(pPed, pArmedGuy);
- }
- } else if (status_ == kPoliceStatusCheckForDefault) {
+ findAndEngageNewTarget(pMission, pPed);
+ } else if (status_ == kPoliceStatusCheckReengageOrDefault) {
// check if there is a nearby enemy
- if (findArmedPedNotPolice(pMission, pPed) != NULL) {
- status_ = kPoliceStatusAlert;
- scoutTimer_.setToMax(); // don't waste time waiting
- } else if (!pPed->isCurrentActionFromSource(Action::kActionDefault)) {
+ bool foundNewTarget = findAndEngageNewTarget(pMission, pPed);
+ if ( !foundNewTarget && !pPed->isCurrentActionFromSource(Action::kActionDefault)) {
// there is no one around so go back to patrol if it's not already the case
pPed->deselectWeapon();
pPed->setCurrentActionWithSource(Action::kActionDefault);
@@ -409,7 +416,7 @@
// There are still some armed peds so keep on alert
status_ = kPoliceStatusAlert;
} else {
- status_ = kPoliceStatusOnPatrol;
+ status_ = kPoliceStatusDefault;
}
}
}
@@ -417,8 +424,11 @@
void PoliceBehaviourComponent::handleBehaviourEvent(PedInstance *pPed, Behaviour::BehaviourEvent evtType, void *pCtxt) {
switch(evtType) {
+ case Behaviour::kBehvEvtEjectedFromVehicle:
+ handleEjectionFromVehicle(pPed, pCtxt);
+ break;
case Behaviour::kBehvEvtWeaponOut:
- if (status_ == kPoliceStatusOnPatrol && !pPed->inVehicle()) {
+ if (status_ == kPoliceStatusDefault && !pPed->inVehicle()) {
// When someone get his weapon out, police is on alert
status_ = kPoliceStatusAlert;
}
@@ -425,28 +435,59 @@
break;
case Behaviour::kBehvEvtWeaponCleared:
// our target has dropped his weapon
- if (pTarget_ == pCtxt) {
- if (status_ == kPoliceStatusFollowAndShoot) {
- status_ = kPoliceStatusPendingEndFollow;
- pPed->stopUsingWeapon();
- // just wait a few time before engaging another target or simply
- // continue with default behavior
- WaitAction *pWait = new WaitAction(WaitAction::kWaitWeapon, kPolicePendingTime);
- pWait->setWarnBehaviour(true);
- pPed->addMovementAction(pWait, false);
- }
- } else if (status_ != kPoliceStatusFollowAndShoot) {
- status_ = kPoliceStatusCheckForDefault;
+ if (status_ == kPoliceStatusFollowAndShootTarget && pTarget_ == pCtxt) {
+ status_ = kPoliceStatusPendingEndFollow;
+ pPed->stopUsingWeapon();
+
+ // just wait a few time before engaging another target or simply
+ // continue with default behavior
+ WaitAction *pWait = new WaitAction(WaitAction::kWaitWeapon, kPolicePendingTime);
+ pWait->setWarnBehaviour(true);
+ pPed->addMovementAction(pWait, false);
+ } else if (status_ == kPoliceStatusAlert) {
+ status_ = kPoliceStatusCheckReengageOrDefault;
}
break;
case Behaviour::kBehvEvtActionEnded:
- // We are at the end of waiting period so check if we need to engage right now
- // of if we can go back on patrol
- status_ = kPoliceStatusCheckForDefault;
+ {
+ Action::ActionType *pType = static_cast<Action::ActionType *> (pCtxt);
+ if (*pType == Action::kActTypeWait) {
+ // We are at the end of waiting period so check if we need to engage right now
+ // of if we can go back on patrol
+ status_ = kPoliceStatusCheckReengageOrDefault;
+ } else {
+ status_ = kPoliceStatusAlert;
+ }
+ }
+
break;
+ default:
+ break;
}
}
+void PoliceBehaviourComponent::handleEjectionFromVehicle(PedInstance *pPed, void *pCtxt) {
+ pPed->destroyAllActions(true);
+ pPed->addToDefaultActions(new WalkToDirectionAction());
+ PedInstance *pShooter = static_cast<PedInstance *>(pCtxt);
+ pPed->setDirectionTowardObject(*pShooter);
+ // Add a walk action just to get away from the vehicle so that the ped can shoot
+ // without being blocked by the vehicle
+ WalkToDirectionAction *outOfCarAction = new WalkToDirectionAction();
+ outOfCarAction->setMaxDistanceToWalk(20);
+ outOfCarAction->setWarnBehaviour(true);
+ pPed->addMovementAction(outOfCarAction, true);
+ status_ = kPoliceStatusOutOfVehicle;
+}
+
+bool PoliceBehaviourComponent::findAndEngageNewTarget(Mission *pMission, PedInstance *pPed) {
+ PedInstance *pArmedGuy = findArmedPedNotPolice(pMission, pPed);
+ if (pArmedGuy != NULL) {
+ followAndShootTarget(pPed, pArmedGuy);
+ }
+ return pArmedGuy != NULL;
+}
+
/*!
* Return a ped that has his weapon out and is not a police man and is close to this policeman.
*/
@@ -462,6 +503,7 @@
void PoliceBehaviourComponent::followAndShootTarget(PedInstance *pPed, PedInstance *pArmedGuy) {
pTarget_ = pArmedGuy;
+ status_ = kPoliceStatusFollowAndShootTarget;
// Set new actions
if (pPed->altAction() == NULL) { // the first time
Modified: freesynd/trunk/src/ia/behaviour.h
===================================================================
--- freesynd/trunk/src/ia/behaviour.h 2017-02-25 15:21:49 UTC (rev 1018)
+++ freesynd/trunk/src/ia/behaviour.h 2017-03-11 19:05:49 UTC (rev 1019)
@@ -60,7 +60,9 @@
//! An action has ended
kBehvEvtActionEnded,
//! An agent is getting into a vehicle so do his persuadeds
- kBehvEvtEnterVehicle
+ kBehvEvtEnterVehicle,
+ //! Car driver has been shot so he is ejected from the car
+ kBehvEvtEjectedFromVehicle,
};
virtual ~Behaviour();
@@ -234,6 +236,9 @@
void handleBehaviourEvent(PedInstance *pPed, Behaviour::BehaviourEvent evtType, void *pCtxt);
private:
+ void handleEjectionFromVehicle(PedInstance *pPed, void *pCtxt);
+ //! Find a nearby armed Ped and follow and shoot him
+ bool findAndEngageNewTarget(Mission *pMission, PedInstance *pPed);
//! Checks whether there is an armed ped next to the ped : returns that ped
PedInstance * findArmedPedNotPolice(Mission *pMission, PedInstance *pPed);
//! Initiate the process of following and shooting at a target
@@ -245,16 +250,18 @@
* Status of police behaviour.
*/
enum PoliceStatus {
- //! Default status
- kPoliceStatusOnPatrol,
+ //! Police is walking or driving car
+ kPoliceStatusDefault,
//! Search for someone who pulled his gun
kPoliceStatusAlert,
//! Move closer from target to shoot at him
- kPoliceStatusFollowAndShoot,
+ kPoliceStatusFollowAndShootTarget,
//! When target drops his weapon, wait some time
kPoliceStatusPendingEndFollow,
//! after waiting, check if police should go on patrol again
- kPoliceStatusCheckForDefault
+ kPoliceStatusCheckReengageOrDefault,
+ //! Police ped is going away from vehicle
+ kPoliceStatusOutOfVehicle
};
PoliceStatus status_;
Modified: freesynd/trunk/src/menus/gameplaymenu.cpp
===================================================================
--- freesynd/trunk/src/menus/gameplaymenu.cpp 2017-02-25 15:21:49 UTC (rev 1018)
+++ freesynd/trunk/src/menus/gameplaymenu.cpp 2017-03-11 19:05:49 UTC (rev 1019)
@@ -1357,11 +1357,14 @@
void GameplayMenu::updateMarkersPosition() {
for (size_t i = 0; i < AgentManager::kMaxSlot; i++) {
if (mission_->sfxObjects(i + 4)->isDrawable()) {
- TilePoint agentPos = mission_->getSquad()->member(i)->position();
- agentPos.ox -= 16;
- agentPos.oz += 256;
+ PedInstance *pAgent = mission_->getSquad()->member(i);
+ if (pAgent != NULL && pAgent->isAlive()) {
+ TilePoint agentPos = pAgent->position();
+ agentPos.ox -= 16;
+ agentPos.oz += 256;
- mission_->sfxObjects(i + 4)->setPosition(agentPos);
+ mission_->sfxObjects(i + 4)->setPosition(agentPos);
+ }
}
}
}
Modified: freesynd/trunk/src/model/vehicle.cpp
===================================================================
--- freesynd/trunk/src/model/vehicle.cpp 2017-02-25 15:21:49 UTC (rev 1018)
+++ freesynd/trunk/src/model/vehicle.cpp 2017-03-11 19:05:49 UTC (rev 1019)
@@ -816,8 +816,17 @@
}
Explosion::createExplosion(g_Session.getMission(), this, 512.0);
- } else {// NOTE: maybe reduce speed on hit?
- // TODO: let passengers know that vehicle is attacked
+ } else if (pDriver_ != NULL && !pDriver_->isOurAgent()) {
+ // in case the car is drived by someone else than our agents
+ // and one of our agent shot the car then
+ // the driver is ejected from the car
+ // Usually he is alone in the car so don't bother with any passengers
+ PedInstance *pShooter = dynamic_cast<PedInstance *>(d.d_owner);
+ if (pShooter && pShooter->isOurAgent()) {
+ PedInstance *pPed = pDriver_;
+ dropPassenger(pPed);
+ pPed->behaviour().handleBehaviourEvent(Behaviour::kBehvEvtEjectedFromVehicle, pShooter);
+ }
}
}
Modified: freesynd/trunk/src/pedactions.cpp
===================================================================
--- freesynd/trunk/src/pedactions.cpp 2017-02-25 15:21:49 UTC (rev 1018)
+++ freesynd/trunk/src/pedactions.cpp 2017-03-11 19:05:49 UTC (rev 1019)
@@ -170,18 +170,16 @@
* \param source
*/
void PedInstance::resetActions(Action::ActionSource source) {
- MovementAction *pAction = (source == Action::kActionDefault) ?
+ currentAction_ = (source == Action::kActionDefault) ?
defaultAction_ : altAction_;
- if (pAction) {
+ if (currentAction_) {
// reset all scripted actions
- MovementAction *pActionToReset = pAction;
+ MovementAction *pActionToReset = currentAction_;
while (pActionToReset != NULL) {
pActionToReset->reset();
pActionToReset = pActionToReset->next();
}
-
- currentAction_ = pAction;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|