CLua.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. #include "stdafx.h"
  2. #include <sstream>
  3. #include <boost/algorithm/string.hpp>
  4. #include <boost/algorithm/string/replace.hpp>
  5. #include "hch/CHeroHandler.h"
  6. #include "hch/CObjectHandler.h"
  7. #include "hch/CTownHandler.h"
  8. #include "hch/CArtHandler.h"
  9. #include "hch/CDefObjInfoHandler.h"
  10. //#include "lua.h"
  11. //#include "lualib.h"
  12. //#include "lauxlib.h"
  13. //#include "lobject.h"
  14. //#include "lgc.h"
  15. //#include "lapi.h"
  16. #include "CLua.h"
  17. #include "CGameState.h"
  18. #include "lib/VCMI_Lib.h"
  19. #include "map.h"
  20. #include "server/CScriptCallback.h"
  21. #include "lib/NetPacks.h"
  22. #pragma warning (disable : 4311)
  23. #define DEFOS const CGObjectInstance *os = cb->getObj(objid)
  24. bool getGlobalFunc(lua_State * L, std::string fname)
  25. {
  26. //unsigned int hash = lua_calchash(fname.c_str(), fname.size());
  27. //lua_pushhstring(L, hash, fname.c_str(), fname.size());
  28. //lua_gettable(L, LUA_GLOBALSINDEX);
  29. //return lua_isfunction(L, -1);
  30. return false;
  31. }
  32. CObjectScript::CObjectScript()
  33. {
  34. language = ESLan::UNDEF;
  35. //std::cout << "Tworze obiekt objectscript "<<this<<std::endl;
  36. }
  37. CObjectScript::~CObjectScript()
  38. {
  39. //std::cout << "Usuwam obiekt objectscript "<<this<<std::endl;
  40. }
  41. CScript::CScript()
  42. {
  43. //std::cout << "Tworze obiekt CScript "<<this<<std::endl;
  44. }
  45. CScript::~CScript()
  46. {
  47. //std::cout << "Usuwam obiekt CScript "<<this<<std::endl;
  48. }
  49. #define LST (is)
  50. CLua::CLua(std::string initpath)
  51. {
  52. opened=false;
  53. open(initpath);
  54. }
  55. CLua::CLua()
  56. {
  57. //std::cout << "Tworze obiekt clua "<<this<<std::endl;
  58. opened=false;
  59. }
  60. void CLua::open(std::string initpath)
  61. {
  62. //LST = lua_open();
  63. //opened = true;
  64. //LUA_OPEN_LIB(LST, luaopen_base);
  65. //LUA_OPEN_LIB(LST, luaopen_io);
  66. //if ((luaL_loadfile (LST, initpath.c_str())) == 0)
  67. //{
  68. // lua_pcall (LST, 0, LUA_MULTRET, 0);
  69. //}
  70. //else
  71. //{
  72. // std::string temp = "Cannot open script ";
  73. // temp += initpath;
  74. // throw std::exception(temp.c_str());
  75. //}
  76. }
  77. void CLua::registerCLuaCallback()
  78. {
  79. }
  80. CLua::~CLua()
  81. {
  82. ////std::cout << "Usuwam obiekt clua "<<this<<std::endl;
  83. //if (opened)
  84. //{
  85. // std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
  86. // lua_close(LST);
  87. //}
  88. }
  89. void CLua::findF(std::string fname)
  90. {
  91. // lua_getfield(is, LUA_GLOBALSINDEX, fname.c_str()); /* function to be called */
  92. }
  93. void CLua::findF2(std::string fname)
  94. {
  95. //lua_pushstring (is, fname.c_str());
  96. //lua_gettable (is, LUA_GLOBALSINDEX);
  97. }
  98. void CLua::findFS(std::string fname)
  99. {
  100. //lua_settop(is, 0);
  101. //if (!getGlobalFunc(is,fname))
  102. //{
  103. // lua_settop(is, 0);
  104. // throw new std::exception((fname + ": function not defined").c_str()); // the call is not defined
  105. //}
  106. }
  107. #undef LST
  108. CLuaObjectScript::CLuaObjectScript(std::string filename)
  109. {
  110. language = ESLan::LUA;
  111. open(filename);
  112. //binit = bnewobject = bonherovisit = brightext = false;
  113. //std::cout << "Tworze obiekt CLuaObjectScript "<<this<<std::endl;
  114. }
  115. CLuaObjectScript::~CLuaObjectScript()
  116. {
  117. //std::cout << "Usuwam obiekt CLuaObjectScript "<<this<<std::endl;
  118. }
  119. void CLuaObjectScript::init()
  120. {
  121. }
  122. std::string CLuaObjectScript::genFN(std::string base, int ID)
  123. {
  124. std::stringstream sts;
  125. sts<<base<<"_"<<ID;
  126. return sts.str();
  127. }
  128. void CLuaObjectScript::newObject(int objid)
  129. {
  130. //findF(genFN("newObject",os->ID));
  131. //lua_pushinteger(is, (int)os);
  132. //if (lua_pcall (is, 1, 0, 0))
  133. //{
  134. // lua_settop(is, 0);
  135. // throw new std::exception(("Failed to call "+genFN("newObject",os->ID)+" function in lua script.").c_str());
  136. //}
  137. //lua_settop(is, 0);
  138. return;
  139. }
  140. void CLuaObjectScript::onHeroVisit(int objid, int heroID)
  141. {
  142. //findF(genFN("heroVisit",os->ID));
  143. //lua_pushinteger(is, (int)os);
  144. //lua_pushinteger(is, heroID);
  145. //if (lua_pcall (is, 2, 0, 0))
  146. //{
  147. // lua_settop(is, 0);
  148. // throw new std::exception(("Failed to call "+genFN("heroVisit",os->ID)+" function in lua script.").c_str());
  149. //}
  150. //lua_settop(is, 0);
  151. }
  152. //std::string CLuaObjectScript::hoverText(int objid)
  153. //{
  154. // //findF(genFN("hoverText",os->ID));
  155. // //lua_pushinteger(is, (int)os);
  156. // //if (lua_pcall (is, 1, 1, 0))
  157. // //{
  158. // // lua_settop(is, 0);
  159. // // throw new std::exception(("Failed to call "+genFN("hoverText",os->ID)+" function in lua script.").c_str());
  160. // //}
  161. // //std::string ret = lua_tostring(is,1);
  162. // //lua_settop(is, 0);
  163. // return "";
  164. //}
  165. void CVisitableOPH::newObject(int objid)
  166. {
  167. visitors.insert
  168. (std::pair<int,std::set<int> >(objid,std::set<int>()));
  169. DEFOS;
  170. MetaString hovername;
  171. int pom;
  172. switch(os->ID)
  173. {
  174. case 51:
  175. pom = 8;
  176. break;
  177. case 23:
  178. pom = 7;
  179. break;
  180. case 61:
  181. pom = 11;
  182. break;
  183. case 32:
  184. pom = 4;
  185. break;
  186. case 100:
  187. pom = 5;
  188. break;
  189. default:
  190. throw new std::exception("Unsupported ID in CVisitableOPH::hoverText");
  191. }
  192. hovername << std::pair<ui8,ui32>(3,os->ID) << " " << std::pair<ui8,ui32>(2,pom);
  193. cb->setHoverName(objid,&hovername);
  194. //int heroID = cb->getSelectedHero();
  195. //if (heroID>=0)
  196. //{
  197. //add += ( (visitors[os].find(heroID) == visitors[os].end())
  198. // ?
  199. // (VLC->generaltexth->allTexts[353]) //not visited
  200. // :
  201. // ( VLC->generaltexth->allTexts[352]) ); //visited
  202. //}
  203. };
  204. void CVisitableOPH::onHeroVisit(int objid, int heroID)
  205. {
  206. if (visitors.find(objid)!=visitors.end())
  207. {
  208. if(visitors[objid].find(heroID)==visitors[objid].end())
  209. {
  210. onNAHeroVisit(objid,heroID, false);
  211. visitors[objid].insert(heroID);
  212. }
  213. else
  214. {
  215. onNAHeroVisit(objid,heroID, true);
  216. }
  217. }
  218. else
  219. {
  220. throw new std::exception("Skrypt nie zainicjalizowal instancji tego obiektu. :(");
  221. }
  222. };
  223. void CVisitableOPH::onNAHeroVisit(int objid, int heroID, bool alreadyVisited)
  224. {
  225. const CGObjectInstance *os = cb->getObj(objid);
  226. int w=0, ot=0, vvv=1;
  227. switch(os->ID)
  228. {
  229. case 51:
  230. w=0;
  231. ot=80;
  232. break;
  233. case 23:
  234. w=1;
  235. ot=39;
  236. break;
  237. case 61:
  238. w=2;
  239. ot=100;
  240. break;
  241. case 32:
  242. w=3;
  243. ot=59;
  244. break;
  245. case 100:
  246. w=4;
  247. ot=143;
  248. vvv=1000;
  249. break;
  250. }
  251. if (!alreadyVisited)
  252. {
  253. switch (os->ID)
  254. {
  255. case 51:
  256. case 23:
  257. case 61:
  258. case 32:
  259. {
  260. //cb->changePrimSkill(heroID,w,vvv);
  261. //std::vector<SComponent*> weko;
  262. //weko.push_back(new SComponent(SComponent::primskill,w,vvv));
  263. //cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&weko);
  264. //break;
  265. }
  266. case 100:
  267. {
  268. //cb->changePrimSkill(heroID,w,vvv);
  269. //std::vector<SComponent*> weko;
  270. //weko.push_back(new SComponent(SComponent::experience,0,vvv));
  271. //cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&weko);
  272. //break;
  273. }
  274. }
  275. }
  276. else
  277. {
  278. ot++;
  279. //cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&std::vector<SComponent*>());
  280. }
  281. }
  282. std::vector<int> CVisitableOPH::yourObjects()
  283. {
  284. std::vector<int> ret(5);
  285. ret.push_back(51);
  286. ret.push_back(23);
  287. ret.push_back(61);
  288. ret.push_back(32);
  289. ret.push_back(100);
  290. return ret;
  291. }
  292. void CVisitableOPW::onNAHeroVisit(int objid, int heroID, bool alreadyVisited)
  293. {
  294. //int mid;
  295. //switch (os->ID)
  296. //{
  297. //case 55:
  298. // mid = 92;
  299. // break;
  300. //case 112:
  301. // mid = 170;
  302. // break;
  303. //case 109:
  304. // mid = 164;
  305. // break;
  306. //}
  307. //if (alreadyVisited)
  308. //{
  309. // if (os->ID!=112)
  310. // mid++;
  311. // else
  312. // mid--;
  313. // cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[mid],&std::vector<SComponent*>()); //TODO: maybe we have memory leak with these windows
  314. //}
  315. //else
  316. //{
  317. // int type, sub, val;
  318. // type = SComponent::resource;
  319. // switch (os->ID)
  320. // {
  321. // case 55:
  322. // if (rand()%2)
  323. // {
  324. // sub = 5;
  325. // val = 5;
  326. // }
  327. // else
  328. // {
  329. // sub = 6;
  330. // val = 500;
  331. // }
  332. // break;
  333. // case 112:
  334. // mid = 170;
  335. // sub = (rand() % 5) + 1;
  336. // val = (rand() % 4) + 3;
  337. // break;
  338. // case 109:
  339. // mid = 164;
  340. // sub = 6;
  341. // if(cb->getDate(2)<2)
  342. // val = 500;
  343. // else
  344. // val = 1000;
  345. // }
  346. // SComponent * com = new SComponent((SComponent::Etype)type,sub,val);
  347. // std::vector<SComponent*> weko;
  348. // weko.push_back(com);
  349. // cb->giveResource(cb->getHeroOwner(heroID),sub,val);
  350. // cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[mid],&weko);
  351. // visited[os] = true;
  352. //}
  353. }
  354. void CVisitableOPW::newTurn ()
  355. {
  356. if (cb->getDate(1)==1)
  357. {
  358. for (std::map<int,bool>::iterator i = visited.begin(); i != visited.end(); i++)
  359. {
  360. (*i).second = false;
  361. }
  362. }
  363. }
  364. void CVisitableOPW::newObject(int objid)
  365. {
  366. visited.insert(std::pair<int,bool>(objid,false));
  367. DEFOS;
  368. MetaString ms;
  369. ms << std::pair<ui8,ui32>(3,os->ID) << " " << std::pair<ui8,ui32>(1,visited[objid] ? 352 : 353);
  370. cb->setHoverName(objid,&ms);
  371. }
  372. void CVisitableOPW::onHeroVisit(int objid, int heroID)
  373. {
  374. if(visited[objid])
  375. onNAHeroVisit(objid,heroID,true);
  376. else
  377. onNAHeroVisit(objid,heroID,false);
  378. }
  379. std::vector<int> CVisitableOPW::yourObjects() //returns IDs of objects which are handled by script
  380. {
  381. std::vector<int> ret(3);
  382. ret.push_back(55); //mystical garden
  383. ret.push_back(112); //windmill
  384. ret.push_back(109); //water wheel
  385. return ret;
  386. }
  387. void CMines::newObject(int objid)
  388. {
  389. ourObjs.push_back(objid);
  390. cb->setOwner(objid,NEUTRAL_PLAYER);
  391. DEFOS;
  392. MetaString ms;
  393. ms << std::pair<ui8,ui32>(3,os->ID);
  394. cb->setHoverName(objid,&ms);
  395. }
  396. void CMines::onHeroVisit(int objid, int heroID)
  397. {
  398. //TODO: this is code for standard mines, no support for abandoned mine (subId==7)
  399. DEFOS;
  400. const CGHeroInstance *h = cb->getHero(heroID);
  401. cb->setOwner(objid,h->tempOwner);
  402. MetaString ms;
  403. ms << std::pair<ui8,ui32>(9,os->subID) << " " << std::pair<ui8,ui32>(6,23+h->tempOwner);
  404. cb->setHoverName(objid,&ms);
  405. ms.clear();
  406. int vv=1; //amount of resource per turn
  407. if (os->subID==0 || os->subID==2)
  408. vv++;
  409. else if (os->subID==6)
  410. vv = 1000;
  411. InfoWindow iw;
  412. iw.text << std::pair<ui8,ui32>(10,os->subID);
  413. iw.player = h->tempOwner;
  414. iw.components.push_back(Component(2,os->subID,vv,-1));
  415. cb->showInfoDialog(&iw);
  416. //TODO: leaving garrison
  417. }
  418. std::vector<int> CMines::yourObjects()
  419. {
  420. std::vector<int> ret;
  421. ret.push_back(53);
  422. return ret;
  423. }
  424. void CMines::newTurn ()
  425. {
  426. const CGObjectInstance * obj;
  427. for (unsigned i=0;i<ourObjs.size();i++)
  428. {
  429. obj = cb->getObj(ourObjs[i]);
  430. if (obj->tempOwner == NEUTRAL_PLAYER)
  431. continue;
  432. int vv = 1;
  433. if (obj->subID==0 || obj->subID==2)
  434. vv++;
  435. else if (obj->subID==6)
  436. vv = 1000;
  437. cb->giveResource(obj->tempOwner,obj->subID,vv);
  438. }
  439. }
  440. void CPickable::newObject(int objid)
  441. {
  442. cb->setBlockVis(objid,true);
  443. MetaString ms;
  444. DEFOS;
  445. switch (os->ID)
  446. {
  447. case 79:
  448. ms << std::pair<ui8,ui32>(4,os->ID);
  449. break;
  450. case 5:
  451. ms << std::pair<ui8,ui32>(5,os->ID);
  452. break;
  453. default:
  454. ms << std::pair<ui8,ui32>(3,os->ID);
  455. break;
  456. }
  457. cb->setHoverName(objid,&ms);
  458. }
  459. void CPickable::onHeroVisit(int objid, int heroID)
  460. {
  461. DEFOS;
  462. switch(os->ID)
  463. {
  464. case 5:
  465. {
  466. cb->giveHeroArtifact(os->subID,heroID,-1); //TODO: na pozycje
  467. break;
  468. }
  469. case 79:
  470. {
  471. ////TODO: handle guards (when battles are finished)
  472. //CResourceObjInfo * t2 = static_cast<CResourceObjInfo *>(os->info);
  473. //int val;
  474. //if(t2->amount)
  475. // val = t2->amount;
  476. //else
  477. //{
  478. // switch(os->subID)
  479. // {
  480. // case 6:
  481. // val = 500 + (rand()%6)*100;
  482. // break;
  483. // case 0: case 2:
  484. // val = 6 + (rand()%5);
  485. // break;
  486. // default:
  487. // val = 3 + (rand()%3);
  488. // break;
  489. // }
  490. //}
  491. //if(t2->message.length())
  492. // cb->showInfoDialog(cb->getHeroOwner(heroID),t2->message,&std::vector<SComponent*>());
  493. //SComponent ccc(SComponent::resource,os->subID,val);
  494. //ccc.description = VLC->objh->advobtxt[113];
  495. //boost::algorithm::replace_first(ccc.description,"%s",VLC->objh->restypes[os->subID]);
  496. //cb->giveResource(cb->getHeroOwner(heroID),os->subID,val);
  497. //cb->showCompInfo(cb->getHeroOwner(heroID),&ccc);
  498. break;
  499. }
  500. case 101:
  501. {
  502. //if (os->subID)
  503. // break; //not OH3 treasure chest
  504. //int wyn = rand()%100;
  505. //if (wyn<32)
  506. //{
  507. // tempStore.push_back(new CSelectableComponent(SComponent::resource,6,1000));
  508. // tempStore.push_back(new CSelectableComponent(SComponent::experience,0,500));
  509. //}//1k/0.5k
  510. //else if(wyn<64)
  511. //{
  512. // tempStore.push_back(new CSelectableComponent(SComponent::resource,6,1500));
  513. // tempStore.push_back(new CSelectableComponent(SComponent::experience,0,1000));
  514. //}//1.5k/1k
  515. //else if(wyn<95)
  516. //{
  517. // tempStore.push_back(new CSelectableComponent(SComponent::resource,6,2000));
  518. // tempStore.push_back(new CSelectableComponent(SComponent::experience,0,1500));
  519. //}//2k/1.5k
  520. //else
  521. //{
  522. // if (1/*TODO: backpack is full*/)
  523. // {
  524. // tempStore.push_back(new CSelectableComponent(SComponent::resource,6,1000));
  525. // tempStore.push_back(new CSelectableComponent(SComponent::experience,0,500));
  526. // }
  527. // else
  528. // {
  529. // //TODO: give treasure artifact
  530. // break;
  531. // }
  532. //}//random treasure artifact, or (if backapack is full) 1k/0.5k
  533. //tempStore[1]->ID = heroID;
  534. //player = cb->getHeroOwner(heroID);
  535. //cb->showSelDialog(player,VLC->objh->advobtxt[146],&tempStore,this);
  536. break;
  537. }
  538. }
  539. //VLC->mh->removeObject(os);
  540. }
  541. void CPickable::chosen(int which)
  542. {
  543. //switch(tempStore[which]->type)
  544. //{
  545. //case SComponent::resource:
  546. // cb->giveResource(player,tempStore[which]->subtype,tempStore[which]->val);
  547. // break;
  548. //case SComponent::experience:
  549. // cb->changePrimSkill(tempStore[which]->ID,4,tempStore[which]->val);
  550. // break;
  551. //default:
  552. // throw new std::exception("Unhandled choice");
  553. //
  554. //}
  555. //for (int i=0;i<tempStore.size();i++)
  556. // delete tempStore[i];
  557. //tempStore.clear();
  558. }
  559. std::vector<int> CPickable::yourObjects() //returns IDs of objects which are handled by script
  560. {
  561. std::vector<int> ret(3);
  562. ret.push_back(79); //resource
  563. ret.push_back(5); //artifact
  564. ret.push_back(101); //treasure chest / commander stone
  565. return ret;
  566. }
  567. void CTownScript::onHeroVisit(int objid, int heroID)
  568. {
  569. cb->heroVisitCastle(objid,heroID);
  570. }
  571. void CTownScript::newObject(int objid)
  572. {
  573. MetaString ms;
  574. const CGTownInstance * n = cb->getTown(objid);
  575. ms << n->name << ", " << n->town->name;
  576. cb->setHoverName(objid,&ms);
  577. }
  578. void CTownScript::onHeroLeave(int objid, int heroID)
  579. {
  580. cb->stopHeroVisitCastle(objid,heroID);
  581. }
  582. std::vector<int> CTownScript::yourObjects() //returns IDs of objects which are handled by script
  583. {
  584. std::vector<int> ret(1);
  585. ret.push_back(98); //town
  586. return ret;
  587. }
  588. void CHeroScript::newObject(int objid)
  589. {
  590. cb->setBlockVis(objid,true);
  591. }
  592. void CHeroScript::onHeroVisit(int objid, int heroID)
  593. {
  594. //TODO: check for allies
  595. const CGHeroInstance *my = cb->getHero(objid),
  596. *vis = cb->getHero(objid);
  597. if(my->tempOwner == vis->tempOwner) //one of allied cases
  598. {
  599. //exchange
  600. }
  601. else
  602. {
  603. cb->startBattle(
  604. &my->army,
  605. &vis->army,
  606. my->pos,
  607. my,
  608. vis);
  609. }
  610. }
  611. std::vector<int> CHeroScript::yourObjects() //returns IDs of objects which are handled by script
  612. {
  613. std::vector<int> ret(1);
  614. ret.push_back(34); //hero
  615. return ret;
  616. }
  617. //std::string CHeroScript::hoverText(int objid)
  618. //{
  619. // //CGHeroInstance* h = static_cast<CGHeroInstance*>(os);
  620. // //std::string ret = VLC->generaltexth->allTexts[15];
  621. // //boost::algorithm::replace_first(ret,"%s",h->name);
  622. // //boost::algorithm::replace_first(ret,"%s",h->type->heroClass->name);
  623. // //return ret;
  624. // return "";
  625. //}
  626. void CMonsterS::newObject(int objid)
  627. {
  628. //os->blockVisit = true;
  629. DEFOS;
  630. switch(VLC->creh->creatures[os->subID].level)
  631. {
  632. case 1:
  633. amounts[objid] = rand()%31+20;
  634. break;
  635. case 2:
  636. amounts[objid] = rand()%16+15;
  637. break;
  638. case 3:
  639. amounts[objid] = rand()%16+10;
  640. break;
  641. case 4:
  642. amounts[objid] = rand()%11+10;
  643. break;
  644. case 5:
  645. amounts[objid] = rand()%9+8;
  646. break;
  647. case 6:
  648. amounts[objid] = rand()%8+5;
  649. break;
  650. case 7:
  651. amounts[objid] = rand()%7+3;
  652. break;
  653. case 8:
  654. amounts[objid] = rand()%4+2;
  655. break;
  656. case 9:
  657. amounts[objid] = rand()%3+2;
  658. break;
  659. case 10:
  660. amounts[objid] = rand()%3+1;
  661. break;
  662. }
  663. MetaString ms;
  664. int pom = CCreature::getQuantityID(amounts[objid]);
  665. pom = 174 + 3*pom + 1;
  666. ms << std::pair<ui8,ui32>(6,pom) << " " << std::pair<ui8,ui32>(7,os->subID);
  667. cb->setHoverName(objid,&ms);
  668. }
  669. void CMonsterS::onHeroVisit(int objid, int heroID)
  670. {
  671. DEFOS;
  672. CCreatureSet set;
  673. //TODO: zrobic secik w sposob wyrafinowany
  674. set.slots[0] = std::pair<CCreature*,int>(&VLC->creh->creatures[os->subID],((CCreatureObjInfo*)os->info)->number);
  675. cb->startBattle(heroID,&set,os->pos);
  676. }
  677. std::vector<int> CMonsterS::yourObjects() //returns IDs of objects which are handled by script
  678. {
  679. std::vector<int> ret(1);
  680. ret.push_back(54); //monster
  681. return ret;
  682. }
  683. void CCreatureGen::newObject(int objid)
  684. {
  685. DEFOS;
  686. amount[objid] = VLC->creh->creatures[VLC->objh->cregens[os->subID]].growth;
  687. MetaString ms;
  688. ms << std::pair<ui8,ui32>(8,os->subID);
  689. cb->setHoverName(objid,&ms);
  690. }
  691. void CCreatureGen::onHeroVisit(int objid, int heroID)
  692. {
  693. }
  694. std::vector<int> CCreatureGen::yourObjects() //returns IDs of objects which are handled by script
  695. {
  696. std::vector<int> ret(1);
  697. ret.push_back(17); //cregen1
  698. return ret;
  699. }