CCreatureSet.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. #define VCMI_DLL
  2. #include "CCreatureSet.h"
  3. #include "CCreatureHandler.h"
  4. #include "VCMI_Lib.h"
  5. #include <assert.h>
  6. #include "CObjectHandler.h"
  7. #include "IGameCallback.h"
  8. #include "CGameState.h"
  9. #include "CGeneralTextHandler.h"
  10. #include <sstream>
  11. #include "CSpellHandler.h"
  12. #include <boost/lexical_cast.hpp>
  13. #include <boost/algorithm/string/replace.hpp>
  14. const CStackInstance &CCreatureSet::operator[](TSlot slot) const
  15. {
  16. TSlots::const_iterator i = stacks.find(slot);
  17. if (i != stacks.end())
  18. return *i->second;
  19. else
  20. throw std::string("That slot is empty!");
  21. }
  22. const CCreature* CCreatureSet::getCreature(TSlot slot) const
  23. {
  24. TSlots::const_iterator i = stacks.find(slot);
  25. if (i != stacks.end())
  26. return i->second->type;
  27. else
  28. return NULL;
  29. }
  30. bool CCreatureSet::setCreature(TSlot slot, TCreature type, TQuantity quantity) /*slots 0 to 6 */
  31. {
  32. if(slot > 6 || slot < 0)
  33. {
  34. tlog1 << "Cannot set slot " << slot << std::endl;
  35. return false;
  36. }
  37. if(!quantity)
  38. {
  39. tlog2 << "Using set creature to delete stack?\n";
  40. eraseStack(slot);
  41. return true;
  42. }
  43. if(hasStackAtSlot(slot)) //remove old creature
  44. eraseStack(slot);
  45. putStack(slot, new CStackInstance(type, quantity));
  46. return true;
  47. }
  48. TSlot CCreatureSet::getSlotFor(TCreature creature, ui32 slotsAmount/*=7*/) const /*returns -1 if no slot available */
  49. {
  50. return getSlotFor(VLC->creh->creatures[creature], slotsAmount);
  51. }
  52. TSlot CCreatureSet::getSlotFor(const CCreature *c, ui32 slotsAmount/*=ARMY_SIZE*/) const
  53. {
  54. assert(c->valid());
  55. for(TSlots::const_iterator i=stacks.begin(); i!=stacks.end(); ++i)
  56. {
  57. assert(i->second->type->valid());
  58. if(i->second->type == c)
  59. {
  60. return i->first; //if there is already such creature we return its slot id
  61. }
  62. }
  63. for(ui32 i=0; i<slotsAmount; i++)
  64. {
  65. if(stacks.find(i) == stacks.end())
  66. {
  67. return i; //return first free slot
  68. }
  69. }
  70. return -1; //no slot available
  71. }
  72. int CCreatureSet::getStackCount(TSlot slot) const
  73. {
  74. TSlots::const_iterator i = stacks.find(slot);
  75. if (i != stacks.end())
  76. return i->second->count;
  77. else
  78. return 0; //TODO? consider issuing a warning
  79. }
  80. bool CCreatureSet::mergableStacks(std::pair<TSlot, TSlot> &out, TSlot preferable /*= -1*/) const /*looks for two same stacks, returns slot positions */
  81. {
  82. //try to match creature to our preferred stack
  83. if(preferable >= 0 && vstd::contains(stacks, preferable))
  84. {
  85. const CCreature *cr = stacks.find(preferable)->second->type;
  86. for(TSlots::const_iterator j=stacks.begin(); j!=stacks.end(); ++j)
  87. {
  88. if(cr == j->second->type && j->first != preferable)
  89. {
  90. out.first = preferable;
  91. out.second = j->first;
  92. return true;
  93. }
  94. }
  95. }
  96. for(TSlots::const_iterator i=stacks.begin(); i!=stacks.end(); ++i)
  97. {
  98. for(TSlots::const_iterator j=stacks.begin(); j!=stacks.end(); ++j)
  99. {
  100. if(i->second->type == j->second->type && i->first != j->first)
  101. {
  102. out.first = i->first;
  103. out.second = j->first;
  104. return true;
  105. }
  106. }
  107. }
  108. return false;
  109. }
  110. void CCreatureSet::sweep()
  111. {
  112. for(TSlots::iterator i=stacks.begin(); i!=stacks.end(); ++i)
  113. {
  114. if(!i->second->count)
  115. {
  116. stacks.erase(i);
  117. sweep();
  118. break;
  119. }
  120. }
  121. }
  122. void CCreatureSet::addToSlot(TSlot slot, TCreature cre, TQuantity count, bool allowMerging/* = true*/)
  123. {
  124. const CCreature *c = VLC->creh->creatures[cre];
  125. if(!hasStackAtSlot(slot))
  126. {
  127. setCreature(slot, cre, count);
  128. }
  129. else if(getCreature(slot) == c && allowMerging) //that slot was empty or contained same type creature
  130. {
  131. setStackCount(slot, getStackCount(slot) + count);
  132. }
  133. else
  134. {
  135. tlog1 << "Failed adding to slot!\n";
  136. }
  137. }
  138. void CCreatureSet::addToSlot(TSlot slot, CStackInstance *stack, bool allowMerging/* = true*/)
  139. {
  140. assert(stack->valid(true));
  141. if(!hasStackAtSlot(slot))
  142. {
  143. putStack(slot, stack);
  144. }
  145. else if(allowMerging && stack->type == getCreature(slot))
  146. {
  147. joinStack(slot, stack);
  148. }
  149. else
  150. {
  151. tlog1 << "Cannot add to slot " << slot << " stack " << *stack << std::endl;
  152. }
  153. }
  154. bool CCreatureSet::validTypes(bool allowUnrandomized /*= false*/) const
  155. {
  156. for(TSlots::const_iterator i=stacks.begin(); i!=stacks.end(); ++i)
  157. {
  158. if(!i->second->valid(allowUnrandomized))
  159. return false;
  160. }
  161. return true;
  162. }
  163. bool CCreatureSet::slotEmpty(TSlot slot) const
  164. {
  165. return !hasStackAtSlot(slot);
  166. }
  167. bool CCreatureSet::needsLastStack() const
  168. {
  169. return false;
  170. }
  171. int CCreatureSet::getArmyStrength() const
  172. {
  173. int ret = 0;
  174. for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); i++)
  175. ret += i->second->type->AIValue * i->second->count;
  176. return ret;
  177. }
  178. ui64 CCreatureSet::getPower (TSlot slot) const
  179. {
  180. return getCreature(slot)->AIValue * getStackCount(slot);
  181. }
  182. std::string CCreatureSet::getRoughAmount (TSlot slot) const
  183. {
  184. return VLC->generaltexth->arraytxt[174 + 3*CCreature::getQuantityID(getStackCount(slot))];
  185. }
  186. int CCreatureSet::stacksCount() const
  187. {
  188. return stacks.size();
  189. }
  190. void CCreatureSet::setFormation(bool tight)
  191. {
  192. formation = tight;
  193. }
  194. void CCreatureSet::setStackCount(TSlot slot, TQuantity count)
  195. {
  196. assert(hasStackAtSlot(slot));
  197. assert(count > 0);
  198. if (STACK_EXP)
  199. stacks[slot]->experience *= ((stacks[slot]->count + count)/(float)stacks[slot]->count);
  200. stacks[slot]->count = count;
  201. armyChanged();
  202. }
  203. void CCreatureSet::giveStackExp(expType exp)
  204. {
  205. for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); i++)
  206. i->second->giveStackExp(exp);
  207. }
  208. void CCreatureSet::clear()
  209. {
  210. while(!stacks.empty())
  211. {
  212. eraseStack(stacks.begin()->first);
  213. }
  214. }
  215. const CStackInstance& CCreatureSet::getStack(TSlot slot) const
  216. {
  217. assert(hasStackAtSlot(slot));
  218. return *stacks.find(slot)->second;
  219. }
  220. void CCreatureSet::eraseStack(TSlot slot)
  221. {
  222. assert(hasStackAtSlot(slot));
  223. CStackInstance *toErase = detachStack(slot);
  224. delNull(toErase);
  225. }
  226. bool CCreatureSet::contains(const CStackInstance *stack) const
  227. {
  228. if(!stack)
  229. return false;
  230. for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); ++i)
  231. if(i->second == stack)
  232. return true;
  233. return false;
  234. }
  235. TSlot CCreatureSet::findStack(const CStackInstance *stack) const
  236. {
  237. if(!stack)
  238. return -1;
  239. for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); ++i)
  240. if(i->second == stack)
  241. return i->first;
  242. return -1;
  243. }
  244. CArmedInstance * CCreatureSet::castToArmyObj()
  245. {
  246. return dynamic_cast<CArmedInstance *>(this);
  247. }
  248. void CCreatureSet::putStack(TSlot slot, CStackInstance *stack)
  249. {
  250. assert(!hasStackAtSlot(slot));
  251. stacks[slot] = stack;
  252. stack->setArmyObj(castToArmyObj());
  253. armyChanged();
  254. }
  255. void CCreatureSet::joinStack(TSlot slot, CStackInstance * stack)
  256. {
  257. const CCreature *c = getCreature(slot);
  258. assert(c == stack->type);
  259. assert(c);
  260. //TODO move stuff
  261. changeStackCount(slot, stack->count);
  262. delNull(stack);
  263. }
  264. void CCreatureSet::changeStackCount(TSlot slot, TQuantity toAdd)
  265. {
  266. setStackCount(slot, getStackCount(slot) + toAdd);
  267. }
  268. CCreatureSet::CCreatureSet()
  269. {
  270. formation = false;
  271. }
  272. CCreatureSet::CCreatureSet(const CCreatureSet&)
  273. {
  274. assert(0);
  275. }
  276. CCreatureSet::~CCreatureSet()
  277. {
  278. clear();
  279. }
  280. void CCreatureSet::setToArmy(CSimpleArmy &src)
  281. {
  282. clear();
  283. while(src)
  284. {
  285. TSimpleSlots::iterator i = src.army.begin();
  286. assert(i->second.type);
  287. assert(i->second.count);
  288. putStack(i->first, new CStackInstance(i->second.type, i->second.count));
  289. src.army.erase(i);
  290. }
  291. }
  292. CStackInstance * CCreatureSet::detachStack(TSlot slot)
  293. {
  294. assert(hasStackAtSlot(slot));
  295. CStackInstance *ret = stacks[slot];
  296. //if(CArmedInstance *armedObj = castToArmyObj())
  297. {
  298. ret->setArmyObj(NULL); //detaches from current armyobj
  299. }
  300. assert(!ret->armyObj); //we failed detaching?
  301. stacks.erase(slot);
  302. armyChanged();
  303. return ret;
  304. }
  305. void CCreatureSet::setStackType(TSlot slot, const CCreature *type)
  306. {
  307. assert(hasStackAtSlot(slot));
  308. CStackInstance *s = stacks[slot];
  309. s->setType(type->idNumber);
  310. armyChanged();
  311. }
  312. bool CCreatureSet::canBeMergedWith(const CCreatureSet &cs, bool allowMergingStacks) const
  313. {
  314. if(!allowMergingStacks)
  315. {
  316. int freeSlots = stacksCount() - ARMY_SIZE;
  317. std::set<const CCreature*> cresToAdd;
  318. for(TSlots::const_iterator i = cs.stacks.begin(); i != cs.stacks.end(); i++)
  319. {
  320. TSlot dest = getSlotFor(i->second->type);
  321. if(dest < 0 || hasStackAtSlot(dest))
  322. cresToAdd.insert(i->second->type);
  323. }
  324. return cresToAdd.size() <= freeSlots;
  325. }
  326. else
  327. {
  328. CCreatureSet cres;
  329. //get types of creatures that need their own slot
  330. for(TSlots::const_iterator i = cs.stacks.begin(); i != cs.stacks.end(); i++)
  331. cres.addToSlot(i->first, i->second->type->idNumber, 1, true);
  332. TSlot j;
  333. for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); i++)
  334. {
  335. if ((j = cres.getSlotFor(i->second->type)) >= 0)
  336. cres.addToSlot(j, i->second->type->idNumber, 1, true); //merge if possible
  337. else
  338. return false; //no place found
  339. }
  340. return true; //all stacks found their slots
  341. }
  342. }
  343. bool CCreatureSet::hasStackAtSlot(TSlot slot) const
  344. {
  345. return vstd::contains(stacks, slot);
  346. }
  347. CCreatureSet & CCreatureSet::operator=(const CCreatureSet&cs)
  348. {
  349. assert(0);
  350. return *this;
  351. }
  352. void CCreatureSet::armyChanged()
  353. {
  354. }
  355. CStackInstance::CStackInstance()
  356. : armyObj(_armyObj)
  357. {
  358. init();
  359. }
  360. CStackInstance::CStackInstance(TCreature id, TQuantity Count)
  361. : armyObj(_armyObj)
  362. {
  363. init();
  364. setType(id);
  365. count = Count;
  366. }
  367. CStackInstance::CStackInstance(const CCreature *cre, TQuantity Count)
  368. : armyObj(_armyObj)
  369. {
  370. init();
  371. setType(cre);
  372. count = Count;
  373. }
  374. void CStackInstance::init()
  375. {
  376. experience = 0;
  377. count = 0;
  378. type = NULL;
  379. idRand = -1;
  380. _armyObj = NULL;
  381. nodeType = STACK_INSTANCE;
  382. }
  383. int CStackInstance::getQuantityID() const
  384. {
  385. return CCreature::getQuantityID(count);
  386. }
  387. int CStackInstance::getExpRank() const
  388. {
  389. int tier = type->level;
  390. if (iswith(tier, 1, 7))
  391. {
  392. for (int i = VLC->creh->expRanks[tier].size()-2; i >-1; --i)//sic!
  393. { //exp values vary from 1st level to max exp at 11th level
  394. if (experience >= VLC->creh->expRanks[tier][i])
  395. return ++i; //faster, but confusing - 0 index mean 1st level of experience
  396. }
  397. return 0;
  398. }
  399. else //higher tier
  400. {
  401. for (int i = VLC->creh->expRanks[0].size()-2; i >-1; --i)
  402. {
  403. if (experience >= VLC->creh->expRanks[0][i])
  404. return ++i;
  405. }
  406. return 0;
  407. }
  408. }
  409. void CStackInstance::giveStackExp(expType exp)
  410. {
  411. int level = type->level;
  412. if (!iswith(level, 1, 7))
  413. level = 0;
  414. CCreatureHandler * creh = VLC->creh;
  415. ui32 maxExp = creh->expRanks[level].back();
  416. amin(exp, (expType)maxExp); //prevent exp overflow due to different types
  417. amin(exp, (maxExp * creh->maxExpPerBattle[level])/100);
  418. amin(experience += exp, maxExp); //can't get more exp than this limit
  419. }
  420. void CStackInstance::setType(int creID)
  421. {
  422. setType(VLC->creh->creatures[creID]);
  423. }
  424. void CStackInstance::setType(const CCreature *c)
  425. {
  426. if(type)
  427. {
  428. detachFrom(const_cast<CCreature*>(type));
  429. if (type->isMyUpgrade(c) && STACK_EXP)
  430. experience *= VLC->creh->expAfterUpgrade / 100.0f;
  431. }
  432. type = c;
  433. attachTo(const_cast<CCreature*>(type));
  434. }
  435. std::string CStackInstance::bonusToString(Bonus *bonus, bool description) const
  436. {
  437. std::map<TBonusType, std::pair<std::string, std::string> >::iterator it = VLC->creh->stackBonuses.find(bonus->type);
  438. if (it != VLC->creh->stackBonuses.end())
  439. {
  440. std::string text;
  441. if (description) //long ability description
  442. {
  443. text = it->second.second;
  444. switch (bonus->type)
  445. {
  446. //no additional modifiers needed
  447. case Bonus::FLYING:
  448. case Bonus::UNLIMITED_RETALIATIONS:
  449. case Bonus::SHOOTER:
  450. case Bonus::FREE_SHOOTING:
  451. case Bonus::NO_SHOTING_PENALTY:
  452. case Bonus::NO_MELEE_PENALTY:
  453. case Bonus::NO_DISTANCE_PENALTY:
  454. case Bonus::NO_OBSTACLES_PENALTY:
  455. case Bonus::JOUSTING: //TODO: percent bonus?
  456. case Bonus::RETURN_AFTER_STRIKE:
  457. case Bonus::BLOCKS_RETALIATION:
  458. case Bonus::TWO_HEX_ATTACK_BREATH:
  459. case Bonus::THREE_HEADED_ATTACK:
  460. case Bonus::ATTACKS_ALL_ADJACENT:
  461. case Bonus::ADDITIONAL_ATTACK: //TODO: what with more than one attack? Axe of Ferocity for example
  462. case Bonus::FULL_HP_REGENERATION:
  463. case Bonus::LIFE_DRAIN: //TODO: chance, hp percentage?
  464. case Bonus::SELF_MORALE:
  465. case Bonus::SELF_LUCK:
  466. case Bonus::FEAR:
  467. case Bonus::FEARLESS:
  468. case Bonus::CHARGE_IMMUNITY:
  469. case Bonus::HEALER:
  470. case Bonus::CATAPULT:
  471. case Bonus::DRAGON_NATURE:
  472. case Bonus::NON_LIVING:
  473. case Bonus::UNDEAD:
  474. break;
  475. //One numeric value
  476. case Bonus::MAGIC_RESISTANCE:
  477. case Bonus::SPELL_RESISTANCE_AURA:
  478. case Bonus::SPELL_DAMAGE_REDUCTION:
  479. case Bonus::LEVEL_SPELL_IMMUNITY:
  480. case Bonus::MANA_DRAIN:
  481. case Bonus::HP_REGENERATION:
  482. case Bonus::ADDITIONAL_RETALIATION:
  483. case Bonus::DOUBLE_DAMAGE_CHANCE:
  484. case Bonus::DARKNESS: //Darkness Dragons any1?
  485. boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSybtype(bonus->type, bonus->subtype))));
  486. break;
  487. //Complex descriptions
  488. case Bonus::HATE:
  489. boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSybtype(bonus->type, bonus->subtype))));
  490. boost::algorithm::replace_first(text, "%s", VLC->creh->creatures[bonus->subtype]->namePl);
  491. break;
  492. case Bonus::SPELL_AFTER_ATTACK:
  493. boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(bonus->additionalInfo));
  494. boost::algorithm::replace_first(text, "%s", VLC->spellh->spells[bonus->subtype]->name);
  495. break;
  496. default:
  497. {}//TODO: allow custom bonus types... someday, somehow
  498. }
  499. }
  500. else //short name
  501. {
  502. text = it->second.first;
  503. switch (bonus->type)
  504. {
  505. case Bonus::MANA_CHANNELING:
  506. case Bonus::MAGIC_MIRROR:
  507. case Bonus::CHANGES_SPELL_COST_FOR_ALLY:
  508. case Bonus::CHANGES_SPELL_COST_FOR_ENEMY:
  509. case Bonus::ENEMY_DEFENCE_REDUCTION:
  510. boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSybtype(bonus->type, bonus->subtype))));
  511. break;
  512. case Bonus::HATE:
  513. boost::algorithm::replace_first(text, "%s", VLC->creh->creatures[bonus->subtype]->namePl);
  514. break;
  515. case Bonus::LEVEL_SPELL_IMMUNITY:
  516. boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(bonus->val));
  517. break;
  518. case Bonus::SPELL_AFTER_ATTACK:
  519. boost::algorithm::replace_first(text, "%s", VLC->spellh->spells[bonus->subtype]->name);
  520. break;
  521. case Bonus::SPELL_IMMUNITY:
  522. boost::algorithm::replace_first(text, "%s", VLC->spellh->spells[bonus->subtype]->name);
  523. break;
  524. }
  525. }
  526. return text;
  527. }
  528. else
  529. return "";
  530. }
  531. void CStackInstance::setArmyObj(const CArmedInstance *ArmyObj)
  532. {
  533. if(_armyObj)
  534. detachFrom(const_cast<CArmedInstance*>(_armyObj));
  535. _armyObj = ArmyObj;
  536. if(ArmyObj)
  537. {
  538. attachTo(const_cast<CArmedInstance*>(_armyObj));
  539. }
  540. }
  541. // void CStackInstance::getParents(TCNodes &out, const CBonusSystemNode *source /*= NULL*/) const
  542. // {
  543. // out.insert(type);
  544. //
  545. // if(source && source != this) //we should be root, if not - do not inherit anything
  546. // return;
  547. //
  548. // if(armyObj)
  549. // out.insert(armyObj);
  550. // else
  551. // out.insert(&IObjectInterface::cb->gameState()->globalEffects);
  552. // }
  553. std::string CStackInstance::getQuantityTXT(bool capitalized /*= true*/) const
  554. {
  555. return VLC->generaltexth->arraytxt[174 + getQuantityID()*3 + 2 - capitalized];
  556. }
  557. bool CStackInstance::valid(bool allowUnrandomized) const
  558. {
  559. bool isRand = (idRand != -1);
  560. if(!isRand)
  561. {
  562. return (type && type == VLC->creh->creatures[type->idNumber]);
  563. }
  564. else
  565. return allowUnrandomized;
  566. }
  567. CStackInstance::~CStackInstance()
  568. {
  569. }
  570. std::string CStackInstance::nodeName() const
  571. {
  572. std::ostringstream oss;
  573. oss << "Stack of " << count << " of ";
  574. if(type)
  575. oss << type->namePl;
  576. else if(idRand)
  577. oss << "[no type, idRand=" << idRand << "]";
  578. else
  579. oss << "[UNDEFINED TYPE]";
  580. return oss.str();
  581. }
  582. void CStackInstance::deserializationFix()
  583. {
  584. const CCreature *backup = type;
  585. type = NULL;
  586. setType(backup);
  587. const CArmedInstance *armyBackup = _armyObj;
  588. _armyObj = NULL;
  589. setArmyObj(armyBackup);
  590. }
  591. CStackBasicDescriptor::CStackBasicDescriptor()
  592. {
  593. type = NULL;
  594. count = -1;
  595. }
  596. CStackBasicDescriptor::CStackBasicDescriptor(TCreature id, TQuantity Count)
  597. : type (VLC->creh->creatures[id]), count(Count)
  598. {
  599. }
  600. CStackBasicDescriptor::CStackBasicDescriptor(const CCreature *c, TQuantity Count)
  601. : type(c), count(Count)
  602. {
  603. }
  604. DLL_EXPORT std::ostream & operator<<(std::ostream & str, const CStackInstance & sth)
  605. {
  606. if(!sth.valid(true))
  607. str << "an invalid stack!";
  608. str << "stack with " << sth.count << " of ";
  609. if(sth.type)
  610. str << sth.type->namePl;
  611. else
  612. str << sth.idRand;
  613. return str;
  614. }
  615. void CSimpleArmy::clear()
  616. {
  617. army.clear();
  618. }
  619. CSimpleArmy::operator bool() const
  620. {
  621. return army.size();
  622. }
  623. bool CSimpleArmy::setCreature(TSlot slot, TCreature cre, TQuantity count)
  624. {
  625. assert(!vstd::contains(army, slot));
  626. army[slot] = CStackBasicDescriptor(cre, count);
  627. return true;
  628. }