]> ruin.nu Git - hbs.git/blob - bs/fleet.cpp
some
[hbs.git] / bs / fleet.cpp
1 /***************************************************************************
2   fleet.cpp  -  description
3   -------------------
4 begin                : Tue Jan 22 2002
5 copyright            : (C) 2002 by Michael Andreen
6 email                : whale@linux.nu
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include "fleet.h"
19
20 #include <iostream>
21 #include <cstdlib>
22 using namespace std;
23
24 //Static variables
25 map<string, vector<int> > Fleet::s_Races;
26 UnitList Fleet::s_Units;
27
28 Fleet::Fleet()
29 {
30         m_iETA = 0;
31         m_iStays = 3;
32         m_sRace = "Cathaar";
33 }
34
35 Fleet::~Fleet(){
36 }
37
38 //////////////////////////////////////////////////////////////////////////
39 //
40 void Fleet::setName(string sName)
41 {
42         m_sName = sName;
43 }
44
45 //////////////////////////////////////////////////////////////////////////
46 //
47 string Fleet::name() const
48 {
49         return m_sName;
50 }
51
52 //////////////////////////////////////////////////////////////////////////
53 //
54 /** This function first sets the race, then it iterates through the the 
55  * s_Races and checks if it finds the race it returns true, if it reaches
56  * the end without finding it it returns false.
57  */
58 bool Fleet::setRace(string sRace)
59 {
60         m_sRace = sRace;
61         for (map<string, vector<int> >::iterator i = s_Races.begin(); i != s_Races.end(); i++)
62         {
63                 if (m_sRace == (*i).first)
64                         return true;
65         }
66         return false;
67 }
68
69 //////////////////////////////////////////////////////////////////////////
70 //
71 string Fleet::race() const
72 {
73         return m_sRace;
74 }
75
76 //////////////////////////////////////////////////////////////////////////
77 //
78 /** This function iterates through m_Fleet and adds all numbers together to
79  * produce a total.
80  */
81 int Fleet::numberOfShips() const
82 {
83         int total = 0;
84
85         for (map<string, vector<int> >::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
86         {
87                 if (i->second.size() != 0)
88                         total += i->second[0];
89         }
90
91         return total;
92 }
93
94 //////////////////////////////////////////////////////////////////////////
95 //
96 void Fleet::setETA(int eta)
97 {
98         m_iETA = eta;
99 }
100
101 //////////////////////////////////////////////////////////////////////////
102 //
103 int  Fleet::ETA() const
104 {
105         return m_iETA;
106 }
107
108 //////////////////////////////////////////////////////////////////////////
109 //
110 void Fleet::setRaces(map<string, vector<int> >& races)
111 {
112         s_Races = races;
113 }
114
115 //////////////////////////////////////////////////////////////////////////
116 //
117 void Fleet::setUnits(UnitList& units)
118 {
119         s_Units = units;
120
121
122 /*      
123            for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); i++)
124            {
125                    cerr << s_Units[(*i).first].Name() << "\t\t"
126                    << s_Units[(*i).first].race() <<"\t"
127                    << s_Units[(*i).first].unitClass() << "\t"
128                    << s_Units[(*i).first].target(0) << "\t"
129                    << s_Units[(*i).first].target(1) << "\t"
130                    << s_Units[(*i).first].target(2) << "\t"
131                    << s_Units[(*i).first].initiative() << "\t"
132                    << s_Units[(*i).first].agility() << "\t"
133                    << s_Units[(*i).first].weaponSpeed() << "\t"
134                    << s_Units[(*i).first].guns() << "\t"
135                    << s_Units[(*i).first].power() << "\t"
136                    << s_Units[(*i).first].armor() << "\t"
137                    << s_Units[(*i).first].EMP() << "\t"
138                    << s_Units[(*i).first].totRes() << "\t"
139                    << s_Units[(*i).first].fuel() << "\t"
140                    << s_Units[(*i).first].ETA() << "\t"
141                    << s_Units[(*i).first].type() << endl;
142            }
143            */
144 }
145
146 //////////////////////////////////////////////////////////////////////////
147 //
148 const map<string, vector<int> >& Fleet::Races()
149 {
150         return s_Races;
151 }
152
153 //////////////////////////////////////////////////////////////////////////
154 //
155 const UnitList& Fleet::Units()
156 {
157         return s_Units;
158 }
159
160 //////////////////////////////////////////////////////////////////////////
161 //
162 vector<int> Fleet::RacesAllowed() const
163 {
164         return s_Races[m_sRace];
165 }
166
167 //////////////////////////////////////////////////////////////////////////
168 //
169 unsigned Fleet::score(int tick) const
170 {
171         unsigned tot_score = 0;
172
173         for (FleetList::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
174         {
175                 int ticks =     i->second.size();
176                 if (ticks == 0)
177                         continue;
178                 --ticks;
179                 if ( ticks < tick)
180                         tot_score += i->second[ticks] * s_Units[i->first].totRes() / 10;
181                 else
182                         tot_score += i->second[tick] * s_Units[i->first].totRes() / 10;
183         }
184
185         return tot_score;
186 }
187
188 //////////////////////////////////////////////////////////////////////////
189 //
190 void Fleet::setFleet(string unittype, int number, int tick)
191 {
192         int earlier = 0;
193         int ticks = m_Fleet[unittype].size();
194
195         if (ticks != 0)
196                 earlier = m_Fleet[unittype][ticks - 1];
197
198         for (int i = ticks; i <= tick; ++i)
199         {
200                 m_Fleet[unittype].push_back(earlier);
201         }
202         m_Fleet[unittype][tick] = number;
203 }
204
205 //////////////////////////////////////////////////////////////////////////
206 //
207 void Fleet::addFleet(std::string unittype, int number, int tick)
208 {
209         int earlier = 0;
210         int ticks = m_Fleet[unittype].size();
211
212         if (ticks != 0)
213                 earlier = m_Fleet[unittype][ticks - 1];
214
215         for (int i = ticks; i <= tick; ++i)
216         {
217                 m_Fleet[unittype].push_back(earlier);
218         }
219         m_Fleet[unittype][tick] += number;
220 }
221
222 //////////////////////////////////////////////////////////////////////////
223 //
224 int      Fleet::fleet(string unittype, int tick)
225 {
226
227         int ticks = m_Fleet[unittype].size();
228         if (ticks == 0)
229                 return 0;
230
231         if (tick < 0)
232                 return m_Fleet[unittype][0];
233
234         --ticks;
235
236         if (ticks < tick)
237                 return m_Fleet[unittype][ticks];
238
239         return m_Fleet[unittype][tick];
240 }
241
242 //////////////////////////////////////////////////////////////////////////
243 //
244 int Fleet::blockedFleet(std::string unittype, int tick)
245 {
246         int ticks = m_BlockedFleet[unittype].size();
247         if (ticks == 0)
248                 return 0;
249
250         --ticks;
251
252         if (ticks < tick)
253                 return 0;
254
255         return m_BlockedFleet[unittype][tick];
256 }
257
258 //////////////////////////////////////////////////////////////////////////
259 //
260 void Fleet::setBlockedFleet(std::string unittype, int number, int tick)
261 {
262         int ticks = m_BlockedFleet[unittype].size();
263
264         for (int i = ticks; i <= tick; ++i)
265         {
266                 m_BlockedFleet[unittype].push_back(0);
267         }
268         m_BlockedFleet[unittype][tick] = number;
269
270         cerr << "This fleet got " << m_BlockedFleet[unittype][tick] << " blocked units tick: " << tick << endl;
271
272 }
273
274 //////////////////////////////////////////////////////////////////////////
275 //
276 void Fleet::addToThis(std::vector<Fleet*> fleets, int tick)
277 {
278         for (UnitList::iterator i = s_Units.begin();  i != s_Units.end(); ++i)
279         {
280                 if (m_Fleet[i->first].size() == 0)
281                         m_Fleet[i->first].push_back(0);
282
283                 for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
284                 {
285                         int num = (*j)->fleet(i->first, tick);
286                         m_Fleet[i->first][0] += num;
287                         if (num > 0)
288                                 cerr << (*j)->name() <<  " adding " << num << " units of type " << i->first << endl;
289                 }
290         }
291 }
292
293 //////////////////////////////////////////////////////////////////////////
294 //
295 void Fleet::distributeLossesGains(std::vector<Fleet*> fleets, int tick)
296 {
297         for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
298         {
299                 string unittype = i->first;
300
301
302                 if (m_Fleet[unittype].size() < 1)
303                         continue;
304                 if (m_Fleet[unittype][0] == 0)
305                         continue;
306
307
308                 int totallost = fleet(unittype,1) - fleet(unittype, 0);
309
310
311                 cerr << "Distributing type: " << unittype << " with a total loss of " << totallost << " units" << endl;
312
313                 cerr << "Total number of units before: " << fleet(unittype, 0)  << " and after : " << fleet(unittype, 1) << endl;
314
315                 for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
316                 {
317                         int fl1 = (*j)->fleet(unittype, tick - 1);
318                         float part = float(fl1) / fleet(unittype, 0) ;
319                         int lost =  int(totallost * part);
320                         (*j)->setFleet(unittype, (*j)->fleet(unittype, tick - 1) + lost, tick);
321
322                         cerr << (*j)->name() << " gaining " << lost << " " << unittype  << " since it's " << part * 100 << "% of the whole fleet, and it had : " << fl1 << " units last tick.." <<  endl;
323
324                         lost = int(part * blockedFleet(unittype, 0));
325
326                         cerr << (*j)->name() << " got " << lost << " blocked " << unittype  << ", the total number of blocked ships was: " << blockedFleet(unittype, 0) << endl; 
327
328                         (*j)->setBlockedFleet(unittype, lost, tick);
329                 }
330         }
331 }
332
333 //////////////////////////////////////////////////////////////////////////
334 //
335 std::vector<Fleet*> Fleet::calculateSide(std::vector<Fleet*> fleets, int tick)
336 {
337         vector<Fleet*> fl;
338         for (vector<Fleet*>::iterator i = fleets.begin(); i != fleets.end(); ++i)
339         {
340                 if ((*i)->stays() == 0)
341                         continue;
342                 else if (( tick - (*i)->ETA()) >= 0 && (tick - (*i)->ETA()) < (*i)->stays())
343                 {
344                         fl.push_back((*i));
345                         cerr << "Using fleet " << (*i)->name() << " for tick " << tick << endl;
346                 }
347                 else if ((*i)->stays() < 0)
348                         fl.push_back((*i));
349         }
350         return fl;
351 }
352
353 //////////////////////////////////////////////////////////////////////////
354 //
355 int Fleet::freeFleet(std:: string unittype, int tick)
356 {
357         int bticks = m_BlockedFleet[unittype].size();
358
359         --bticks;
360
361         if (bticks < tick)
362                 return fleet(unittype, tick);
363
364
365         int free = fleet(unittype,tick) - m_BlockedFleet[unittype][tick];
366         if (free < 0)
367                 return 0;
368         return free;
369 }
370
371
372 //////////////////////////////////////////////////////////////////////////
373 //
374 void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits)
375 {
376
377         float guns = s_Units[unittype].guns() * number;
378
379
380         if (guns == 0)
381                 return;
382
383         float gunsleft = guns;
384         for (int count = 0; count < 3; ++count)
385         {
386                 string ta = s_Units[unittype].target(count);
387
388                 while (gunsleft > 0)
389                 {
390                         int total = 0;
391                         map<string, int*> targets = findTargets(ta,total, 0);
392
393                         if (targets.size() == 0)
394                                 break;
395
396                         for (map<string, int*>::iterator j = targets.begin(); j != targets.end(); ++j)
397                         {
398                                 float maxguns = float((*j->second))/total * guns;
399
400                                 if (m_Armor[j->first] <= 0 || m_Armor[j->first] > s_Units[j->first].armor())
401                                         m_Armor[j->first] = s_Units[j->first].armor();
402                                 double k = maxguns;
403
404                                 while (k > 0)   
405                                 {
406
407                                         if (*(j->second) <= 0)
408                                                 break;
409
410                                         int wpsp = s_Units[unittype].weaponSpeed();
411                                         int agil = s_Units[j->first].agility();
412
413                                         k -= float(100)/(25 + wpsp - agil);
414
415                                         m_Armor[j->first] -= s_Units[unittype].power();
416                                         if (m_Armor[j->first] <= 0)
417                                         {
418                                                 m_Armor[j->first] = s_Units[j->first].armor();
419                                                 (*j->second)--;
420                                                 hitunits[j->first]++;
421                                         }
422
423                                 }
424                                 if (k <= 0)
425                                         gunsleft -= maxguns;
426                                 else
427                                         gunsleft -= maxguns - k;
428                         }
429                 }
430         }
431 }
432
433 //////////////////////////////////////////////////////////////////////////
434 //
435 void Fleet::takeEMP(std::string unittype, int number, std::map<std::string, int>& hitunits)
436 {
437         int guns = s_Units[unittype].guns() * number;
438         if (guns == 0)
439                 return;
440
441         float gunsleft = guns;
442         for (int count = 0; count < 3; ++count)
443         {
444                 string ta = s_Units[unittype].target(count);
445
446                 while (gunsleft > 0)
447                 {
448                         int total = 0;
449                         map<string, int*> targets = findTargets(ta, total, 1);
450
451                         if (targets.size() == 0)
452                                 break;
453
454                         for (map<string, int*>::iterator j = targets.begin(); j != targets.end(); ++j)
455                         {
456                                 float maxguns = float((*j->second))/total * gunsleft;
457                                 double k = maxguns;
458                                 int hits = 0;
459
460                                 while (k > 0)   
461                                 {
462
463                                         if (*(j->second) <= blockedFleet(j->first, 1))
464                                                 break;
465
466                                         int eres = s_Units[j->first].EMP();
467
468                                         k -= float(100)/(100-eres);
469                                         hits++;
470                                         hitunits[j->first]++;
471                                         blockFleet(j->first, 1);
472                                 }
473                                 if (k <= 0)
474                                         gunsleft -= maxguns;
475                                 else
476                                         gunsleft -= maxguns - k;
477                         }
478                 }
479         }
480 }
481
482 //////////////////////////////////////////////////////////////////////////
483 //
484 void Fleet::killFleet(std::string unittype, int number, int tick)
485 {
486         int earlier = 0;
487         int ticks = m_Fleet[unittype].size();
488
489         if (ticks != 0)
490                 earlier = m_Fleet[unittype][ticks - 1];
491
492         for (int i = ticks; i <= tick; ++i)
493         {
494                 m_Fleet[unittype].push_back(earlier);
495         }
496         m_Fleet[unittype][tick] -= number;
497 }
498
499 //////////////////////////////////////////////////////////////////////////
500 //
501 void Fleet::setResource(std::string type, int number, int tick)
502 {
503
504         int ticks = m_Resources[type].size();
505         for (int i = ticks; i <= tick; ++i)
506                 m_Resources[type].push_back(number);
507         m_Resources[type][tick] = number;
508 }
509
510 //////////////////////////////////////////////////////////////////////////
511 //
512 void Fleet::addResource(std::string type, int number, int tick)
513 {
514
515         int ticks = m_Resources[type].size();
516         int latest = resource(type, tick - 1);
517
518         for (int i = ticks; i <= tick; ++i)
519                 m_Resources[type].push_back(latest);
520         m_Resources[type][tick] += number;
521 }
522
523 //////////////////////////////////////////////////////////////////////////
524 //
525 int Fleet::resource(std::string type, int tick) const
526 {
527         if (tick < 0)
528                 return 0;
529
530         vector<int>const* resource = 0;
531         for (ResourceList::const_iterator i = m_Resources.begin(); i != m_Resources.end(); ++i)
532         {
533                 if (i->first == type)
534                 {
535                         resource = &i->second;
536                         break;
537                 }
538         }
539         if (resource == 0)
540                 return 0;
541
542         int ticks = resource->size();
543
544         if( ticks == 0)
545                 return 0;
546
547         --ticks;
548
549         if (ticks < tick)
550                 return resource->at(ticks);
551         return resource->at(tick);
552 }
553
554 //////////////////////////////////////////////////////////////////////////
555 //
556 void Fleet::resetResources()
557 {
558         m_Resources.clear() ;   
559 }
560
561 //////////////////////////////////////////////////////////////////////////
562 //
563 void Fleet::printFleet()
564 {
565         for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
566         {
567                 for (int tick = 0; tick < 5 ;++tick)
568                 {
569                         int num = fleet(i->first, tick);
570
571                         if (num <= 0)
572                                 break;
573                         cerr << num << " " << i->first << " during tick: " << tick << endl;
574                 }
575         }
576 }
577
578 //////////////////////////////////////////////////////////////////////////
579 //
580 void Fleet::blockFleet(std::string unittype, int number, int tick)
581 {
582         if (m_BlockedFleet[unittype].size() >= 1)
583         {
584                 m_BlockedFleet[unittype][0] += number;
585                 if (m_BlockedFleet[unittype].size() > 1)
586                         m_BlockedFleet[unittype][1] += number;
587                 else
588                         m_BlockedFleet[unittype].push_back(m_BlockedFleet[unittype][0]);
589         }
590         else
591         {
592                 m_BlockedFleet[unittype].push_back(number);
593                 m_BlockedFleet[unittype].push_back(number);
594         }
595 }
596
597 //////////////////////////////////////////////////////////////////////////
598 //
599 void Fleet::distributeCappedRoids(std::vector<Fleet*> fleets, int tick)
600 {
601         for (ResourceList::iterator i = m_Resources.begin(); i != m_Resources.end(); ++i)
602         {
603                 string res = i->first;
604
605
606                 cerr << "Distributing type: " << res << endl;
607                 for (vector<int>::iterator j = i->second.begin(); j != i->second.end(); ++j)
608                         cout << (*j) << endl;
609
610                 if (m_Resources[res].size() < 2)
611                         continue;
612                 if (m_Resources[res][1] == 0)
613                         continue;
614
615
616                 int totcapped = resource(res,1) - resource(res, 0);
617
618
619                 cerr << "Distributing type: " << res << " with a total gain of " << totcapped << " roids" << endl;
620
621                 cerr << "Total number of roids before: " << resource(res, 0)  << " and after : " << resource(res, 1) << endl;
622
623                 for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
624                 {
625                         unsigned fl1 = (*j)->score(tick - 1);
626                         float part = float(fl1) / score(0) ;
627                         int lost =  int(totcapped * part);
628
629                         cerr << (*j)->name() << " gaining " << lost << " " << res  << " since it's " << part * 100 << "% of the whole score, and it had : " << fl1 << " score last tick.. compared to fleet total of: " << score(0) <<  endl;
630
631                         //(*j)->setResource(res, (*j)->resource(res,tick-1) + lost, tick);
632                         (*j)->addResource(res,lost, tick);
633                 }
634         }
635 }
636
637 //////////////////////////////////////////////////////////////////////////
638 //
639 void Fleet::addFleet(std::map<string, int> units, int tick)
640 {
641         for (map<string, int>::iterator i = units.begin(); i != units.end(); ++i)
642                 addFleet(i->first, i->second, tick);
643 }
644
645 //////////////////////////////////////////////////////////////////////////
646 //
647 int Fleet::stays() const
648 {
649         return m_iStays;
650 }
651
652 //////////////////////////////////////////////////////////////////////////
653 //
654 void Fleet::setStays(int ticks)
655 {
656         m_iStays = ticks;
657 }
658
659 //////////////////////////////////////////////////////////////////////////
660 //
661 void Fleet::calculateLostStealships(string unittype, std::map<std::string, int> stolen, int tick)
662 {
663         int stealscore = 0;
664         for (map<string, int>::iterator i = stolen.begin(); i != stolen.end(); ++i)
665         {
666                 stealscore += int(stolen[i->first] * (s_Units[i->first].totRes() / 10.0));      
667         }
668
669         int lost = int(stealscore / (s_Units[unittype].totRes() / 10.0));
670
671         cerr << "Lost " << lost << " " << unittype << " due to stealing ships worth: " << stealscore << endl; 
672         killFleet(unittype, lost, tick);
673 }
674
675 //////////////////////////////////////////////////////////////////////////
676 //
677 void Fleet::distributeStolenShips(std::map<std::string, std::map<std::string, int> > stolen, std::vector<Fleet*> fleets, int tick)
678 {
679         for(map<string, map<string, int> >::iterator i = stolen.begin(); i != stolen.end(); ++i)
680         {
681                 int totalstealers = 0;
682                 for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
683                         totalstealers += (*j)->fleet(i->first, tick - 1);
684
685                 for (map<string, int>::iterator j = i->second.begin(); j != i->second.end(); ++j)
686                 {
687                         for (vector<Fleet*>::iterator k = fleets.begin(); k != fleets.end(); ++k)
688                         {
689                                 int stolen = int(float ((*k)->fleet(i->first, tick - 1)) / totalstealers * j->second);
690                                 (*k)->addFleet(j->first, stolen, tick);
691                         }
692                 }
693         }
694 }
695
696 //////////////////////////////////////////////////////////////////////////
697 //
698 void Fleet::calculateSalvage()
699 {
700         for (FleetList::iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
701         {
702
703                 map<string, int> res = s_Units[i->first].resources();
704
705                 if (i->second.size() > 0)
706                         cerr << endl << i->first << ": ";
707
708                 int tick = 0;
709                 for (vector<int>::iterator j = i->second.begin(); j != i->second.end(); ++j, ++tick)
710                 {
711                         int lostunits = fleet(i->first, tick - 1) - fleet(i->first, tick);
712
713                         if (lostunits <= 0)
714                                 continue;
715                         cerr << "(" << tick << ":" << fleet(i->first, tick) << ") ";
716                         for (map<string, int>::iterator k = res.begin(); k != res.end(); ++k)
717                                 addResource(k->first, int(lostunits * k->second * 0.25), tick);
718                 }
719         }
720 }
721
722 //////////////////////////////////////////////////////////////////////////
723 //
724 void Fleet::resetTicks()
725 {
726         for (FleetList::iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
727         {
728                 if ( i->second.size() < 2)
729                         continue;
730
731                 int temp = i->second[0];
732                 i->second.clear();
733
734                 if (temp > 0)
735                         i->second.push_back(temp);
736         }
737         resetResources();
738 }
739
740 //////////////////////////////////////////////////////////////////////////
741 //
742 int Fleet::freePodGuns(int tick) 
743 {
744         int guns = 0;
745         for (FleetList::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
746         {
747                 if (s_Units[i->first].type() == "Pod")
748                 {
749                         guns += freeFleet(i->first, tick) * s_Units[i->first].guns();
750                 }
751         }
752         guns -= usedPodGuns(tick);
753         return guns;
754 }
755
756 //////////////////////////////////////////////////////////////////////////
757 //
758 int Fleet::usedPodGuns(int tick) const
759 {
760         int ticks = m_UsedPodGuns.size();
761
762         if (ticks == 0)
763                 return 0;
764
765         if (tick < 0)
766                 return m_UsedPodGuns[0];
767
768         --ticks;
769
770         if (ticks < tick)
771                 return m_UsedPodGuns[ticks];
772
773         return m_UsedPodGuns[tick];
774
775 }
776
777 //////////////////////////////////////////////////////////////////////////
778 //
779 void Fleet::usePodGuns(int tick, int guns)
780 {
781         int ticks = m_UsedPodGuns.size();
782
783         for (int i = ticks; i <= tick; ++i)
784         {
785                 m_UsedPodGuns.push_back(0);
786         }
787         m_UsedPodGuns[tick] += guns;
788 }
789
790 //////////////////////////////////////////////////////////////////////////
791 //
792 std::map<std::string, int*> Fleet::findTargets(std::string targetClass,int& total, int attackerType)
793 {
794         map<string, int*> targets;
795
796         for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
797         {
798                 if (m_Fleet[i->first].size() == 0)
799                         continue;
800
801                 if (m_Fleet[i->first].size() == 1 )
802                         m_Fleet[i->first].push_back(m_Fleet[i->first][0]);
803
804                 if (m_Fleet[i->first][1] > 0  && ( targetClass == i->second.unitClass() || targetClass == "All"))
805                 {
806                         if (i->second.unitClass() == "PDS" && attackerType == 1)
807                                 continue;
808                         targets[i->first] = &m_Fleet[i->first][1];
809                         total += m_Fleet[i->first][1];
810                 }
811         }
812         return targets;
813 }