Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc @ 10915

Last change on this file since 10915 was 10915, checked in by gania, 8 years ago

little fix

File size: 29.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Gani Aliguzhinov
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "ActionpointController.h"
30
31#include "core/XMLPort.h"
32#include <algorithm>
33#include "worldentities/Actionpoint.h"
34
35namespace orxonox
36{
37
38    RegisterClass(ActionpointController);
39
40    ActionpointController::ActionpointController(Context* context) : FightingController(context)
41    {
42        this->bPatrolling_ = false;
43
44        this->actionCounter_ = 0;
45        this->bInLoop_ = false;
46        this->bLoop_ = false;
47        this->bEndLoop_ = false;
48        loopActionpoints_.clear();
49        parsedActionpoints_.clear();
50        actionpoints_.clear();
51        healthSpawners_.clear();
52        damageSpawners_.clear();
53        speedSpawners_.clear();
54        this->bTakenOver_ = false;
55        this->action_ = Action::NONE;
56        this->squaredaccuracy_ = 2500;
57        this->bFirstTick_ = true;
58        this->bStartedDodging_ = false;
59        this->timeDodged_ = 0;
60        this->bDefaultPatrol_ = true;
61        this->bDefaultFightAll_ = true;
62        this->stop_ = false;
63        RegisterObject(ActionpointController);
64
65    }
66    void ActionpointController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
67    {
68        SUPER( ActionpointController, XMLPort, xmlelement, mode );
69        // XMLPortEventSink(ActionpointController, BaseObject, "stop", stop, xmlelement, mode);
70        // XMLPortEventSink(ActionpointController, BaseObject, "go", stop, xmlelement, mode);
71
72        XMLPortObject(ActionpointController, WorldEntity, "actionpoints", addActionpoint, getActionpoint,  xmlelement, mode);
73        XMLPortParam(ActionpointController, "defaultFightAll", setDefaultFightAll, getDefaultFightAll, xmlelement, mode).defaultValues(true);
74        XMLPortParam(ActionpointController, "defaultPatrol", setDefaultPatrol, getDefaultPatrol, xmlelement, mode).defaultValues(true);
75    }
76    // void ActionpointController::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
77    // {
78    //     SUPER(ActionpointController, XMLEventPort, xmlelement, mode);
79    //     XMLPortEventSink(ActionpointController, BaseObject, "stop", stop, xmlelement, mode);
80    //     XMLPortEventSink(ActionpointController, BaseObject, "go", stop, xmlelement, mode);
81
82    // }
83    // bool ActionpointController::stop(bool bTriggered, BaseObject* trigger)
84    // {
85    //     this->stop_ = true;
86    //     return true;
87    // }
88    // bool ActionpointController::go(bool bTriggered, BaseObject* trigger)
89    // {
90    //     this->stop_ = false;
91    //     return true;
92    // }
93    ActionpointController::~ActionpointController()
94    {
95        loopActionpoints_.clear();
96        parsedActionpoints_.clear();
97        actionpoints_.clear();
98        healthSpawners_.clear();
99        damageSpawners_.clear();
100        speedSpawners_.clear();
101    }
102    void ActionpointController::tick(float dt)
103    {
104        if (!this->getControllableEntity())
105            return;
106        if (stop_)
107            return;
108        if (this->timeout_ > 0 && this->bFiredRocket_)
109        {
110            this->timeout_ -= dt;
111        }
112        if (this->bStartedDodging_)
113        {
114            this->timeDodged_ += dt;
115            if (this->timeDodged_ > 4.0f)
116            {
117                this->bStartedDodging_ = false;
118                this->timeDodged_ = 0;
119            }
120        }
121        maneuverCounter_ += dt;
122        if (maneuverCounter_ > 6.0f)
123            maneuverCounter_ = 0;
124        this->timeOffset_ += dt;
125        if (this->timeOffset_ >= 2.4f)
126            this->timeOffset_ = 0.0f;
127        if (timeout_ <= 0)
128            this->bFiredRocket_ = false;
129
130        if (this->bHasTargetPosition_)
131        {
132            this->moveToTargetPosition(dt);
133        }
134        else if (this->bLookAtTarget_)
135        {
136            this->lookAtTarget(dt);
137        }
138
139        if (!this->getControllableEntity())
140            return;
141        if (this->bShooting_)
142        {
143            this->doFire();
144        }
145        if (this->bFirstTick_)
146        {
147            std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end());
148            std::reverse(actionpoints_.begin(), actionpoints_.end());
149            if (this->parsedActionpoints_.empty())
150            {
151                this->action_ = Action::FIGHTALL;
152            }
153        }
154        if (this->bFirstTick_)
155        {   
156            this->timeOffset_ = 0.0f;
157            this->bActionCalled_ = false;
158            setSpawners();
159            // orxout(internal_error) << "health spawners size = " << this->healthSpawners_.size() <<
160            // ", damage spawners size = " << this->damageSpawners_.size() <<
161            // ", speed spawners size = " << this->speedSpawners_.size() << endl;       
162            this->bFirstTick_ = false;
163        }
164        if (!this->getControllableEntity())
165            return;
166        //maneuver every 0.25 sec ->
167        if (this->hasTarget() && 
168            ((this->timeOffset_ >= 0.4f && this->timeOffset_ < 0.8f) || 
169             (this->timeOffset_ >= 1.2f && this->timeOffset_ < 1.6f) ||
170             (this->timeOffset_ >= 1.8f && this->timeOffset_ < 2.0f) ||
171             (this->timeOffset_ >= 2.2f && this->timeOffset_ < 2.4f)) && !this->bManeuverCalled_)
172        {
173            this->bManeuverCalled_ = true;
174            this->maneuver();
175            this->bShooting_ = this->canFire();
176        }
177        if ((this->timeOffset_ >= 0.0f && this->timeOffset_ < 0.4f) || 
178             (this->timeOffset_ >= 0.8f && this->timeOffset_ < 1.2f) ||
179             (this->timeOffset_ >= 1.6f && this->timeOffset_ < 1.8f) ||
180             (this->timeOffset_ >= 2.0f && this->timeOffset_ < 2.2f))
181            this->bManeuverCalled_ = false;
182        SUPER(ActionpointController, tick, dt);
183    }
184     
185
186
187    void ActionpointController::action()
188    {
189        if (!this || !this->getControllableEntity())
190            return;
191        if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity()))
192            return;
193        if (this->bDefaultPatrol_ || (this->action_ != Action::FLY && this->action_ != Action::NONE))
194        {
195            this->startAttackingEnemiesThatAreClose();
196        }
197        this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
198        this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
199
200        // if (this->actionCounter_ % 2 == 0)
201        //No action -> pop one from stack
202        if (this->action_ == Action::NONE || this->bTakenOver_)
203        {
204            // Point point = closestPickup(PickupType::HEALTH);
205            // if (point.action != Action::NONE)
206            // {
207            //     orxout(internal_error) << "found health" << endl;
208            //     this->parsedActionpoints_.push_back(point);
209            // }
210
211            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_)
212            {
213                Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
214                this->parsedActionpoints_.push_back (p);
215            }
216            this->executeActionpoint();
217            this->bTakenOver_ = false;
218            // this->action();
219        }
220        //Action fightall -> fight till nobody alive
221        if (this->action_ == Action::FIGHTALL)
222        {
223
224            if (!this->hasTarget())
225            {
226                ControllableEntity* newTarget = this->closestTarget();   
227                if (newTarget)
228                {
229                    this->setAction (Action::FIGHTALL, newTarget);
230                    //this->action();
231                }
232                else
233                {
234                    this->nextActionpoint();
235                    this->executeActionpoint();
236   
237                }
238            }
239        }
240        //Action fight -> fight as long as enemies in range
241        else if (this->action_ == Action::FIGHT)
242        {
243
244            if (!this->hasTarget() )
245            {
246                //----find a target----
247                ControllableEntity* newTarget = this->closestTarget();   
248                if (newTarget && 
249                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
250                {
251                    this->setAction (Action::FIGHT, newTarget);
252                    //this->action();
253                }
254                else
255                {
256                    this->nextActionpoint();
257                    this->executeActionpoint();
258                }
259            }
260            else if (this->hasTarget())
261            {
262                //----fly in formation if far enough----
263                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
264                   
265                if (diffVector.length() > this->attackRange_)
266                {
267                    ControllableEntity* newTarget = this->closestTarget();
268                   
269                    if (newTarget && 
270                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
271                    {
272                        this->setAction (Action::FIGHT, newTarget);
273                    }
274                    else
275                    {
276                        this->nextActionpoint();
277                        this->executeActionpoint();
278                    }
279                }
280            }
281        }
282        else if (this->action_ == Action::FLY)
283        {
284            if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
285            {
286                this->nextActionpoint();   
287                this->executeActionpoint();
288            }
289        }
290        else if (this->action_ == Action::PROTECT)
291        {
292            if (!this->getProtect())
293            {
294                this->nextActionpoint();
295                this->executeActionpoint(); 
296            }
297            this->stayNearProtect();
298        }
299        else if (this->action_ == Action::ATTACK)
300        {   
301
302            if (!this->hasTarget())
303            {
304                this->nextActionpoint();
305                this->executeActionpoint();
306            }
307        }
308
309            // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length());
310            // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_)
311            // {
312            //     //----choose where to go----
313            //     this->maneuver();
314            // }
315            // else
316            // {
317            //     this->dodgeTowards(healthPosition);
318            // }
319            // //----fire if you can----
320            // this->bShooting_ = this->canFire(); 
321         
322        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
323
324    }
325    void ActionpointController::setProtect (ControllableEntity* protect)
326    {
327        this->protect_ = protect;
328    }
329    ControllableEntity* ActionpointController::getProtect ()
330    {
331        return this->protect_;
332    }
333    void ActionpointController::addActionpoint(WorldEntity* actionpoint)
334    {
335        std::string actionName;
336        Vector3 position;
337        std::string targetName;
338        bool inLoop = false;
339        Point p;
340        if (actionpoint->getIdentifier()->getName() == "Actionpoint")
341        {
342            Actionpoint* ap = orxonox_cast<Actionpoint*> (actionpoint);
343            actionName = ap->getActionXML();
344            targetName = ap->getName();
345            position = ap->getWorldPosition();
346
347            if (this->bEndLoop_)
348            {
349                this->bInLoop_ = false;
350            }
351            if (!this->bInLoop_ && ap->getLoopStart())
352            {
353                this->bInLoop_ = true;
354            }
355            if (this->bInLoop_ && ap->getLoopEnd())
356            {
357                this->bEndLoop_ = true;
358            }
359            inLoop = this->bInLoop_;
360
361            Action::Value value;
362           
363            if ( actionName == "FIGHT" )
364            { value = Action::FIGHT; }
365            else if ( actionName == "FLY" )
366            { value = Action::FLY; }
367            else if ( actionName == "PROTECT" )
368            { value = Action::PROTECT; }
369            else if ( actionName == "NONE" )
370            { value = Action::NONE; }
371            else if ( actionName == "FIGHTALL" )
372            { value = Action::FIGHTALL; }
373            else if ( actionName == "ATTACK" )
374            { value = Action::ATTACK; }
375            else
376                ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ actionName + "'." );
377            p.action = value; p.name = targetName; p.position = position; p.inLoop = inLoop;
378        }
379        else
380        {
381            inLoop = true;
382            p.action = Action::FLY; p.name = ""; p.position = actionpoint->getWorldPosition(); p.inLoop = inLoop;
383        }
384            parsedActionpoints_.push_back(p);
385            this->actionpoints_.push_back(actionpoint);
386    }
387    WorldEntity* ActionpointController::getActionpoint(unsigned int index) const
388    {
389        if (index < this->actionpoints_.size())
390            return this->actionpoints_[index];
391        else
392            return 0;
393    }
394
395    Action::Value ActionpointController::getAction ()
396    {
397        return this->action_;
398    }
399    std::string ActionpointController::getActionName()
400    {
401        switch ( this->action_ )
402        {
403            case Action::FIGHT:
404            { return "FIGHT"; break; }
405            case Action::FLY:
406            { return "FLY"; break; }
407            case Action::PROTECT:
408            { return "PROTECT"; break; }
409            case Action::NONE:
410            { return "NONE"; break; }
411            case Action::FIGHTALL:
412            { return "FIGHTALL"; break; }
413            case Action::ATTACK:
414            { return "ATTACK"; break; }
415            default:
416                return "NONE";
417                break;
418        }
419    }
420    void ActionpointController::setAction (Action::Value action)
421    {
422        this->action_ = action;
423    }
424    void ActionpointController::setAction (Action::Value action, ControllableEntity* target)
425    {
426        this->action_ = action;
427        if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
428        {   
429            if (target)
430                this->setTarget (target);
431        }
432        else if (action == Action::PROTECT)
433        {
434            if (target)
435                this->setProtect (target);
436        }
437    }
438    void ActionpointController::setAction (Action::Value action, const Vector3& target)
439    {
440        this->action_ = action;
441        if (action == Action::FLY)
442        {
443            this->setTargetPosition (target);
444        }
445    }
446    void ActionpointController::setAction (Action::Value action, const Vector3& target,  const Quaternion& orient )
447    {
448        this->action_ = action;
449        if (action == Action::FLY)
450        {
451            this->setTargetPosition (target);
452            this->setTargetOrientation (orient);
453        } 
454    }
455   
456    //------------------------------------------------------------------------------
457    //------------------------------Actionpoint methods-----------------------------
458    //------------------------------------------------------------------------------
459
460    //POST: this starts doing what was asked by the last element of parsedActionpoints_,
461    //if last element was failed to be parsed, next element will be executed.
462    void ActionpointController::executeActionpoint()
463    {
464        Point p;
465        if (this->bLoop_ && !loopActionpoints_.empty())
466        {
467            p = loopActionpoints_.back();
468        }
469        else if (this->bLoop_)
470        {
471            this->bLoop_ = false;
472            return;
473        }
474        else if (!this->bLoop_ && !parsedActionpoints_.empty())
475        {
476            p = parsedActionpoints_.back();
477        }
478        else
479        {
480            this->setTarget(0);
481            this->setTargetPosition(this->getControllableEntity()->getWorldPosition());
482            this->action_ = Action::NONE;
483            return;
484        }
485        if (!this->bLoop_ && this->parsedActionpoints_.back().inLoop)
486        {
487            //MOVES all points that are in loop to a loop vector
488            this->fillLoop();
489            this->bLoop_ = true;
490            executeActionpoint();
491            return;
492        }
493        this->setAction (p.action);
494        switch (this->action_)
495        {
496            case Action::FIGHT:
497            {
498                std::string targetName = p.name;
499                if (targetName == "")
500                    break;
501                for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
502                {
503                    if (CommonController::getName(*itP) == targetName)
504                    {
505                        this->setTarget (static_cast<ControllableEntity*>(*itP));
506                    }
507                }
508                break;
509            }
510            case Action::FLY:
511            {
512                this->setTargetPosition( p.position );
513                if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
514                {
515                    this->nextActionpoint();
516                    this->executeActionpoint();
517                }
518                break;
519            }
520            case Action::PROTECT:
521            {
522               
523                std::string protectName = p.name;
524                if (protectName == "reservedKeyword:human")
525                {
526                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
527                    {
528                        if (orxonox_cast<ControllableEntity*>(*itP) && ((*itP)->getController()) && ((*itP)->getController()->getIdentifier()->getName() == "NewHumanController"))
529                        {
530                            this->setProtect (static_cast<ControllableEntity*>(*itP));
531                        }
532                    }
533                }
534                else
535                {
536                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
537                    {
538                        if (CommonController::getName(*itP) == protectName)
539                        {
540                            this->setProtect (static_cast<ControllableEntity*>(*itP));
541                        }
542                    }                           
543                }
544                if (!this->getProtect())
545                {
546                    this->nextActionpoint();
547                    this->executeActionpoint();
548                }
549                break;
550            }
551            case Action::NONE:
552            {
553                break;
554            }
555            case Action::FIGHTALL:
556            {
557                break;
558            }
559            case Action::ATTACK:
560            {
561                std::string targetName = p.name;
562
563                for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
564                {
565                    if (CommonController::getName(*itP) == targetName)
566                    {
567                        this->setTarget (static_cast<ControllableEntity*>(*itP));
568                    }
569                }
570                if (!this->hasTarget())
571                {
572                    this->nextActionpoint();
573                    this->executeActionpoint();
574                }
575                break;
576            }
577            default:
578                break;
579        }   
580    }
581
582   
583    void ActionpointController::stayNearProtect()
584    {
585        Vector3 targetRelativePosition(0, 300, 300);
586        if (!this->getProtect())
587        {
588            this->nextActionpoint();
589            return;
590        } 
591        Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 
592            (this->getProtect()->getWorldOrientation()* (targetRelativePosition)));
593        this->setTargetPosition(targetAbsolutePosition);
594        if (!this->getProtect())
595        {
596            this->nextActionpoint();
597            return;
598        } 
599        this->setTargetOrientation(this->getProtect()->getWorldOrientation());
600    }
601    void ActionpointController::nextActionpoint()
602    {
603        if (!this || !this->getControllableEntity())
604            return;
605        if (this->bLoop_)
606        {
607            if (this->bPatrolling_)
608            {
609                this->loopActionpoints_.pop_back();
610                this->bPatrolling_ = false;
611            }
612            else if (!this->loopActionpoints_.empty())
613            {
614                this->moveBackToTop();
615            }
616        }
617        else
618        {
619            if (!this->parsedActionpoints_.empty())
620            {
621                this->parsedActionpoints_.pop_back();
622            }           
623        }
624        this->setAction(Action::NONE);
625        this->bHasTargetPosition_ = false;
626    }
627    void ActionpointController::moveBackToTop()
628    {
629        Point temp = loopActionpoints_.back();
630        loopActionpoints_.pop_back();
631        std::reverse (loopActionpoints_.begin(), loopActionpoints_.end());
632        loopActionpoints_.push_back(temp);
633        std::reverse (loopActionpoints_.begin(), loopActionpoints_.end());
634    }
635    void ActionpointController::fillLoop()
636    {
637        loopActionpoints_.clear();
638        fillLoopReversed();
639        std::reverse (loopActionpoints_.begin(), loopActionpoints_.end());
640    }
641    void ActionpointController::fillLoopReversed()
642    {
643        if (parsedActionpoints_.back().inLoop)
644        {
645            loopActionpoints_.push_back(parsedActionpoints_.back());
646            parsedActionpoints_.pop_back();
647        }
648        if (parsedActionpoints_.back().inLoop)
649        {
650            fillLoopReversed();
651        }
652    }
653   
654    void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b)
655    {
656      this->parsedActionpoints_ = vector;
657      this->loopActionpoints_ = loop;
658      this->bLoop_ = b;
659      this->bTakenOver_ = true;
660    }
661    void ActionpointController::setClosestTarget()
662    {
663        this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) ); 
664    }
665    Pawn* ActionpointController::closestTarget()
666    {
667        if (!this->getControllableEntity())
668            return 0;
669
670        Pawn* closestTarget = 0;
671        float minDistance =  std::numeric_limits<float>::infinity();
672        Gametype* gt = this->getGametype();
673        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
674        {
675            if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
676                continue;
677
678            float distance = CommonController::distance (*itP, this->getControllableEntity());
679            if (distance < minDistance)
680            {
681                closestTarget = *itP;
682                minDistance = distance;
683            }
684        }
685        if (closestTarget)
686        {
687           return closestTarget;
688        } 
689        return 0; 
690    }
691    void ActionpointController::startAttackingEnemiesThatAreClose()
692    {
693        //if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
694        {
695            if (!this->target_ || (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_))
696            {
697                Pawn* newTarget = this->closestTarget();
698                if ( newTarget && 
699                    CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
700                        <= this->attackRange_ )
701                {
702                    this->setTarget(newTarget);
703                    if (this->bLoop_ && !this->bPatrolling_)
704                    {
705                        Point p = { Action::FIGHT, "", Vector3::ZERO, true };
706                        this->loopActionpoints_.push_back(p);
707                    }
708                    else if (!this->bPatrolling_)
709                    {
710                        //orxout (internal_error) << "found new target " << CommonController::getName(newTarget) <<endl;
711                        Point p = { Action::FIGHT, "", Vector3::ZERO, false };
712                        this->parsedActionpoints_.push_back(p);
713                    }
714                    this->bPatrolling_ = true;
715                    this->executeActionpoint();
716                }
717            }
718        }
719    }
720    Vector3 ActionpointController::bestHealthPickup(float searchRadius)
721    {
722
723        //1000000/distance^2 * 1/index+1
724        float maxUse = 0;
725        float tempUse = -1;
726        int index = 0;
727        float distance = 0;
728        Vector3 bestPosition = this->getControllableEntity()->getWorldPosition();
729
730        for (std::multimap<int, std::pair<PickupSpawner*, bool> >::iterator it=healthSpawners_.begin(); it!=healthSpawners_.end(); ++it)
731        {
732            distance = (this->getControllableEntity()->getWorldPosition() - (*it).second.first->getWorldPosition()).length();
733            if (distance < this->tolerance_ || !(*it).second.second)
734            {
735                (*it).second.second = false;
736                continue;
737            }
738            if (distance > searchRadius)
739                continue;
740            index = (*it).first;
741            tempUse = 1000000*1/(1+distance*distance) * 1/((index/2.0f)+1);
742            if (tempUse > maxUse)
743            {
744                bestPosition = (*it).second.first->getWorldPosition();
745                maxUse = tempUse;
746            }
747        }
748        //std::multimap<int, std::pair<PickupSpawner*, bool> >::iterator it = this->healthSpawners_.find(index);
749        //P.S. check if it == ... .end()
750        //orxout (internal_error) << "best position = " << bestPosition << endl;
751        return  bestPosition;
752    }
753    void ActionpointController::setSpawners()
754    {
755        std::vector<std::string> damagePickups;
756        std::vector<std::string> healthPickups;
757        std::vector<std::string> speedPickups;       
758        int index = 0;
759
760
761        damagePickups.push_back("largedamageboostpickup");
762        damagePickups.push_back("dronepickup");           
763        damagePickups.push_back("mediumdamageboostpickup");
764        damagePickups.push_back("smalldamageboostpickup");
765
766        healthPickups.push_back("triplehealthspeedinvisibilitypickup");           
767        healthPickups.push_back("crazyhealthpickup");
768        healthPickups.push_back("hugehealthpickup");
769        healthPickups.push_back("hugeshieldpickup");
770        healthPickups.push_back("hugeinvisiblepickup");
771        healthPickups.push_back("hugeshrinkpickup");
772        healthPickups.push_back("mediumhealthpickup");
773        healthPickups.push_back("mediumshieldpickup");
774        healthPickups.push_back("mediuminvisiblepickup");
775        healthPickups.push_back("mediumshrinkpickup"); 
776        healthPickups.push_back("smallhealthpickup");                   
777        healthPickups.push_back("smallshieldpickup");
778        healthPickups.push_back("smallinvisiblepickup");
779        healthPickups.push_back("smallshrinkpickup");
780
781        speedPickups.push_back("triplehealthspeedinvisibilitypickup");
782        speedPickups.push_back("hugespeedpickup");
783        speedPickups.push_back("smalljumppickup");
784        speedPickups.push_back("mediumspeedpickup");
785        speedPickups.push_back("smallspeedpickup");
786       
787
788
789        for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it; ++it)
790        {
791            if ((*it)->getIdentifier()->getName() != "PickupSpawner")
792                continue;
793            PickupSpawner* spawner = static_cast<PickupSpawner*>(*it);
794            std::string name = spawner->getPickupTemplateName();
795            //float distance = ((*it)->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length();
796            // if (distance < 50.0f)
797            //     continue;           
798            for (unsigned int i = 0; i < healthPickups.size(); ++i)
799            {
800                if (name == healthPickups.at(i))
801                {
802                    index = i;
803                    this->healthSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true)));
804                    break;
805                }
806            }
807            for (unsigned int i = 0; i < damagePickups.size(); ++i)
808            {
809                if (name == damagePickups.at(i))
810                {
811                    //tempUse = 1000000*1/(1+distance*distance) * 1/((i/2.0f)+1);
812                    index = i;
813                    this->damageSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true)));
814                    break;
815                }
816            }
817            for (unsigned int i = 0; i < speedPickups.size(); ++i)
818            {
819                if (name == speedPickups.at(i))
820                {
821                    //tempUse = 1000000*1/(1+distance*distance) * 1/((i/2.0f)+1);
822                    index = i;
823                    this->speedSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true)));
824                    break;
825                }
826            }
827            // if (tempUse > maxUse)
828            // {
829            //     Point p = { Action::FLY, "", (*it)->getWorldPosition(), false };
830            //     maxUse = tempUse;
831            //     maxPoint = p;
832            // }
833            // else
834            // {
835            //     tempUse = -1;
836            //     continue;
837            // }
838            // orxout(internal_error) << "resp time  = " << static_cast<PickupSpawner*>(*it)->getRespawnTime() << endl;
839        } 
840    }
841}
Note: See TracBrowser for help on using the repository browser.