Commit part 3 of patch #897 (and there is still more to come!).

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3158 4a71c877-e1ca-e34f-864e-861f7616d084
master
Freddie Witherden 2007-12-24 14:57:58 +00:00
parent fd9d44e1d3
commit ea9d378131
4 changed files with 61 additions and 55 deletions

View File

@ -673,7 +673,7 @@ BOOL recvMessage(void)
recvBuildStarted(); recvBuildStarted();
break; break;
case NET_BUILDFINISHED: // a building is complete case NET_BUILDFINISHED: // a building is complete
recvBuildFinished(&msg); recvBuildFinished();
break; break;
case NET_STRUCTDEST: // structure destroy case NET_STRUCTDEST: // structure destroy
recvDestroyStructure(&msg); recvDestroyStructure(&msg);

View File

@ -236,7 +236,7 @@ extern BOOL multiplayerWinSequence(BOOL firstCall);
// Buildings . multistruct // Buildings . multistruct
extern BOOL sendBuildStarted (STRUCTURE *psStruct, DROID *psDroid); extern BOOL sendBuildStarted (STRUCTURE *psStruct, DROID *psDroid);
extern BOOL SendDestroyStructure(const STRUCTURE* s); extern BOOL SendDestroyStructure(const STRUCTURE* s);
extern BOOL SendBuildFinished (const STRUCTURE* psStruct); extern BOOL SendBuildFinished (STRUCTURE *psStruct);
extern BOOL sendLasSat (UBYTE player, STRUCTURE *psStruct, BASE_OBJECT *psObj); extern BOOL sendLasSat (UBYTE player, STRUCTURE *psStruct, BASE_OBJECT *psObj);

View File

@ -35,7 +35,7 @@ extern BOOL receiveWholeDroid (NETMSG *pMsg);
extern BOOL recvDestroyStructure (NETMSG *pMsg); extern BOOL recvDestroyStructure (NETMSG *pMsg);
//extern BOOL RecvBuild (NETMSG *pMsg); //extern BOOL RecvBuild (NETMSG *pMsg);
extern BOOL recvBuildStarted (); extern BOOL recvBuildStarted ();
extern BOOL recvBuildFinished (NETMSG *pMsg); extern BOOL recvBuildFinished ();
//extern BOOL receiveWholeStructure (NETMSG *pMsg); //extern BOOL receiveWholeStructure (NETMSG *pMsg);
extern BOOL recvTemplate (NETMSG *pMsg); extern BOOL recvTemplate (NETMSG *pMsg);
extern BOOL recvDestroyFeature (NETMSG *pMsg); extern BOOL recvDestroyFeature (NETMSG *pMsg);

View File

@ -175,94 +175,100 @@ BOOL recvBuildStarted()
// //////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////
// INFORM others that a building has been completed. // INFORM others that a building has been completed.
BOOL SendBuildFinished(const STRUCTURE* psStruct) BOOL SendBuildFinished(STRUCTURE *psStruct)
{ {
NETMSG m; DBCONPRINTF(ConsoleString,(ConsoleString,"SendBuildFinished() called"));
NetAdd(m,0,psStruct->id); //id of finished struct NETbeginEncode(NET_BUILDFINISHED, NET_ALL_PLAYERS);
// also enough info to build it if we don't already know about it. // ID of building
NetAdd(m,4,psStruct->pStructureType->ref); // kind of building. NETuint32_t(&psStruct->id);
NetAdd(m,8,psStruct->pos.x); // x pos
NetAdd(m,10,psStruct->pos.y); // y pos // Along with enough info to build it (if needed)
NetAdd(m,12,psStruct->pos.z); // y pos NETuint32_t(&psStruct->pStructureType->ref);
m.body[14] =(char) psStruct->player; // player NETuint16_t(&psStruct->pos.x);
NETuint16_t(&psStruct->pos.y);
m.size =15; NETuint16_t(&psStruct->pos.z);
m.type =NET_BUILDFINISHED; NETuint8_t(&psStruct->player);
return (NETbcast(&m,FALSE)); return NETend();
} }
// //////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////
BOOL recvBuildFinished(NETMSG *m) BOOL recvBuildFinished()
{ {
UDWORD strId;//,i; UDWORD structId;
STRUCTURE *psStr; STRUCTURE *psStruct;
UWORD x,y,z; UWORD x,y,z;
UDWORD type,typeindex; UDWORD type,typeindex;
UBYTE player; UBYTE player;
NetGet(m,0,strId); // get the struct id.
psStr = IdToStruct(strId,ANYPLAYER);
if(psStr) DBCONPRINTF(ConsoleString,(ConsoleString,"recvBuildFinished() called"));
NETbeginDecode();
NETuint32_t(&structId); // get the struct id.
psStruct = IdToStruct(structId,ANYPLAYER);
if (psStruct)
{ // make it complete. { // make it complete.
psStr->currentBuildPts = psStr->pStructureType->buildPoints+1; psStruct->currentBuildPts = psStruct->pStructureType->buildPoints+1;
if(psStr->status != SS_BUILT) if (psStruct->status != SS_BUILT)
{ {
psStr->status = SS_BUILT; psStruct->status = SS_BUILT;
buildingComplete(psStr); buildingComplete(psStruct);
} }
NETlogEntry("building finished ok." ,0,0); NETlogEntry("building finished ok." ,0,0);
NETend();
return TRUE; return TRUE;
} }
// the building wasn't started, so we'll have to just plonk it down in the map. // The building wasn't started, so we'll have to just plonk it down in the map.
NetGet(m,4,type); // kind of building. NETuint32_t(&type); // Kind of building.
NetGet(m,8,x); // x pos NETuint16_t(&x); // x pos
NetGet(m,10,y); // y pos NETuint16_t(&y); // y pos
NetGet(m,12,z); // z pos NETuint16_t(&z); // z pos
NETuint8_t(&player);
player = m->body[14]; // player // Find the structures stats
for (typeindex=0; // Find structure target
for(typeindex=0; // find structure target
(typeindex<numStructureStats ) && (asStructureStats[typeindex].ref != type); (typeindex<numStructureStats ) && (asStructureStats[typeindex].ref != type);
typeindex++); typeindex++);
psStr = 0;
// check for similar buildings, to avoid overlaps // Check for similar buildings, to avoid overlaps
if (TILE_HAS_STRUCTURE(mapTile(map_coord(x), map_coord(y)))) if (TILE_HAS_STRUCTURE(mapTile(map_coord(x), map_coord(y))))
{ {
// get structure; // Get the current structure
psStr = getTileStructure(map_coord(x), map_coord(y)); psStruct = getTileStructure(map_coord(x), map_coord(y));
if(asStructureStats[typeindex].type == psStr->pStructureType->type) if (asStructureStats[typeindex].type == psStruct->pStructureType->type)
{ {
// correct type, correct location, just rename the id's to sync it.. (urgh) // Correct type, correct location, just rename the id's to sync it.. (urgh)
psStr->id = strId; psStruct->id = structId;
psStr->status = SS_BUILT; psStruct->status = SS_BUILT;
buildingComplete(psStr); buildingComplete(psStruct);
NETlogEntry("structure id modified" ,0,player); NETlogEntry("structure id modified", 0, player);
NETend();
return TRUE; return TRUE;
} }
} }
// Build the structure
psStr = buildStructure(&(asStructureStats[typeindex]), // build the structure. psStruct = buildStructure(&(asStructureStats[typeindex]), // Build the structure.
x,y, x, y, player,TRUE);
player,TRUE);
if (psStr) if (psStruct)
{ {
psStr->id = strId; psStruct->id = structId;
psStr->status = SS_BUILT; psStruct->status = SS_BUILT;
buildingComplete(psStr); buildingComplete(psStruct);
DBCONPRINTF(ConsoleString,(ConsoleString,"MultiPlayer: Struct not found on recvbuildcomplete :%d",strId )); DBCONPRINTF(ConsoleString,(ConsoleString,"MultiPlayer: Struct not found on recvbuildcomplete :%d",structId ));
NETlogEntry("had to plonk down a building" ,0,player); NETlogEntry("had to plonk down a building" ,0,player);
} }
else else
{ {
DBCONPRINTF(ConsoleString,(ConsoleString,"MultiPlayer: Struct not found on recvbuildcomplete BUILDIT FAILED TOO!:%d",strId )); DBCONPRINTF(ConsoleString,(ConsoleString,"MultiPlayer: Struct not found on recvbuildcomplete BUILDIT FAILED TOO!:%d",structId ));
NETlogEntry("had to plonk down a building, BUT FAILED OH S**T." ,0,player); NETlogEntry("had to plonk down a building, BUT FAILED OH S**T." ,0,player);
} }
NETend();
return FALSE; return FALSE;
} }