浏览代码

* done #40, #32, #21
* added files for Lua handler and moved Lua test code

Michał W. Urbańczyk 18 年之前
父节点
当前提交
f1d5e686ce
共有 10 个文件被更改,包括 116 次插入65 次删除
  1. 5 2
      CAdvmapInterface.cpp
  2. 4 3
      CCallback.cpp
  3. 1 0
      CGameInterface.cpp
  4. 56 0
      CLuaHandler.cpp
  5. 19 0
      CLuaHandler.h
  6. 5 56
      CMT.cpp
  7. 11 3
      hch/CAmbarCendamo.cpp
  8. 12 0
      hch/CTownHandler.cpp
  9. 3 1
      hch/CTownHandler.h
  10. 二进制
      manisfest VCMI.txt

+ 5 - 2
CAdvmapInterface.cpp

@@ -514,7 +514,7 @@ void CTownList::draw()
 			continue;
 		}
 
-		blitAtWR(CGI->townh->getPic(items[i]->type),posporx,pospory+i*32);
+		blitAtWR(CGI->townh->getPic(items[i]->town->typeID),posporx,pospory+i*32);
 
 		if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE))
 		{
@@ -961,9 +961,12 @@ void CTerrainRect::show()
 						pn = 20;
 					}
 				}
+
 			}
+			if (  ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->movement)
+				pn+=25;
 			if (pn>=0)
-			{				
+			{			
 				int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
 					y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
 				if (x<0 || y<0 || x>pos.w || y>pos.h)

+ 4 - 3
CCallback.cpp

@@ -102,8 +102,9 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
 		{
 			hero->pos = endpos;
 		}*/
-		//if(CGI->heroh->heroInstances[ID]->movement>=CGI->mh->getCost(stpos, endpos, CGI->heroh->heroInstances[ID]))
+		if((hero->movement>=CGI->mh->getCost(stpos, endpos, hero))  || player==-1)
 		{ //performing move
+			hero->movement-=CGI->mh->getCost(stpos, endpos, hero);
 			int nn=0; //number of interfece of currently browsed player
 			for(std::map<int, PlayerState>::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing
 			{
@@ -115,8 +116,8 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
 				break; //for testing only
 			}
 		}
-		//else
-			//return true; //move ended - no more movement points
+		else
+			return true; //move ended - no more movement points
 		hero->pos = curd.dst;
 		hero->ourObject->pos = curd.dst;
 	}

+ 1 - 0
CGameInterface.cpp

@@ -768,6 +768,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
 	//ho->moveDir = 0; //move ended
 	ho->isStanding = true;
 	//move finished
+	adventureInt->heroList.draw();
 }
 void CPlayerInterface::heroKilled(const CHeroInstance * hero)
 {

+ 56 - 0
CLuaHandler.cpp

@@ -0,0 +1,56 @@
+#include "stdafx.h"
+
+#include "lua.h"
+#include "lualib.h"
+#include "lauxlib.h"
+#include <luabind/luabind.hpp>
+#include <luabind/function.hpp>
+#include <luabind/class.hpp>
+#include "CLuaHandler.h"
+
+void piszpowitanie2(std::string i) //simple global function for testing
+{
+	std::cout<<"powitanie2zc++. Liczba dnia to " << i;
+}
+
+
+CLuaHandler::CLuaHandler()
+{
+}
+CLuaHandler::~CLuaHandler()
+{
+}
+void CLuaHandler::test()
+{
+	int iErr = 0;
+	lua_State *lua = lua_open ();  // Open Lua
+	LUA_OPEN_LIB(lua, luaopen_base);
+	LUA_OPEN_LIB(lua, luaopen_io);
+
+	if ((iErr = luaL_loadfile (lua, "test.lua")) == 0)
+	{
+		
+
+	   // Call main...
+	   if ((iErr = lua_pcall (lua, 0, LUA_MULTRET, 0)) == 0)
+	   {    
+			luabind::open(lua);
+			luabind::module(lua)
+			[
+				luabind::def("powitanie",&piszpowitanie2)
+			];
+
+			//int ret = luabind::call_function<int>(lua, "helloWorld2");
+
+			lua_pushstring (lua, "helloWorld2");
+			lua_gettable (lua, LUA_GLOBALSINDEX);  
+			lua_pcall (lua, 0, 0, 0);
+
+			// Push the function name onto the stack
+			lua_pushstring (lua, "helloWorld");
+			lua_gettable (lua, LUA_GLOBALSINDEX);  
+			lua_pcall (lua, 0, 0, 0);
+		}
+	}
+	lua_close (lua);
+}

+ 19 - 0
CLuaHandler.h

@@ -0,0 +1,19 @@
+#ifndef CLUAHANDLER_H
+#define CLUAHANDLER_H
+#include "global.h"
+#if (LUA_VERSION_NUM < 500)
+#  define LUA_OPEN_LIB(L, lib) lib(L)
+#else
+#  define LUA_OPEN_LIB(L, lib) \
+     lua_pushcfunction((L), lib); \
+     lua_pcall((L), 0, 0, 0);
+#endif
+class CLuaHandler
+{
+public:
+	CLuaHandler();
+	~CLuaHandler();
+
+	void test();
+};
+#endif //CLUAHANDLER_H

+ 5 - 56
CMT.cpp

@@ -43,7 +43,7 @@
 #include "CPathfinder.h"
 #include "CGameState.h"
 #include "CCallback.h"
-
+#include "CLuaHandler.h"
 #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
 #  include <fcntl.h>
 #  include <io.h>
@@ -58,25 +58,6 @@ const char * NAME = "VCMI 0.3 \"Tol Galen\"";
 SDL_Surface * ekran, * screen, * screen2;
 TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
 
-#include "lua.h"
-#include "lualib.h"
-#include "lauxlib.h"
-#include <luabind/luabind.hpp>
-#include <luabind/function.hpp>
-#include <luabind/class.hpp>
-
-#if (LUA_VERSION_NUM < 500)
-#  define LUA_OPEN_LIB(L, lib) lib(L)
-#else
-#  define LUA_OPEN_LIB(L, lib) \
-     lua_pushcfunction((L), lib); \
-     lua_pcall((L), 0, 0, 0);
-#endif
-void piszpowitanie2(std::string i)
-{
-	std::cout<<"powitanie2zc++. Liczba dnia to " << i;
-}
-
 void initGameState(CGameInfo * cgi)
 {
 	cgi->state->day=1;
@@ -170,7 +151,8 @@ void initGameState(CGameInfo * cgi)
 	{
 		CTownInstance * vti = new CTownInstance();
 		(*vti)=*(cgi->townh->townInstances[i]);
-
+		if (vti->name.length()==0) // if town hasn't name we draw it
+			vti->name=vti->town->names[rand()%vti->town->names.size()];
 		
 		cgi->state->players[vti->owner].towns.push_back(vti);
 	}
@@ -178,41 +160,8 @@ void initGameState(CGameInfo * cgi)
 
 int _tmain(int argc, _TCHAR* argv[])
 { 
-
-	int iErr = 0;
-	lua_State *lua = lua_open ();  // Open Lua
-		LUA_OPEN_LIB(lua, luaopen_base);
-		LUA_OPEN_LIB(lua, luaopen_io);
-
-	if ((iErr = luaL_loadfile (lua, "test.lua")) == 0)
-	{
-		
-
-	   // Call main...
-	   if ((iErr = lua_pcall (lua, 0, LUA_MULTRET, 0)) == 0)
-	   {    
-		   luabind::open(lua);
-		   luabind::module(lua)
-			[
-				luabind::def("powitanie",&piszpowitanie2)
-
-			];
-
-	   //int ret = luabind::call_function<int>(lua, "helloWorld2");
-
-		  lua_pushstring (lua, "helloWorld2");
-		  lua_gettable (lua, LUA_GLOBALSINDEX);  
-		  lua_pcall (lua, 0, 0, 0);
-
-		  // Push the function name onto the stack
-		  lua_pushstring (lua, "helloWorld");
-		  lua_gettable (lua, LUA_GLOBALSINDEX);  
-		  lua_pcall (lua, 0, 0, 0);
-	   }
-
-	}
-	lua_close (lua);
-
+	CLuaHandler luatest;
+	luatest.test();
 
 		//CBIKHandler cb;
 		//cb.open("CSECRET.BIK");

+ 11 - 3
hch/CAmbarCendamo.cpp

@@ -1508,14 +1508,14 @@ void CAmbarCendamo::deh3m()
 				nobj->owner = spec->player;
 				nobj->info = spec;
 				//////////// rewriting info to CTownInstance class /////////////////////
-				CTownInstance * nt = new CTownInstance;
+				CTownInstance * nt = new CTownInstance();
 				nt->owner = spec->player;
-				nt->type = CTownHandler::getTypeByDefName(map.defy[nobj->defNumber].name);
+				nt->town = &CGI->townh->towns[CTownHandler::getTypeByDefName(map.defy[nobj->defNumber].name)];
 				nt->builded = 0;
 				nt->destroyed = 0;
 				nt->name = spec->name;
 				nt->garrison = spec->garrison;
-				nt->garrisonHero = spec->garnisonHero;
+				nt->garrisonHero = NULL;// spec->garnisonHero is not readed - TODO: readit
 				nt->pos = int3(spec->x, spec->y, spec->z);
 				nt->possibleSpells = spec->possibleSpells;
 				nt->obligatorySpells = spec->obligatorySpells;
@@ -2844,6 +2844,14 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					{
 						town1DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
 					}
+					for (int ij=0;ij<CGI->townh->townInstances.size();ij++) // wyharatac gdy bedzie dziedziczenie
+					{
+						if (CGI->townh->townInstances[ij]->pos==CGI->objh->objInstances[j]->pos)
+						{
+							CGI->townh->townInstances[ij]->town = &CGI->townh->towns[nxt.bytes[20]];
+							break;
+						}
+					}
 				}
 				//((CCastleObjInfo*)CGI->objh->objInstances[j].info)
 				break;

+ 12 - 0
hch/CTownHandler.cpp

@@ -17,6 +17,7 @@ void CTownHandler::loadNames()
 	std::istringstream ins, names;
 	ins.str(CGI->bitmaph->getTextFile("TOWNTYPE.TXT"));
 	names.str(CGI->bitmaph->getTextFile("TOWNNAME.TXT"));
+	int si=0;
 	while (!ins.eof())
 	{
 		CTown town;
@@ -27,6 +28,7 @@ void CTownHandler::loadNames()
 			names.getline(bufname,50);
 			town.names.push_back(std::string(bufname));
 		}
+		town.typeID=si++;
 		town.bonus=towns.size();
 		if (town.bonus==8) town.bonus=3; 
 		if (town.name.length())
@@ -60,3 +62,13 @@ int CTownHandler::getTypeByDefName(std::string name)
 	//TODO
 	return 0;
 }
+
+CTownInstance::CTownInstance()
+  :pos(-1,-1,-1)
+{
+	builded=-1;
+	destroyed=-1;
+	garrisonHero=NULL;
+	owner=-1;
+	town=NULL;
+}

+ 3 - 1
hch/CTownHandler.h

@@ -19,6 +19,7 @@ public:
 	std::string name; //name of type
 	std::vector<std::string> names; //names of the town instances
 	int bonus; //pic number
+	int typeID;
 };
 
 class CTownHandler
@@ -39,7 +40,6 @@ public:
 class CTownInstance
 {
 public:
-	int type; //type of town
 	int owner; //ID of owner
 	int3 pos; //position
 	CTown * town;
@@ -56,6 +56,8 @@ public:
 	CHero * garrisonHero;
 
 	std::vector<CSpell *> possibleSpells, obligatorySpells, availableSpells;
+
+	CTownInstance();
 };
 
 #endif //CTOWNHANDLER_H

二进制
manisfest VCMI.txt