Keeping track of things in Multiplayer
by Pauliver · in Torque Game Builder · 06/18/2006 (4:26 pm) · 4 replies
I am designing Risk in T2D, i have my map done and i have mouse/keyboard controlled movement working. I don't expect to have any trouble with the user gui, HOWEVER i am stuck on data/class -esk management.
I have over 50 territories on the risk board, however as the risk board is just an image i was really hoping to use datablocks to manage my data.
My original idea was to use some sort of data structure (script only) to track which country can attack which other country, and then i was hoping i could use some graphical
data structure (something that also had an image & scripting) to keep track of which player has which country, and how many armys they had.
This was going to be my backend (the structure of it):
//========================================================================
// CountryHashMap (maps a name to an ID, and vice versa)
//========================================================================
datablock t2dBaseDatablock(CountryArray)
{
CountryCount = 0;
CountryID = 0;
};
datablock t2dBaseDatablock(CountryDataItem)
{
Name = "";
ID = 0;
Continent = "";
AdjoinedCountries=new GameBaseData()
{
datablock = CountryArray;
};
};
function CountryArray::AddLink(%this,%countryID)
{
if(%countryId != 0 )
{
%this.CountryID[%this.CountryCount]= %countryID;
%this.CountryCount++;
}
}
//========================================================================
// CountryHashMap (maps a name to an ID, and vice versa)
//========================================================================
datablock GameBaseData(CountryHashMap)
{
CountryCount = 0;
CountryID = 0;
CountryName = "";
};
function CountryHashMap::AddCountry(%this,%CountryID,%CountryName)
{
%this.CountryID[%CountryName] = %CountryID;
%this.CountryName[%CountryID] = %CountryName;
%this.CountryCount++;
}
function CountryHashMap::GetCountryById(%this,%countryID)
{
return %this.CountryName[%countryID];
}
function CountryHashMap::GetCountryByName(%this,%countryName)
{
return %this.CountryID[%countryName];
}
//========================================================================
// CountryHashMap (maps a name to an ID, and vice versa)
//========================================================================
datablock GameBaseData(CountryArray)
{
CountryCount = 0;
CountryVector = 0;
HashMap = new GameBaseData()
{
datablock=CountryHashMap;
};
};
function CountryArray::Add(%this,%country)
{
%this.HashMap.AddCountry(%country.ID,%country.Name);
%this.CountryVector[%country.ID] = %country;
%this.CountryCount++;
}
function CountryArray::GetCountryById(%this,%countryID)
{
return %this.CountryVector[%countryID];
}
function CountryArray::GetCountryByName(%this,%CountryName)
{
return %this.CountryVector[%this.Hashmap.GetCountryByName(%CountryName)];
}
It didn't work...
I'm trying to avoid doing this in c++ for my demo [I'm part of a school of thought that believes that you should always write a demo first, then do it once after you have everything figured out]. After i have it working the first time i'll write it again using C++ and hopefully custom.
So yeah if someone could toss me an idea or a hint of how they would do the following
Keep track of who controls which territory, how many armys they have on it, and what adjoining territories connect to the selected territory, i would greatly appreciate it. (preferrably in some kind of DataBlock so that the engine keeps them synchronized between clients).
If anyone is interested to see what i have so far i'll be happy to package it and upload it.
Thanks for all your help.
I have over 50 territories on the risk board, however as the risk board is just an image i was really hoping to use datablocks to manage my data.
My original idea was to use some sort of data structure (script only) to track which country can attack which other country, and then i was hoping i could use some graphical
data structure (something that also had an image & scripting) to keep track of which player has which country, and how many armys they had.
This was going to be my backend (the structure of it):
//========================================================================
// CountryHashMap (maps a name to an ID, and vice versa)
//========================================================================
datablock t2dBaseDatablock(CountryArray)
{
CountryCount = 0;
CountryID = 0;
};
datablock t2dBaseDatablock(CountryDataItem)
{
Name = "";
ID = 0;
Continent = "";
AdjoinedCountries=new GameBaseData()
{
datablock = CountryArray;
};
};
function CountryArray::AddLink(%this,%countryID)
{
if(%countryId != 0 )
{
%this.CountryID[%this.CountryCount]= %countryID;
%this.CountryCount++;
}
}
//========================================================================
// CountryHashMap (maps a name to an ID, and vice versa)
//========================================================================
datablock GameBaseData(CountryHashMap)
{
CountryCount = 0;
CountryID = 0;
CountryName = "";
};
function CountryHashMap::AddCountry(%this,%CountryID,%CountryName)
{
%this.CountryID[%CountryName] = %CountryID;
%this.CountryName[%CountryID] = %CountryName;
%this.CountryCount++;
}
function CountryHashMap::GetCountryById(%this,%countryID)
{
return %this.CountryName[%countryID];
}
function CountryHashMap::GetCountryByName(%this,%countryName)
{
return %this.CountryID[%countryName];
}
//========================================================================
// CountryHashMap (maps a name to an ID, and vice versa)
//========================================================================
datablock GameBaseData(CountryArray)
{
CountryCount = 0;
CountryVector = 0;
HashMap = new GameBaseData()
{
datablock=CountryHashMap;
};
};
function CountryArray::Add(%this,%country)
{
%this.HashMap.AddCountry(%country.ID,%country.Name);
%this.CountryVector[%country.ID] = %country;
%this.CountryCount++;
}
function CountryArray::GetCountryById(%this,%countryID)
{
return %this.CountryVector[%countryID];
}
function CountryArray::GetCountryByName(%this,%CountryName)
{
return %this.CountryVector[%this.Hashmap.GetCountryByName(%CountryName)];
}
It didn't work...
I'm trying to avoid doing this in c++ for my demo [I'm part of a school of thought that believes that you should always write a demo first, then do it once after you have everything figured out]. After i have it working the first time i'll write it again using C++ and hopefully custom.
So yeah if someone could toss me an idea or a hint of how they would do the following
Keep track of who controls which territory, how many armys they have on it, and what adjoining territories connect to the selected territory, i would greatly appreciate it. (preferrably in some kind of DataBlock so that the engine keeps them synchronized between clients).
If anyone is interested to see what i have so far i'll be happy to package it and upload it.
Thanks for all your help.
#2
I have 2 more simple questions
1) are simgroups synchronized over the network by the engine?
2) can you add an onclick event to the t2dstaticsprites or will i just have to compare the position of the mouse::down event with the position of the image of the static sprite?
thank you again for all your help.
06/19/2006 (8:30 am)
Thank you, that was very helpfullI have 2 more simple questions
1) are simgroups synchronized over the network by the engine?
2) can you add an onclick event to the t2dstaticsprites or will i just have to compare the position of the mouse::down event with the position of the image of the static sprite?
thank you again for all your help.
#3
1) NFI, never looked into it. AFAIK, nothing is really "synchronized" over the network. By that I mean you have to specifically pass things to the client using the commandToClien() function. That being said, I don't see why you can't pass the details of a SimObject to the client, although it would be better if the client had the same country details as the server.
2) Compare the mouse down event. Use something like this:
I think that should be right, too early in the morning :-P
06/20/2006 (1:02 pm)
Pauliver,1) NFI, never looked into it. AFAIK, nothing is really "synchronized" over the network. By that I mean you have to specifically pass things to the client using the commandToClien() function. That being said, I don't see why you can't pass the details of a SimObject to the client, although it would be better if the client had the same country details as the server.
2) Compare the mouse down event. Use something like this:
onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
for (%i = 0; %i < Country.getCount(); %i++)
{
%currentCountry = Country.getObject(%i);
if %currentCountry.getPosition() = %worldPosition
{
doSelectFunction();
}
}
}I think that should be right, too early in the morning :-P
#4
06/20/2006 (2:06 pm)
Objects only "synchronize" over the network if you are using TGE networking, which stock TGB does not have. In either case, SimGroup is not networked.
Torque Owner Glenn Prince
new SimGroup(Country); function createCountry(%name, %armies, %player, %pos) { %country = new t2dStaticSprite(); { scenegraph = t2dscene; } %country.setImageMap(NeutralCountryImage); %country.setPosition(%pos); %country.setLayer($countryLayer); %country.setGraphGroup($countryGroup); %country.name = %name; %country.armies = %armies; %country.owner = %player; Country.add(%country); } new SimGroup(CountryLink); function createCountryLink(%firstCountry, %secondCountry, %pos) { %link = new t2dStaticSprite(); { scenegraph = t2dscene; } %link.setImageMap(CountryLinkArrow); %link.setPosition(%pos); %link.setLayer($countryLayer); %link.setGraphGroup($countryGroup); %link.firstCountry = %firstCountry; %link.secondCountry = %secondCountry; CountryLink.add(%link); }Then, to set up a country you do something like this:
createCountry("North America", 1, 1, "10 15");Then, after you have created your countries you create the links:
createCountryLink("North America", "South America", "12 17");You can then step through each item and check links,create addtional countries on the fly etc.
Code above should be good but is untested.
Regards,
Glenn