Author Topic: SDK  (Read 1767 times)

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
SDK
« on: April 08, 2005, 05:14:36 PM »
I have only 1 question: who wrote the headers/source  (In particular OP2helper.cpp/h) ?
I'm updating the code in include the function RecordBase. It will use the Record... member functions to record a base that is "built" by using CreateBase. This way any convecs added to that buildingGroup will keep the base intact, without having to record it "by hand" adding lots of buildingGroup.RecordBuilding(...) lines.

I think i should rename the file while i'm at it. I don't use all the functinos in there anyway..
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
SDK
« Reply #1 on: April 08, 2005, 05:19:52 PM »
I wrote that file. And good idea to add a function like that. I didn't really have AI in mind when I first wrote it. We should probably consider adopting such a function for the next official release.
 

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
SDK
« Reply #2 on: April 10, 2005, 08:34:05 AM »
Easy: i've just copied & pasted your function, and changed it a bit to use Record instead of CreateUnit:
Code: [Select]
void RecordBase(BuildingGroup grp,int x,int y,struct BaseInfo &baseInfo)
{
int i;
int curX, curY;
int curX2, curY2;

// Create the buildings
for (i = 0; i < baseInfo.numBuilding; i++)
{
  BuildingInfo &curItem = baseInfo.bldnInfo[i];
  curX = x + curItem.x;
  curY = y + curItem.y;
  grp.RecordBuilding(LOCATION(curX,curY),curItem.type,mapNone);
}

// Create the tube lines
for (i = 0; i < baseInfo.numTubeLine; i++)
{
  TubeWallInfo &curItem = baseInfo.tubeInfo[i];
  curX = x + curItem.fromX;
  curY = y + curItem.fromY;
  curX2 = x + curItem.toX;
  curY2 = y + curItem.toY;
  RecordTubeOrWall(grp,LOCATION(curX,curY),LOCATION(curX2,curY2),mapTube);
}

// Create the wall lines
for (i = 0; i < baseInfo.numWallLine; i++)
{
  TubeWallInfo &curItem = baseInfo.wallInfo[i];
  curX = x + curItem.fromX;
  curY = y + curItem.fromY;
  curX2 = x + curItem.toX;
  curY2 = y + curItem.toY;
  RecordTubeOrWall(grp,LOCATION(curX,curY),LOCATION(curX2,curY2),mapWall);
}

// Create the vehicles
for (i = 0; i < baseInfo.numVehicle; i++)
{
  VehicleInfo &curItem = baseInfo.vehicleInfo[i];
  if (curItem.type==mapGuardPost)
  {
   curX = x + curItem.x;
   curY = y + curItem.y;
   grp.RecordBuilding(LOCATION(curX,curY),curItem.type,mapNone);
  }
}
}

I'm not sure the RecordTubeOrWall function is made by you, or added by me - if you dont have that, let me know, i'll post it also
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
SDK
« Reply #3 on: April 10, 2005, 02:40:22 PM »
I'm pretty sure I never wrote a RecordTubeOrWall. It was probably written by you.
 

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
SDK
« Reply #4 on: April 10, 2005, 02:43:36 PM »
Same thing: i'ts a mere copy of your code, amended to use Record functions instead:
Code: [Select]
void RecordTubeOrWall(BuildingGroup grp,LOCATION start,LOCATION end,map_id type)
{
int increment=1;

if (start.x==end.x)   // vertical tube
{
  if (type==mapTube) grp.RecordTube(LOCATION(start.x,start.y));
  else grp.RecordWall(LOCATION(start.x,start.y),type);

  if (start.y==end.y) increment=0;
  else increment=(start.y<=end.y?1:-1);
  do
  {
   start.y+=increment;
   if (type==mapTube) grp.RecordTube(LOCATION(start.x,start.y));
   else grp.RecordWall(LOCATION(start.x,start.y),type);
  }
  while (start.y!=end.y);
}
else if (start.y==end.y) // horizontal tube
{
  if (type==mapTube) grp.RecordTube(LOCATION(start.x,start.y));
  else grp.RecordWall(LOCATION(start.x,start.y),type);

  if (start.x==end.x) increment=0;
  else increment=(start.x<=end.x?1:-1);
  do
  {
   start.x+=increment;
   if (type==mapTube) grp.RecordTube(LOCATION(start.x,start.y));
   else grp.RecordWall(LOCATION(start.x,start.y),type);
  }
  while (start.x!=end.x);
}
else // diagonal -> horizontal first, then vertical:
{
  RecordTubeOrWall(grp,start,LOCATION(end.x,start.y),type);
  RecordTubeOrWall(grp,LOCATION(end.x,start.y),end,type);
}
}
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz