start rework on persuasion.
authorbenblan <benblan@3ce38193-f967-438d-acd5-fc4e68e0da95>
Wed, 13 Aug 2014 11:42:54 +0000 (11:42 +0000)
committerbenblan <benblan@3ce38193-f967-438d-acd5-fc4e68e0da95>
Wed, 13 Aug 2014 11:42:54 +0000 (11:42 +0000)
freesynd/branches/rework-actions/src/core/gamesession.cpp
freesynd/branches/rework-actions/src/ia/action.cpp
freesynd/branches/rework-actions/src/menus/gameplaymenu.cpp
freesynd/branches/rework-actions/src/ped.cpp
freesynd/branches/rework-actions/src/ped.h

index bba38b8e6d9c5ce252e0185b9b86987b8042eac3..9ae47292caffcd0edeca2cadbdeb2266b09216d0 100644 (file)
@@ -37,25 +37,25 @@ Block g_Blocks[50] = {
     {"#CNTRY_16", 40000000, 40000000, 16, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},            // 3 - GREENLAND
     {"#CNTRY_20", 54000000, 54000000, 20, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, "10", 0, 0, 0},            // 4 - Scandinavia
     {"#CNTRY_18", 40000000, 40000000, 18, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, "6:12:13", 0, 0, 0},       // 5 - Ural
-    {"#CNTRY_22", 54000000, 54000000, 22, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, "7", 0, 0, 0},             // 6 - Siberia
+    {"#CNTRY_22", 54000000, 54000000, 22, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, "7:13", 0, 0, 0},          // 6 - Siberia
     {"#CNTRY_12", 56000000, 56000000, 12, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},            // 7 - KAMCHATKA
     {"#CNTRY_21", 58000000, 58000000, 21, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},            // 8 - YUKON
     {"#CNTRY_01", 48000000, 48000000, 1, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, "4", 0, 0, 0},              // 9 - West Eur.
     {"#CNTRY_15", 50000000, 50000000, 15, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, "11", 0, 0, 0},            // 10 - Central Eur.
     {"#CNTRY_10", 52000000, 52000000, 10, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, "5", 0, 0, 0},             // 11 - Eastern Eur.
-    {"#CNTRY_09", 42000000, 42000000, 9, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},             // 12 - KAZAKHSTAN
+    {"#CNTRY_09", 42000000, 42000000, 9, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, "23:24", 0, 0, 0},          // 12 - KAZAKHSTAN
     {"#CNTRY_03", 52000000, 52000000, 3, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, "14", 0, 0, 0},             // 13 - MONGOLIA
     {"#CNTRY_02", 42000000, 42000000, 2, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},             // 14 - FAR EAST
-    {"#CNTRY_42", 44000000, 44000000, 42, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
-    {"#CNTRY_05", 46000000, 46000000, 5, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
-    {"#CNTRY_23", 56000000, 56000000, 23, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
-    {"#CNTRY_34", 58000000, 58000000, 34, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
-    {"#CNTRY_29", 40000000, 40000000, 29, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
-    {"#CNTRY_28", 50000000, 50000000, 28, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
-    {"#CNTRY_35", 40000000, 40000000, 35, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
-    {"#CNTRY_06", 50000000, 50000000, 6, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
-    {"#CNTRY_04", 52000000, 52000000, 4, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
-    {"#CNTRY_50", 54000000, 54000000, 50, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
+    {"#CNTRY_42", 44000000, 44000000, 42, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},            // 15 - 
+    {"#CNTRY_05", 46000000, 46000000, 5, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},             // 16 - 
+    {"#CNTRY_23", 56000000, 56000000, 23, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},            // 17 - 
+    {"#CNTRY_34", 58000000, 58000000, 34, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},            // 18 - 
+    {"#CNTRY_29", 40000000, 40000000, 29, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},            // 19 - 
+    {"#CNTRY_28", 50000000, 50000000, 28, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},            // 20 - 
+    {"#CNTRY_35", 40000000, 40000000, 35, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},            // 21 - 
+    {"#CNTRY_06", 50000000, 50000000, 6, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},             // 22 - 
+    {"#CNTRY_04", 52000000, 52000000, 4, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},             // 23 - Iran
+    {"#CNTRY_50", 54000000, 54000000, 50, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},            // 24 - China
     {"#CNTRY_32", 40000000, 40000000, 32, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
     {"#CNTRY_24", 42000000, 42000000, 24, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
     {"#CNTRY_37", 44000000, 44000000, 37, 30, 0, STAT_VERY_HAPPY, 0, 0, BLK_UNAVAIL, NULL, 0, 0, 0},
index ba0b7c5880b8118241134a3001b849e73f27bc5f..b987e505ce73c3dfa578559926d60fd8fc5d68d1 100644 (file)
@@ -507,7 +507,7 @@ HitAction(kOrigAction, d) {
  */
 bool FallDeadHitAction::doExecute(int elapsed, Mission *pMission, PedInstance *pPed) {
     if (status_ == kActStatusRunning) {
-        pPed->handleDeath(damage_);
+        pPed->handleDeath(pMission, damage_);
         setSucceeded();
     }
     return true;
@@ -539,7 +539,7 @@ void RecoilHitAction::doStart(Mission *pMission, PedInstance *pPed) {
  */
 bool RecoilHitAction::doExecute(int elapsed, Mission *pMission, PedInstance *pPed) {
     if (status_ == kActStatusRunning) {
-        if (pPed->handleDeath(damage_)) {
+        if (pPed->handleDeath(pMission, damage_)) {
             targetState_ = PedInstance::pa_smNone;
         }
         setSucceeded();
@@ -573,7 +573,7 @@ void LaserHitAction::doStart(Mission *pMission, PedInstance *pPed) {
  */
 bool LaserHitAction::doExecute(int elapsed, Mission *pMission, PedInstance *pPed) {
     if (status_ == kActStatusRunning) {
-        if (pPed->handleDeath(damage_)) {
+        if (pPed->handleDeath(pMission, damage_)) {
             targetState_ = PedInstance::pa_smNone;
         }
         setSucceeded();
@@ -612,7 +612,7 @@ bool WalkBurnHitAction::doExecute(int elapsed, Mission *pMission, PedInstance *p
     if (burnTimer_.update(elapsed)) {
         setSucceeded();
 
-        if (pPed->handleDeath(damage_)) {
+        if (pPed->handleDeath(pMission, damage_)) {
             targetState_ = PedInstance::pa_smNone;
         }
     }
index 871a48aa087fc18976b7c9673d0b77bb8c257dde..be111ab4da555872b9cff798d860e60f38f22b09 100644 (file)
@@ -1488,8 +1488,11 @@ void GameplayMenu::handleGameEvent(GameEvent evt) {
         }
     } else if (evt.type == GameEvent::kEvtWeaponCleared) {
         // some ped has put his weapon away, deactivate panic among civilians
-        cntArmedPed_ -= 1;
-        if (cntArmedPed_ == 0) {
+        // we check value just to be sure not to go out of range
+        if (cntArmedPed_ > 1) {
+            cntArmedPed_ -= 1;
+        } else if (cntArmedPed_ == 1) {
+            cntArmedPed_ = 0;
             for (size_t i = 0; i < mission_->numPeds(); i++) {
                 PedInstance *pPed = mission_->ped(i);
                 if (pPed->type() == PedInstance::kPedTypeCivilian &&
index ce06ac2a26964c751bad963b2ecc225e4b29bb12..b27626bb294b03bf0be82f15a341d9ef76c93611 100644 (file)
@@ -1660,7 +1660,7 @@ bool PedInstance::animate(int elapsed, Mission *mission) {
                             findQueueInActQueue(it->group_id + 2);
 
                         if (owner_->isDead()) {
-                            ((PedInstance *)owner_)->rmvPersuaded(this);
+                            owner_->rmvPersuaded(this);
                             // agent is dead choose another agent from alive
                             owner_ = NULL;
                             Squad *sq = mission->getSquad();
@@ -1689,7 +1689,7 @@ bool PedInstance::animate(int elapsed, Mission *mission) {
                                 if ((it_wpn->state & 2) != 0)
                                     disable_walking = true;
                             }
-                            if (((PedInstance *)owner_)->isArmed()) {
+                            if (owner_->isArmed()) {
                                 if (weapons_.empty()) {
                                     // enable find and pickup weapon
                                     if (it_wpn != actions_queue_.end()) {
@@ -1706,7 +1706,7 @@ bool PedInstance::animate(int elapsed, Mission *mission) {
                                     if (searched != it->actions.end()) {
                                         actionQueueType & aqt_attack = *searched;
                                         targetDescType *t_fire =
-                                            ((PedInstance *)owner_)->lastFiringTarget();
+                                            owner_->lastFiringTarget();
                                         if (t_fire->desc == 1) {
                                             // changing action to execute
                                             aqt_attack.act_exec = PedInstance::ai_aAttackLocation
@@ -2598,12 +2598,12 @@ void PedInstance::handleHit(DamageInflictType &d) {
  * \param d Damage description
  * \return true if Ped has died
  */
-bool PedInstance::handleDeath(ShootableMapObject::DamageInflictType &d) {
+bool PedInstance::handleDeath(Mission *pMission, ShootableMapObject::DamageInflictType &d) {
     if (health_ == 0) {
         clearDestination();
         switchActionStateTo(PedInstance::pa_smDead);
-        if ((desc_state_ & pd_smControlled) != 0 && owner_)
-            ((PedInstance *)owner_)->rmvPersuaded(this);
+
+        updatePersuadedRelations(pMission->getSquad());
 
         if (selectedWeapon() && selectedWeapon()->canShoot()) {
             GameEvent::sendEvt(GameEvent::kMission, GameEvent::kEvtWeaponCleared);
@@ -2706,7 +2706,7 @@ bool PedInstance::handleDamage(ShootableMapObject::DamageInflictType *d) {
         destroyAllActions();
         switchActionStateTo(PedInstance::pa_smDead);
         if ((desc_state_ & pd_smControlled) != 0 && owner_)
-            ((PedInstance *)owner_)->rmvPersuaded(this);
+            owner_->rmvPersuaded(this);
 
         switch (d->dtype) {
             case MapObject::dmg_Bullet:
@@ -2924,7 +2924,7 @@ int PedInstance::getDefaultSpeed()
     }
 
     if (desc_state_ == PedInstance::pd_smControlled) {
-        speed_new *= ((PedInstance *)owner_)->getSpeedOwnerBoost();
+        speed_new *= owner_->getSpeedOwnerBoost();
         speed_new >>= 1;
     }
 
@@ -3074,8 +3074,8 @@ bool PedInstance::canPersuade(int points) {
     }
     // always 1
     int points_avail = 1;
-    for (std::set <PedInstance *>::iterator it = persuaded_group_.begin();
-         it != persuaded_group_.end(); ++it)
+    for (std::set <PedInstance *>::iterator it = persuadedSet_.begin();
+         it != persuadedSet_.end(); ++it)
     {
         // NOTE: mods influence "to persuade" points, but not
         // of already persuaded
@@ -3085,12 +3085,39 @@ bool PedInstance::canPersuade(int points) {
 }
 
 void PedInstance::addPersuaded(PedInstance *p) {
-    persuaded_group_.insert(p);
+    persuadedSet_.insert(p);
 }
 
 void PedInstance::rmvPersuaded(PedInstance *p) {
-    std::set <PedInstance *>::iterator it =  persuaded_group_.find(p);
-    if (it != persuaded_group_.end())
-        persuaded_group_.erase(it);
+    std::set <PedInstance *>::iterator it =  persuadedSet_.find(p);
+    if (it != persuadedSet_.end())
+        persuadedSet_.erase(it);
 }
 
+/*!
+ * After a ped died (agent or other), updates the relation between the owner
+ * and the peds he has persuaded.
+ * If dead ped is a persuaded, just removed him from the list of his owner.
+ * If dead ped is our agent, transfer all his persuaded to another living agent.
+ * \param pSquad List of available agents
+ */
+void PedInstance::updatePersuadedRelations(Squad *pSquad) {
+    if (IS_FLAG_SET(desc_state_, pd_smControlled) && owner_ != NULL) {
+        owner_->rmvPersuaded(this);
+        owner_ = NULL;
+    } else if (isOurAgent()) {
+        // our agent is dead, assign all persuaded to another living agent
+        for (uint8 i = 0; i < AgentManager::kMaxSlot; ++i) {
+            PedInstance *pAgent = pSquad->member(i);
+            if (pAgent && pAgent->isAlive()) {
+                while(!persuadedSet_.empty()) {
+                    std::set <PedInstance *>::iterator it = persuadedSet_.begin();
+                    PedInstance *pPed = *it;
+                    persuadedSet_.erase(it);
+                    pAgent->addPersuaded(pPed);
+                }
+                break;
+            }
+        }
+    }
+}
\ No newline at end of file
index 02ffa12f3beb019ffb18033aec07aa66dfa1ef2a..acbec609a8162db05a48b75eb9b002f8ba9d3d00 100644 (file)
@@ -43,6 +43,7 @@
 
 class Agent;
 class Mission;
+class Squad;
 class VehicleInstance;
 class Vehicle;
 
@@ -385,7 +386,7 @@ public:
     //! Method called when object is hit by a weapon shot.
     void handleHit(ShootableMapObject::DamageInflictType &d);
     //! Method called to check if ped has died
-    bool handleDeath(ShootableMapObject::DamageInflictType &d);
+    bool handleDeath(Mission *pMission, ShootableMapObject::DamageInflictType &d);
     bool handleDamage(ShootableMapObject::DamageInflictType *d);
 
     //! Method called when an agent try to persuad this ped
@@ -900,6 +901,9 @@ protected:
 
     //! Creates and insert a HitAction for the ped
     void insertHitAction(DamageInflictType &d);
+
+    //! When a ped dies, changes the persuaded owner/persuaded_group relation.
+    void updatePersuadedRelations(Squad *pSquad);
 protected:
     Ped *ped_;
     //! Type of Ped
@@ -956,11 +960,12 @@ protected:
     //! This flag tells if this is our agent, assuming it's an agent.
     bool is_our_;
     //! controller of ped - for persuaded
-    ShootableMapObject *owner_;
+    PedInstance *owner_;
     targetDescType last_firing_target_;
     //! points needed to persuade ped
     int persuasion_points_;
-    std::set <PedInstance *> persuaded_group_;
+    //! The group of peds that this ped has persuaded
+    std::set <PedInstance *> persuadedSet_;
     //! Tells whether the panic can react to panic or not
     bool panicImmuned_;