2007-10-28 13:34:33 +02:00
|
|
|
#include "stdafx.h"
|
2008-07-30 20:51:19 +03:00
|
|
|
#include <sstream>
|
2008-08-13 03:44:31 +03:00
|
|
|
#include <boost/bind.hpp>
|
|
|
|
#include <boost/function.hpp>
|
2008-07-30 20:51:19 +03:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
2007-11-19 00:58:28 +02:00
|
|
|
#include "hch/CHeroHandler.h"
|
2008-07-30 20:51:19 +03:00
|
|
|
#include "hch/CObjectHandler.h"
|
|
|
|
#include "hch/CTownHandler.h"
|
|
|
|
#include "hch/CArtHandler.h"
|
|
|
|
#include "hch/CDefObjInfoHandler.h"
|
2008-07-25 20:28:28 +03:00
|
|
|
//#include "lua.h"
|
|
|
|
//#include "lualib.h"
|
|
|
|
//#include "lauxlib.h"
|
|
|
|
//#include "lobject.h"
|
|
|
|
//#include "lgc.h"
|
|
|
|
//#include "lapi.h"
|
2008-07-30 20:51:19 +03:00
|
|
|
#include "CLua.h"
|
2007-11-19 00:58:28 +02:00
|
|
|
#include "CGameState.h"
|
2008-07-30 20:51:19 +03:00
|
|
|
#include "lib/VCMI_Lib.h"
|
2008-07-02 11:39:56 +03:00
|
|
|
#include "map.h"
|
2008-07-30 20:51:19 +03:00
|
|
|
#include "server/CScriptCallback.h"
|
|
|
|
#include "lib/NetPacks.h"
|
2007-11-24 00:33:55 +02:00
|
|
|
#pragma warning (disable : 4311)
|
2008-07-30 20:51:19 +03:00
|
|
|
#define DEFOS const CGObjectInstance *os = cb->getObj(objid)
|
2007-11-19 00:58:28 +02:00
|
|
|
bool getGlobalFunc(lua_State * L, std::string fname)
|
|
|
|
{
|
2008-07-25 20:28:28 +03:00
|
|
|
//unsigned int hash = lua_calchash(fname.c_str(), fname.size());
|
|
|
|
//lua_pushhstring(L, hash, fname.c_str(), fname.size());
|
|
|
|
//lua_gettable(L, LUA_GLOBALSINDEX);
|
|
|
|
//return lua_isfunction(L, -1);
|
|
|
|
return false;
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
2007-10-28 13:34:33 +02:00
|
|
|
|
|
|
|
CObjectScript::CObjectScript()
|
|
|
|
{
|
2008-08-02 18:08:03 +03:00
|
|
|
language = UNDEF;
|
2007-10-28 13:34:33 +02:00
|
|
|
//std::cout << "Tworze obiekt objectscript "<<this<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
CObjectScript::~CObjectScript()
|
|
|
|
{
|
|
|
|
//std::cout << "Usuwam obiekt objectscript "<<this<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
CScript::CScript()
|
|
|
|
{
|
|
|
|
//std::cout << "Tworze obiekt CScript "<<this<<std::endl;
|
|
|
|
}
|
|
|
|
CScript::~CScript()
|
|
|
|
{
|
|
|
|
//std::cout << "Usuwam obiekt CScript "<<this<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LST (is)
|
|
|
|
CLua::CLua(std::string initpath)
|
|
|
|
{
|
|
|
|
opened=false;
|
2007-11-19 00:58:28 +02:00
|
|
|
open(initpath);
|
|
|
|
}
|
|
|
|
CLua::CLua()
|
|
|
|
{
|
|
|
|
//std::cout << "Tworze obiekt clua "<<this<<std::endl;
|
|
|
|
opened=false;
|
|
|
|
}
|
|
|
|
void CLua::open(std::string initpath)
|
|
|
|
{
|
2008-07-25 20:28:28 +03:00
|
|
|
//LST = lua_open();
|
|
|
|
//opened = true;
|
|
|
|
//LUA_OPEN_LIB(LST, luaopen_base);
|
|
|
|
//LUA_OPEN_LIB(LST, luaopen_io);
|
|
|
|
//if ((luaL_loadfile (LST, initpath.c_str())) == 0)
|
|
|
|
//{
|
|
|
|
// lua_pcall (LST, 0, LUA_MULTRET, 0);
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// std::string temp = "Cannot open script ";
|
|
|
|
// temp += initpath;
|
|
|
|
// throw std::exception(temp.c_str());
|
|
|
|
//}
|
2007-10-28 13:34:33 +02:00
|
|
|
}
|
|
|
|
void CLua::registerCLuaCallback()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CLua::~CLua()
|
|
|
|
{
|
2008-07-25 20:28:28 +03:00
|
|
|
////std::cout << "Usuwam obiekt clua "<<this<<std::endl;
|
|
|
|
//if (opened)
|
|
|
|
//{
|
|
|
|
// std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
|
|
|
|
// lua_close(LST);
|
|
|
|
//}
|
2007-10-28 13:34:33 +02:00
|
|
|
}
|
2007-11-19 00:58:28 +02:00
|
|
|
|
|
|
|
void CLua::findF(std::string fname)
|
|
|
|
{
|
2008-07-25 20:28:28 +03:00
|
|
|
// lua_getfield(is, LUA_GLOBALSINDEX, fname.c_str()); /* function to be called */
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
|
|
|
void CLua::findF2(std::string fname)
|
|
|
|
{
|
2008-07-25 20:28:28 +03:00
|
|
|
//lua_pushstring (is, fname.c_str());
|
|
|
|
//lua_gettable (is, LUA_GLOBALSINDEX);
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
|
|
|
void CLua::findFS(std::string fname)
|
|
|
|
{
|
2008-07-25 20:28:28 +03:00
|
|
|
//lua_settop(is, 0);
|
|
|
|
//if (!getGlobalFunc(is,fname))
|
|
|
|
//{
|
|
|
|
// lua_settop(is, 0);
|
|
|
|
// throw new std::exception((fname + ": function not defined").c_str()); // the call is not defined
|
|
|
|
//}
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
2007-10-28 13:34:33 +02:00
|
|
|
#undef LST
|
|
|
|
|
2007-11-19 00:58:28 +02:00
|
|
|
CLuaObjectScript::CLuaObjectScript(std::string filename)
|
2007-10-28 13:34:33 +02:00
|
|
|
{
|
2008-08-02 18:08:03 +03:00
|
|
|
language = LUA;
|
2007-11-19 00:58:28 +02:00
|
|
|
open(filename);
|
|
|
|
//binit = bnewobject = bonherovisit = brightext = false;
|
2007-10-28 13:34:33 +02:00
|
|
|
//std::cout << "Tworze obiekt CLuaObjectScript "<<this<<std::endl;
|
|
|
|
}
|
|
|
|
CLuaObjectScript::~CLuaObjectScript()
|
|
|
|
{
|
|
|
|
//std::cout << "Usuwam obiekt CLuaObjectScript "<<this<<std::endl;
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLuaObjectScript::init()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CLuaObjectScript::genFN(std::string base, int ID)
|
|
|
|
{
|
|
|
|
std::stringstream sts;
|
|
|
|
sts<<base<<"_"<<ID;
|
|
|
|
return sts.str();
|
|
|
|
}
|
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
void CLuaObjectScript::newObject(int objid)
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
2008-07-25 20:28:28 +03:00
|
|
|
//findF(genFN("newObject",os->ID));
|
|
|
|
//lua_pushinteger(is, (int)os);
|
|
|
|
//if (lua_pcall (is, 1, 0, 0))
|
|
|
|
//{
|
|
|
|
// lua_settop(is, 0);
|
|
|
|
// throw new std::exception(("Failed to call "+genFN("newObject",os->ID)+" function in lua script.").c_str());
|
|
|
|
//}
|
|
|
|
//lua_settop(is, 0);
|
2007-11-19 00:58:28 +02:00
|
|
|
return;
|
|
|
|
}
|
2008-07-30 20:51:19 +03:00
|
|
|
void CLuaObjectScript::onHeroVisit(int objid, int heroID)
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
2008-07-25 20:28:28 +03:00
|
|
|
//findF(genFN("heroVisit",os->ID));
|
|
|
|
//lua_pushinteger(is, (int)os);
|
|
|
|
//lua_pushinteger(is, heroID);
|
|
|
|
//if (lua_pcall (is, 2, 0, 0))
|
|
|
|
//{
|
|
|
|
// lua_settop(is, 0);
|
|
|
|
// throw new std::exception(("Failed to call "+genFN("heroVisit",os->ID)+" function in lua script.").c_str());
|
|
|
|
//}
|
|
|
|
//lua_settop(is, 0);
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
2008-07-30 20:51:19 +03:00
|
|
|
//std::string CLuaObjectScript::hoverText(int objid)
|
|
|
|
//{
|
|
|
|
// //findF(genFN("hoverText",os->ID));
|
|
|
|
// //lua_pushinteger(is, (int)os);
|
|
|
|
// //if (lua_pcall (is, 1, 1, 0))
|
|
|
|
// //{
|
|
|
|
// // lua_settop(is, 0);
|
|
|
|
// // throw new std::exception(("Failed to call "+genFN("hoverText",os->ID)+" function in lua script.").c_str());
|
|
|
|
// //}
|
|
|
|
// //std::string ret = lua_tostring(is,1);
|
|
|
|
// //lua_settop(is, 0);
|
|
|
|
// return "";
|
|
|
|
//}
|
|
|
|
|
|
|
|
void CVisitableOPH::newObject(int objid)
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
visitors.insert
|
|
|
|
(std::pair<int,std::set<int> >(objid,std::set<int>()));
|
2007-11-19 00:58:28 +02:00
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
DEFOS;
|
|
|
|
MetaString hovername;
|
|
|
|
int pom;
|
|
|
|
switch(os->ID)
|
|
|
|
{
|
|
|
|
case 51:
|
|
|
|
pom = 8;
|
|
|
|
break;
|
|
|
|
case 23:
|
|
|
|
pom = 7;
|
|
|
|
break;
|
|
|
|
case 61:
|
|
|
|
pom = 11;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
pom = 4;
|
|
|
|
break;
|
|
|
|
case 100:
|
|
|
|
pom = 5;
|
|
|
|
break;
|
2008-08-22 15:21:09 +03:00
|
|
|
case 102:
|
|
|
|
typeOfTree[objid] = rand()%3;
|
|
|
|
return;
|
2008-07-30 20:51:19 +03:00
|
|
|
default:
|
2008-08-22 15:21:09 +03:00
|
|
|
std::cout << "Unsupported ID in CVisitableOPH::hoverText" << std::endl;
|
|
|
|
return;
|
2008-07-30 20:51:19 +03:00
|
|
|
}
|
|
|
|
hovername << std::pair<ui8,ui32>(3,os->ID) << " " << std::pair<ui8,ui32>(2,pom);
|
|
|
|
cb->setHoverName(objid,&hovername);
|
|
|
|
|
|
|
|
//int heroID = cb->getSelectedHero();
|
|
|
|
//if (heroID>=0)
|
|
|
|
//{
|
|
|
|
//add += ( (visitors[os].find(heroID) == visitors[os].end())
|
|
|
|
// ?
|
|
|
|
// (VLC->generaltexth->allTexts[353]) //not visited
|
|
|
|
// :
|
|
|
|
// ( VLC->generaltexth->allTexts[352]) ); //visited
|
|
|
|
//}
|
2007-11-19 00:58:28 +02:00
|
|
|
};
|
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
void CVisitableOPH::onHeroVisit(int objid, int heroID)
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
2008-08-22 15:21:09 +03:00
|
|
|
DEFOS;
|
2008-07-30 20:51:19 +03:00
|
|
|
if (visitors.find(objid)!=visitors.end())
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
if(visitors[objid].find(heroID)==visitors[objid].end())
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
onNAHeroVisit(objid,heroID, false);
|
2008-08-22 15:21:09 +03:00
|
|
|
if(os->ID != 102)
|
|
|
|
visitors[objid].insert(heroID);
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
onNAHeroVisit(objid,heroID, true);
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-04 12:05:52 +03:00
|
|
|
#ifndef __GNUC__
|
2007-11-19 00:58:28 +02:00
|
|
|
throw new std::exception("Skrypt nie zainicjalizowal instancji tego obiektu. :(");
|
2008-08-04 12:05:52 +03:00
|
|
|
#else
|
|
|
|
throw new std::exception();
|
|
|
|
#endif
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
|
|
|
};
|
2008-07-30 20:51:19 +03:00
|
|
|
void CVisitableOPH::onNAHeroVisit(int objid, int heroID, bool alreadyVisited)
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
const CGObjectInstance *os = cb->getObj(objid);
|
2008-08-22 15:21:09 +03:00
|
|
|
int id=0, subid=0, ot=0, val=1;
|
2007-11-24 00:33:55 +02:00
|
|
|
switch(os->ID)
|
|
|
|
{
|
|
|
|
case 51:
|
2008-08-22 15:21:09 +03:00
|
|
|
subid=0;
|
2007-11-24 00:33:55 +02:00
|
|
|
ot=80;
|
|
|
|
break;
|
|
|
|
case 23:
|
2008-08-22 15:21:09 +03:00
|
|
|
subid=1;
|
2007-11-24 00:33:55 +02:00
|
|
|
ot=39;
|
|
|
|
break;
|
|
|
|
case 61:
|
2008-08-22 15:21:09 +03:00
|
|
|
subid=2;
|
2007-11-24 00:33:55 +02:00
|
|
|
ot=100;
|
|
|
|
break;
|
|
|
|
case 32:
|
2008-08-22 15:21:09 +03:00
|
|
|
subid=3;
|
2007-11-24 00:33:55 +02:00
|
|
|
ot=59;
|
|
|
|
break;
|
2007-12-25 18:25:53 +02:00
|
|
|
case 100:
|
2008-08-22 15:21:09 +03:00
|
|
|
id=5;
|
2007-12-25 18:25:53 +02:00
|
|
|
ot=143;
|
2008-08-22 15:21:09 +03:00
|
|
|
val=1000;
|
|
|
|
break;
|
|
|
|
case 102:
|
|
|
|
id = 5;
|
|
|
|
subid = 1;
|
|
|
|
ot = 146;
|
|
|
|
val = 1;
|
2007-12-25 18:25:53 +02:00
|
|
|
break;
|
2007-11-24 00:33:55 +02:00
|
|
|
}
|
2007-11-19 00:58:28 +02:00
|
|
|
if (!alreadyVisited)
|
|
|
|
{
|
|
|
|
switch (os->ID)
|
|
|
|
{
|
|
|
|
case 51:
|
|
|
|
case 23:
|
|
|
|
case 61:
|
|
|
|
case 32:
|
|
|
|
{
|
2008-08-22 15:21:09 +03:00
|
|
|
cb->changePrimSkill(heroID,subid,val);
|
2008-08-04 18:56:36 +03:00
|
|
|
InfoWindow iw;
|
2008-08-22 15:21:09 +03:00
|
|
|
iw.components.push_back(Component(0,subid,val,0));
|
2008-08-04 18:56:36 +03:00
|
|
|
iw.text << std::pair<ui8,ui32>(11,ot);
|
2008-08-26 00:14:00 +03:00
|
|
|
iw.player = cb->getOwner(heroID);
|
2008-08-04 18:56:36 +03:00
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
break;
|
2007-12-25 18:25:53 +02:00
|
|
|
}
|
2008-08-22 15:21:09 +03:00
|
|
|
case 100: //give exp
|
2007-12-25 18:25:53 +02:00
|
|
|
{
|
2008-08-04 18:56:36 +03:00
|
|
|
InfoWindow iw;
|
2008-08-22 15:21:09 +03:00
|
|
|
iw.components.push_back(Component(id,subid,val,0));
|
2008-08-26 00:14:00 +03:00
|
|
|
iw.player = cb->getOwner(heroID);
|
2008-08-04 18:56:36 +03:00
|
|
|
iw.text << std::pair<ui8,ui32>(11,ot);
|
|
|
|
cb->showInfoDialog(&iw);
|
2008-08-22 15:21:09 +03:00
|
|
|
cb->changePrimSkill(heroID,4,val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 102:
|
|
|
|
{
|
|
|
|
const CGHeroInstance *h = cb->getHero(heroID);
|
2008-11-01 00:41:22 +02:00
|
|
|
val = VLC->heroh->reqExp(h->level+val) - VLC->heroh->reqExp(h->level);
|
2008-08-22 15:21:09 +03:00
|
|
|
if(!typeOfTree[objid])
|
|
|
|
{
|
|
|
|
visitors[objid].insert(heroID);
|
|
|
|
InfoWindow iw;
|
|
|
|
iw.components.push_back(Component(id,subid,1,0));
|
2008-08-26 00:14:00 +03:00
|
|
|
iw.player = cb->getOwner(heroID);
|
2008-08-22 15:21:09 +03:00
|
|
|
iw.text << std::pair<ui8,ui32>(11,148);
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
cb->changePrimSkill(heroID,4,val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int res, resval;
|
|
|
|
if(typeOfTree[objid]==1)
|
|
|
|
{
|
|
|
|
res = 6;
|
|
|
|
resval = 2000;
|
|
|
|
ot = 149;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = 5;
|
|
|
|
resval = 10;
|
|
|
|
ot = 151;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(cb->getResource(h->tempOwner,res) < resval) //not enough resources
|
|
|
|
{
|
|
|
|
ot++;
|
|
|
|
InfoWindow iw;
|
|
|
|
iw.player = h->tempOwner;
|
|
|
|
iw.text << std::pair<ui8,ui32>(11,ot);
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
YesNoDialog sd;
|
2008-08-26 00:14:00 +03:00
|
|
|
sd.player = cb->getOwner(heroID);
|
2008-08-22 15:21:09 +03:00
|
|
|
sd.text << std::pair<ui8,ui32>(11,ot);
|
|
|
|
sd.components.push_back(Component(id,subid,val,0));
|
|
|
|
cb->showYesNoDialog(&sd,CFunctionList<void(ui32)>(boost::bind(&CVisitableOPH::treeSelected,this,objid,heroID,res,resval,val,_1)));
|
|
|
|
}
|
2008-08-04 18:56:36 +03:00
|
|
|
break;
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-24 00:33:55 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ot++;
|
2008-08-04 18:56:36 +03:00
|
|
|
InfoWindow iw;
|
2008-08-26 00:14:00 +03:00
|
|
|
iw.player = cb->getOwner(heroID);
|
2008-08-04 18:56:36 +03:00
|
|
|
iw.text << std::pair<ui8,ui32>(11,ot);
|
|
|
|
cb->showInfoDialog(&iw);
|
2007-11-24 00:33:55 +02:00
|
|
|
}
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> CVisitableOPH::yourObjects()
|
|
|
|
{
|
2008-08-22 15:21:09 +03:00
|
|
|
std::vector<int> ret;
|
|
|
|
ret.push_back(51);//camp
|
|
|
|
ret.push_back(23);//tower
|
|
|
|
ret.push_back(61);//axis
|
|
|
|
ret.push_back(32);//garden
|
|
|
|
ret.push_back(100);//stone
|
|
|
|
ret.push_back(102);//tree
|
2007-11-19 00:58:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-08-22 15:21:09 +03:00
|
|
|
void CVisitableOPH::treeSelected( int objid, int heroID, int resType, int resVal, int expVal, ui32 result )
|
|
|
|
{
|
|
|
|
if(result==0) //player agreed to give res for exp
|
|
|
|
{
|
2008-08-26 00:14:00 +03:00
|
|
|
cb->giveResource(cb->getOwner(heroID),resType,-resVal); //take resource
|
2008-08-22 15:21:09 +03:00
|
|
|
cb->changePrimSkill(heroID,4,expVal); //give exp
|
|
|
|
visitors[objid].insert(heroID); //set state to visited
|
|
|
|
}
|
|
|
|
}
|
2008-07-30 20:51:19 +03:00
|
|
|
void CVisitableOPW::onNAHeroVisit(int objid, int heroID, bool alreadyVisited)
|
2007-11-24 00:33:55 +02:00
|
|
|
{
|
2008-07-31 13:35:22 +03:00
|
|
|
DEFOS;
|
|
|
|
int mid;
|
|
|
|
switch (os->ID)
|
|
|
|
{
|
|
|
|
case 55:
|
|
|
|
mid = 92;
|
|
|
|
break;
|
|
|
|
case 112:
|
|
|
|
mid = 170;
|
|
|
|
break;
|
|
|
|
case 109:
|
|
|
|
mid = 164;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (alreadyVisited)
|
|
|
|
{
|
|
|
|
if (os->ID!=112)
|
|
|
|
mid++;
|
|
|
|
else
|
|
|
|
mid--;
|
|
|
|
|
|
|
|
InfoWindow iw;
|
|
|
|
iw.player = cb->getHero(heroID)->tempOwner;
|
|
|
|
iw.text << std::pair<ui8,ui32>(11,mid);
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int type, sub, val;
|
|
|
|
type = 2;
|
|
|
|
switch (os->ID)
|
|
|
|
{
|
|
|
|
case 55:
|
|
|
|
if (rand()%2)
|
|
|
|
{
|
|
|
|
sub = 5;
|
|
|
|
val = 5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sub = 6;
|
|
|
|
val = 500;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 112:
|
|
|
|
mid = 170;
|
|
|
|
sub = (rand() % 5) + 1;
|
|
|
|
val = (rand() % 4) + 3;
|
|
|
|
break;
|
|
|
|
case 109:
|
|
|
|
mid = 164;
|
|
|
|
sub = 6;
|
|
|
|
if(cb->getDate(2)<2)
|
|
|
|
val = 500;
|
|
|
|
else
|
|
|
|
val = 1000;
|
|
|
|
}
|
2008-08-26 00:14:00 +03:00
|
|
|
int player = cb->getOwner(heroID);
|
2008-07-31 13:35:22 +03:00
|
|
|
cb->giveResource(player,sub,val);
|
|
|
|
InfoWindow iw;
|
|
|
|
iw.player = player;
|
|
|
|
iw.components.push_back(Component(type,sub,val,0));
|
|
|
|
iw.text << std::pair<ui8,ui32>(11,mid);
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
visited[objid] = true;
|
|
|
|
MetaString ms; //set text to "visited"
|
|
|
|
ms << std::pair<ui8,ui32>(3,os->ID) << " " << std::pair<ui8,ui32>(1,352);
|
|
|
|
cb->setHoverName(objid,&ms);
|
|
|
|
}
|
2007-11-24 00:33:55 +02:00
|
|
|
}
|
|
|
|
void CVisitableOPW::newTurn ()
|
|
|
|
{
|
2008-07-31 13:35:22 +03:00
|
|
|
if (cb->getDate(1)==1) //first day of week
|
2007-11-24 00:33:55 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
for (std::map<int,bool>::iterator i = visited.begin(); i != visited.end(); i++)
|
2007-11-24 00:33:55 +02:00
|
|
|
{
|
|
|
|
(*i).second = false;
|
2008-07-31 13:35:22 +03:00
|
|
|
MetaString ms; //set text to "not visited"
|
|
|
|
ms << std::pair<ui8,ui32>(3,cb->getObj(i->first)->ID) << " " << std::pair<ui8,ui32>(1,353);
|
|
|
|
cb->setHoverName(i->first,&ms);
|
2007-11-24 00:33:55 +02:00
|
|
|
}
|
2008-07-31 13:35:22 +03:00
|
|
|
|
2007-11-24 00:33:55 +02:00
|
|
|
}
|
|
|
|
}
|
2008-07-30 20:51:19 +03:00
|
|
|
void CVisitableOPW::newObject(int objid)
|
2007-11-24 00:33:55 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
visited.insert(std::pair<int,bool>(objid,false));
|
|
|
|
DEFOS;
|
|
|
|
MetaString ms;
|
|
|
|
ms << std::pair<ui8,ui32>(3,os->ID) << " " << std::pair<ui8,ui32>(1,visited[objid] ? 352 : 353);
|
|
|
|
cb->setHoverName(objid,&ms);
|
2007-11-24 00:33:55 +02:00
|
|
|
}
|
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
void CVisitableOPW::onHeroVisit(int objid, int heroID)
|
2007-11-24 00:33:55 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
if(visited[objid])
|
|
|
|
onNAHeroVisit(objid,heroID,true);
|
2007-11-24 00:33:55 +02:00
|
|
|
else
|
2008-07-30 20:51:19 +03:00
|
|
|
onNAHeroVisit(objid,heroID,false);
|
2007-11-24 00:33:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> CVisitableOPW::yourObjects() //returns IDs of objects which are handled by script
|
|
|
|
{
|
|
|
|
std::vector<int> ret(3);
|
|
|
|
ret.push_back(55); //mystical garden
|
|
|
|
ret.push_back(112); //windmill
|
|
|
|
ret.push_back(109); //water wheel
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
void CMines::newObject(int objid)
|
|
|
|
{
|
|
|
|
ourObjs.push_back(objid);
|
|
|
|
cb->setOwner(objid,NEUTRAL_PLAYER);
|
|
|
|
DEFOS;
|
|
|
|
MetaString ms;
|
|
|
|
ms << std::pair<ui8,ui32>(3,os->ID);
|
|
|
|
cb->setHoverName(objid,&ms);
|
|
|
|
}
|
|
|
|
void CMines::onHeroVisit(int objid, int heroID)
|
|
|
|
{
|
2008-07-31 00:27:15 +03:00
|
|
|
//TODO: this is code for standard mines, no support for abandoned mine (subId==7)
|
2008-07-30 20:51:19 +03:00
|
|
|
DEFOS;
|
2008-09-01 03:25:36 +03:00
|
|
|
if(os->subID==7)
|
|
|
|
return;
|
2008-07-30 20:51:19 +03:00
|
|
|
const CGHeroInstance *h = cb->getHero(heroID);
|
2008-07-31 13:35:22 +03:00
|
|
|
if(h->tempOwner == os->tempOwner)
|
|
|
|
return; //TODO: leaving garrison
|
2008-07-30 20:51:19 +03:00
|
|
|
cb->setOwner(objid,h->tempOwner);
|
|
|
|
MetaString ms;
|
|
|
|
ms << std::pair<ui8,ui32>(9,os->subID) << " " << std::pair<ui8,ui32>(6,23+h->tempOwner);
|
|
|
|
cb->setHoverName(objid,&ms);
|
2008-07-31 00:27:15 +03:00
|
|
|
ms.clear();
|
|
|
|
|
|
|
|
int vv=1; //amount of resource per turn
|
|
|
|
if (os->subID==0 || os->subID==2)
|
|
|
|
vv++;
|
|
|
|
else if (os->subID==6)
|
|
|
|
vv = 1000;
|
|
|
|
|
|
|
|
InfoWindow iw;
|
|
|
|
iw.text << std::pair<ui8,ui32>(10,os->subID);
|
|
|
|
iw.player = h->tempOwner;
|
|
|
|
iw.components.push_back(Component(2,os->subID,vv,-1));
|
|
|
|
cb->showInfoDialog(&iw);
|
2007-11-24 16:17:57 +02:00
|
|
|
}
|
|
|
|
std::vector<int> CMines::yourObjects()
|
|
|
|
{
|
2008-07-31 00:27:15 +03:00
|
|
|
std::vector<int> ret;
|
2007-11-24 16:17:57 +02:00
|
|
|
ret.push_back(53);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
void CMines::newTurn ()
|
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
const CGObjectInstance * obj;
|
|
|
|
for (unsigned i=0;i<ourObjs.size();i++)
|
2007-11-24 16:17:57 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
obj = cb->getObj(ourObjs[i]);
|
|
|
|
if (obj->tempOwner == NEUTRAL_PLAYER)
|
2007-11-24 16:17:57 +02:00
|
|
|
continue;
|
|
|
|
int vv = 1;
|
2008-07-30 20:51:19 +03:00
|
|
|
if (obj->subID==0 || obj->subID==2)
|
2007-11-24 16:17:57 +02:00
|
|
|
vv++;
|
2008-07-30 20:51:19 +03:00
|
|
|
else if (obj->subID==6)
|
2007-11-24 16:17:57 +02:00
|
|
|
vv = 1000;
|
2008-07-30 20:51:19 +03:00
|
|
|
cb->giveResource(obj->tempOwner,obj->subID,vv);
|
2007-11-24 16:17:57 +02:00
|
|
|
}
|
2007-11-25 15:16:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
void CPickable::newObject(int objid)
|
2007-11-25 15:16:45 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
cb->setBlockVis(objid,true);
|
|
|
|
|
|
|
|
MetaString ms;
|
|
|
|
DEFOS;
|
|
|
|
switch (os->ID)
|
|
|
|
{
|
|
|
|
case 79:
|
2008-07-31 13:35:22 +03:00
|
|
|
ms << std::pair<ui8,ui32>(4,os->subID);
|
2008-07-30 20:51:19 +03:00
|
|
|
break;
|
|
|
|
case 5:
|
2008-07-31 13:35:22 +03:00
|
|
|
ms << std::pair<ui8,ui32>(5,os->subID);
|
2008-07-30 20:51:19 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ms << std::pair<ui8,ui32>(3,os->ID);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cb->setHoverName(objid,&ms);
|
2007-11-25 15:16:45 +02:00
|
|
|
}
|
2008-07-30 20:51:19 +03:00
|
|
|
void CPickable::onHeroVisit(int objid, int heroID)
|
2007-11-25 15:16:45 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
DEFOS;
|
2007-11-25 15:16:45 +02:00
|
|
|
switch(os->ID)
|
|
|
|
{
|
2008-08-13 03:44:31 +03:00
|
|
|
case 5: //artifact
|
2008-02-07 20:45:22 +02:00
|
|
|
{
|
2008-09-29 00:01:49 +03:00
|
|
|
cb->giveHeroArtifact(os->subID,heroID,-2);
|
2008-08-25 13:25:16 +03:00
|
|
|
InfoWindow iw;
|
2008-08-26 00:14:00 +03:00
|
|
|
iw.player = cb->getOwner(heroID);
|
2008-08-25 13:25:16 +03:00
|
|
|
iw.components.push_back(Component(4,os->subID,0,0));
|
|
|
|
iw.text << std::pair<ui8,ui32>(12,os->subID);
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 12: //campfire
|
|
|
|
{
|
|
|
|
int val = (rand()%3) + 4, //4 - 6
|
|
|
|
res = rand()%6,
|
2008-08-26 00:14:00 +03:00
|
|
|
owner = cb->getOwner(heroID);
|
2008-08-25 13:25:16 +03:00
|
|
|
cb->giveResource(owner,res,val); //non-gold resource
|
|
|
|
cb->giveResource(owner,6,val*100);//gold
|
|
|
|
InfoWindow iw;
|
|
|
|
iw.player = owner;
|
|
|
|
iw.components.push_back(Component(2,6,val*100,0));
|
|
|
|
iw.components.push_back(Component(2,res,val,0));
|
|
|
|
iw.text << std::pair<ui8,ui32>(11,23);
|
|
|
|
cb->showInfoDialog(&iw);
|
2008-02-07 20:45:22 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-08-13 03:44:31 +03:00
|
|
|
case 79: //resource
|
2007-11-25 15:16:45 +02:00
|
|
|
{
|
2008-08-04 18:56:36 +03:00
|
|
|
//TODO: handle guards (when battles are finished)
|
|
|
|
CResourceObjInfo * t2 = static_cast<CResourceObjInfo *>(os->info);
|
|
|
|
int val;
|
|
|
|
if(t2->amount)
|
|
|
|
val = t2->amount;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(os->subID)
|
|
|
|
{
|
|
|
|
case 6:
|
|
|
|
val = 500 + (rand()%6)*100;
|
|
|
|
break;
|
|
|
|
case 0: case 2:
|
|
|
|
val = 6 + (rand()%5);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
val = 3 + (rand()%3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(t2->message.length())
|
|
|
|
{
|
|
|
|
InfoWindow iw;
|
|
|
|
iw.player = cb->getHero(heroID)->tempOwner;
|
|
|
|
iw.text << t2->message;
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
}
|
|
|
|
|
2008-08-26 00:14:00 +03:00
|
|
|
cb->giveResource(cb->getOwner(heroID),os->subID,val);
|
2008-08-04 18:56:36 +03:00
|
|
|
|
|
|
|
ShowInInfobox sii;
|
2008-08-26 00:14:00 +03:00
|
|
|
sii.player = cb->getOwner(heroID);
|
2008-08-04 18:56:36 +03:00
|
|
|
sii.c = Component(2,os->subID,val,0);
|
|
|
|
sii.text << std::pair<ui8,ui32>(11,113);
|
|
|
|
sii.text.replacements.push_back(VLC->objh->restypes[os->subID]);
|
|
|
|
cb->showCompInfo(&sii);
|
2007-11-25 15:16:45 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-08-13 03:44:31 +03:00
|
|
|
case 101: //treasure chest
|
2007-12-25 18:25:53 +02:00
|
|
|
{
|
2008-08-13 03:44:31 +03:00
|
|
|
if (os->subID) //not OH3 treasure chest
|
|
|
|
break;
|
|
|
|
int wyn = rand()%100, val=0;
|
|
|
|
if (wyn<32) //1k/0.5k
|
|
|
|
{
|
|
|
|
val = 1000;
|
|
|
|
}
|
|
|
|
else if(wyn<64) //1.5k/1k
|
|
|
|
{
|
|
|
|
val = 1500;
|
|
|
|
}
|
|
|
|
else if(wyn<95) //2k/1.5k
|
|
|
|
{
|
|
|
|
val = 2000;
|
|
|
|
}
|
|
|
|
else //random treasure artifact, or (if backapack is full) 1k/0.5k
|
|
|
|
{
|
|
|
|
if (1/*TODO: backpack is full*/)
|
|
|
|
{
|
|
|
|
val = 1000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//TODO: give treasure artifact
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SelectionDialog sd;
|
2008-08-26 00:14:00 +03:00
|
|
|
sd.player = cb->getOwner(heroID);
|
2008-08-13 03:44:31 +03:00
|
|
|
sd.text << std::pair<ui8,ui32>(11,146);
|
|
|
|
sd.components.push_back(Component(2,6,val,0));
|
|
|
|
sd.components.push_back(Component(5,0,val-500,0));
|
|
|
|
boost::function<void(ui32)> fun = boost::bind(&CPickable::chosen,this,_1,heroID,val);
|
|
|
|
cb->showSelectionDialog(&sd,fun);
|
2007-12-25 18:25:53 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-11-25 15:16:45 +02:00
|
|
|
}
|
2008-08-13 07:41:11 +03:00
|
|
|
cb->removeObject(objid);
|
2007-11-25 15:16:45 +02:00
|
|
|
}
|
2008-08-13 03:44:31 +03:00
|
|
|
void CPickable::chosen(ui32 which, int heroid, int val)
|
2007-12-25 18:25:53 +02:00
|
|
|
{
|
2008-08-13 03:44:31 +03:00
|
|
|
switch(which)
|
|
|
|
{
|
|
|
|
case 0: //player pick gold
|
2008-08-26 00:14:00 +03:00
|
|
|
cb->giveResource(cb->getOwner(heroid),6,val);
|
2008-08-13 03:44:31 +03:00
|
|
|
break;
|
|
|
|
case 1: //player pick exp
|
|
|
|
cb->changePrimSkill(heroid, 4, val-500);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw std::string("Unhandled choice");
|
|
|
|
}
|
2007-11-25 15:16:45 +02:00
|
|
|
}
|
2008-03-10 01:06:35 +02:00
|
|
|
|
2007-11-25 15:16:45 +02:00
|
|
|
std::vector<int> CPickable::yourObjects() //returns IDs of objects which are handled by script
|
|
|
|
{
|
2008-08-22 15:21:09 +03:00
|
|
|
std::vector<int> ret;
|
2007-11-25 15:16:45 +02:00
|
|
|
ret.push_back(79); //resource
|
|
|
|
ret.push_back(5); //artifact
|
2008-08-25 13:25:16 +03:00
|
|
|
ret.push_back(12); //resource
|
2007-11-25 15:16:45 +02:00
|
|
|
ret.push_back(101); //treasure chest / commander stone
|
|
|
|
return ret;
|
2008-01-28 16:01:09 +02:00
|
|
|
}
|
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
void CTownScript::onHeroVisit(int objid, int heroID)
|
2008-01-28 16:01:09 +02:00
|
|
|
{
|
2008-09-12 11:51:46 +03:00
|
|
|
DEFOS;
|
2008-08-27 13:19:18 +03:00
|
|
|
if(cb->getOwner(objid)!=cb->getOwner(heroID))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2008-07-30 20:51:19 +03:00
|
|
|
cb->heroVisitCastle(objid,heroID);
|
2008-01-28 16:01:09 +02:00
|
|
|
}
|
2008-07-30 20:51:19 +03:00
|
|
|
|
|
|
|
void CTownScript::newObject(int objid)
|
2008-01-28 16:01:09 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
MetaString ms;
|
|
|
|
const CGTownInstance * n = cb->getTown(objid);
|
|
|
|
ms << n->name << ", " << n->town->name;
|
|
|
|
cb->setHoverName(objid,&ms);
|
2008-01-28 16:01:09 +02:00
|
|
|
}
|
2008-07-30 20:51:19 +03:00
|
|
|
|
|
|
|
void CTownScript::onHeroLeave(int objid, int heroID)
|
2008-01-28 16:01:09 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
cb->stopHeroVisitCastle(objid,heroID);
|
2008-01-28 16:01:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> CTownScript::yourObjects() //returns IDs of objects which are handled by script
|
|
|
|
{
|
|
|
|
std::vector<int> ret(1);
|
|
|
|
ret.push_back(98); //town
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-25 01:06:27 +02:00
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
void CHeroScript::newObject(int objid)
|
2008-02-25 01:06:27 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
cb->setBlockVis(objid,true);
|
2008-08-02 13:25:58 +03:00
|
|
|
MetaString ms;
|
|
|
|
ms << std::pair<ui8,ui32>(1,15);
|
|
|
|
ms.replacements.push_back(cb->getHero(objid)->name);
|
|
|
|
ms.replacements.push_back(cb->getHero(objid)->type->heroClass->name);
|
|
|
|
cb->setHoverName(objid,&ms);
|
2008-02-25 01:06:27 +02:00
|
|
|
}
|
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
void CHeroScript::onHeroVisit(int objid, int heroID)
|
2008-02-25 01:06:27 +02:00
|
|
|
{
|
|
|
|
//TODO: check for allies
|
2008-07-30 20:51:19 +03:00
|
|
|
const CGHeroInstance *my = cb->getHero(objid),
|
2008-09-17 20:13:01 +03:00
|
|
|
*vis = cb->getHero(heroID);
|
2008-07-30 20:51:19 +03:00
|
|
|
if(my->tempOwner == vis->tempOwner) //one of allied cases
|
2008-02-26 20:01:26 +02:00
|
|
|
{
|
|
|
|
//exchange
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-02-28 19:00:16 +02:00
|
|
|
cb->startBattle(
|
2008-07-30 20:51:19 +03:00
|
|
|
&vis->army,
|
2008-09-17 20:13:01 +03:00
|
|
|
&my->army,
|
|
|
|
vis->pos,
|
2008-09-12 11:51:46 +03:00
|
|
|
vis,
|
2008-09-17 20:13:01 +03:00
|
|
|
my,
|
2008-09-12 11:51:46 +03:00
|
|
|
0);
|
2008-02-26 20:01:26 +02:00
|
|
|
}
|
2008-02-25 01:06:27 +02:00
|
|
|
}
|
|
|
|
std::vector<int> CHeroScript::yourObjects() //returns IDs of objects which are handled by script
|
|
|
|
{
|
2008-08-22 15:21:09 +03:00
|
|
|
std::vector<int> ret;
|
2008-03-01 00:14:53 +02:00
|
|
|
ret.push_back(34); //hero
|
2008-02-25 01:06:27 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2008-07-30 20:51:19 +03:00
|
|
|
void CMonsterS::newObject(int objid)
|
2008-02-25 01:06:27 +02:00
|
|
|
{
|
2008-03-01 00:14:53 +02:00
|
|
|
//os->blockVisit = true;
|
2008-07-30 20:51:19 +03:00
|
|
|
DEFOS;
|
|
|
|
switch(VLC->creh->creatures[os->subID].level)
|
2008-02-25 01:06:27 +02:00
|
|
|
{
|
|
|
|
case 1:
|
2008-09-20 21:30:37 +03:00
|
|
|
cb->setAmount(objid,rand()%31+20);
|
2008-02-25 01:06:27 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2008-09-20 21:30:37 +03:00
|
|
|
cb->setAmount(objid,rand()%16+15);
|
2008-02-25 01:06:27 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2008-09-20 21:30:37 +03:00
|
|
|
cb->setAmount(objid,rand()%16+10);
|
2008-02-25 01:06:27 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
2008-09-20 21:30:37 +03:00
|
|
|
cb->setAmount(objid,rand()%11+10);
|
2008-02-25 01:06:27 +02:00
|
|
|
break;
|
|
|
|
case 5:
|
2008-09-20 21:30:37 +03:00
|
|
|
cb->setAmount(objid,rand()%9+8);
|
2008-02-25 01:06:27 +02:00
|
|
|
break;
|
|
|
|
case 6:
|
2008-09-20 21:30:37 +03:00
|
|
|
cb->setAmount(objid,rand()%8+5);
|
2008-02-25 01:06:27 +02:00
|
|
|
break;
|
|
|
|
case 7:
|
2008-09-20 21:30:37 +03:00
|
|
|
cb->setAmount(objid,rand()%7+3);
|
2008-02-25 01:06:27 +02:00
|
|
|
break;
|
|
|
|
case 8:
|
2008-09-20 21:30:37 +03:00
|
|
|
cb->setAmount(objid,rand()%4+2);
|
2008-02-25 01:06:27 +02:00
|
|
|
break;
|
|
|
|
case 9:
|
2008-09-20 21:30:37 +03:00
|
|
|
cb->setAmount(objid,rand()%3+2);
|
2008-02-25 01:06:27 +02:00
|
|
|
break;
|
|
|
|
case 10:
|
2008-09-20 21:30:37 +03:00
|
|
|
cb->setAmount(objid,rand()%3+1);
|
2008-02-25 01:06:27 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
MetaString ms;
|
2008-09-20 21:30:37 +03:00
|
|
|
int pom = CCreature::getQuantityID(((CCreatureObjInfo*)(os->info))->number);
|
2008-02-25 01:06:27 +02:00
|
|
|
pom = 174 + 3*pom + 1;
|
2008-07-30 20:51:19 +03:00
|
|
|
ms << std::pair<ui8,ui32>(6,pom) << " " << std::pair<ui8,ui32>(7,os->subID);
|
|
|
|
cb->setHoverName(objid,&ms);
|
2008-02-25 01:06:27 +02:00
|
|
|
}
|
2008-07-30 20:51:19 +03:00
|
|
|
void CMonsterS::onHeroVisit(int objid, int heroID)
|
2008-02-25 01:06:27 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
DEFOS;
|
2008-02-25 01:06:27 +02:00
|
|
|
CCreatureSet set;
|
|
|
|
//TODO: zrobic secik w sposob wyrafinowany
|
2008-09-20 21:30:37 +03:00
|
|
|
set.slots[0] = std::pair<ui32,si32>(os->subID,((CCreatureObjInfo*)(os->info))->number);
|
2008-09-12 11:51:46 +03:00
|
|
|
cb->startBattle(heroID,set,os->pos,boost::bind(&CMonsterS::endBattleWith,this,os,_1));
|
2008-02-25 01:06:27 +02:00
|
|
|
}
|
|
|
|
std::vector<int> CMonsterS::yourObjects() //returns IDs of objects which are handled by script
|
|
|
|
{
|
2008-08-22 15:21:09 +03:00
|
|
|
std::vector<int> ret;
|
2008-03-01 00:14:53 +02:00
|
|
|
ret.push_back(54); //monster
|
2008-02-25 01:06:27 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2008-03-01 00:14:53 +02:00
|
|
|
|
2008-09-12 11:51:46 +03:00
|
|
|
void CMonsterS::endBattleWith(const CGObjectInstance *monster, BattleResult *result )
|
|
|
|
{
|
|
|
|
if(result->winner==0)
|
|
|
|
{
|
|
|
|
cb->removeObject(monster->id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-09-20 21:30:37 +03:00
|
|
|
int killedAmount=0;
|
|
|
|
for(std::set<std::pair<ui32,si32> >::iterator i=result->casualties[1].begin(); i!=result->casualties[1].end(); i++)
|
|
|
|
if(i->first == monster->subID)
|
|
|
|
killedAmount += i->second;
|
|
|
|
cb->setAmount(monster->id,((CCreatureObjInfo*)(monster->info))->number - killedAmount);
|
2008-09-12 11:51:46 +03:00
|
|
|
}
|
|
|
|
}
|
2008-03-01 00:14:53 +02:00
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
void CCreatureGen::newObject(int objid)
|
2008-03-01 00:14:53 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
DEFOS;
|
|
|
|
amount[objid] = VLC->creh->creatures[VLC->objh->cregens[os->subID]].growth;
|
|
|
|
MetaString ms;
|
|
|
|
ms << std::pair<ui8,ui32>(8,os->subID);
|
|
|
|
cb->setHoverName(objid,&ms);
|
2008-03-01 00:14:53 +02:00
|
|
|
}
|
2008-07-30 20:51:19 +03:00
|
|
|
void CCreatureGen::onHeroVisit(int objid, int heroID)
|
2008-03-01 00:14:53 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
std::vector<int> CCreatureGen::yourObjects() //returns IDs of objects which are handled by script
|
|
|
|
{
|
2008-09-23 13:58:54 +03:00
|
|
|
std::vector<int> ret;
|
2008-03-01 00:14:53 +02:00
|
|
|
ret.push_back(17); //cregen1
|
|
|
|
return ret;
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|
2008-09-23 13:58:54 +03:00
|
|
|
|
|
|
|
void CTeleports::newObject(int objid)
|
|
|
|
{
|
|
|
|
DEFOS;
|
|
|
|
objs[os->ID][os->subID].push_back(objid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTeleports::onHeroVisit(int objid, int heroID)
|
|
|
|
{
|
|
|
|
DEFOS;
|
|
|
|
int destinationid=-1;
|
|
|
|
switch(os->ID)
|
|
|
|
{
|
|
|
|
case 43: //one way - find correspong exit monolith
|
|
|
|
if(vstd::contains(objs,44) && vstd::contains(objs[44],os->subID) && objs[44][os->subID].size())
|
|
|
|
destinationid = objs[44][os->subID][rand()%objs[44][os->subID].size()];
|
|
|
|
else
|
|
|
|
tlog2 << "Cannot find corresponding exit monolith for "<<objid << std::endl;
|
|
|
|
break;
|
|
|
|
case 45: //two way monolith - pick any other one
|
|
|
|
if(vstd::contains(objs,45) && vstd::contains(objs[45],os->subID) && objs[45][os->subID].size()>1)
|
|
|
|
while ((destinationid = objs[45][os->subID][rand()%objs[45][os->subID].size()])==objid);
|
|
|
|
else
|
|
|
|
tlog2 << "Cannot find corresponding exit monolith for "<<objid << std::endl;
|
|
|
|
break;
|
|
|
|
case 103: //find nearest subterranean gate on the other level
|
|
|
|
{
|
|
|
|
std::pair<int,double> best(-1,150000); //pair<id,dist>
|
|
|
|
for(int i=0; i<objs[103][0].size(); i++)
|
|
|
|
{
|
|
|
|
if(cb->getObj(objs[103][0][i])->pos.z == os->pos.z) continue; //gates on our level are not interesting
|
|
|
|
double hlp = cb->getObj(objs[103][0][i])->pos.dist2d(os->pos);
|
|
|
|
if(hlp<best.second)
|
|
|
|
{
|
|
|
|
best.first = objs[103][0][i];
|
|
|
|
best.second = hlp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(best.first<0)
|
|
|
|
return;
|
|
|
|
else
|
|
|
|
destinationid = best.first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(destinationid < 0)
|
|
|
|
{
|
|
|
|
tlog2 << "Cannot find exit... :( \n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cb->moveHero(heroID,(os->ID!=103)
|
|
|
|
?(CGHeroInstance::convertPosition(cb->getObj(destinationid)->pos,true))
|
|
|
|
:(cb->getObj(destinationid)->pos),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> CTeleports::yourObjects() //returns IDs of objects which are handled by script
|
|
|
|
{
|
|
|
|
std::vector<int> ret;
|
|
|
|
ret.push_back(43);
|
|
|
|
ret.push_back(44);
|
|
|
|
ret.push_back(45);
|
|
|
|
ret.push_back(103);
|
|
|
|
return ret;
|
|
|
|
}
|