Author Topic: Player Placement  (Read 2195 times)

Offline Leviathan

  • Hero Member
  • *****
  • Posts: 4055
Player Placement
« on: April 20, 2005, 04:58:41 PM »
In Hoovile in the SDK, becuase most maps are gonna be coded from that, by editing it...

How can I edit it to instead of having random placement having a placment where players are placed opposite to one another.

On Hoovile, a 4 player map there are 4 starting locations.
0 1 2 3 placed like so on the map:
0 1
2 3
With the random placement in a 2 player game players can be placed next to one another eg 0 and 1.

I like to be able to do opposite to one another, so:
0 vs 3 and 1 vs 2

Player 1 should be placed randomly and Player 2 should be placed opposite.

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Player Placement
« Reply #1 on: April 24, 2005, 08:28:06 AM »
Okay, this is what i worked out:

Template.cpp
Code: [Select]
int pos[4];
void GetStartingLocations(int numPlayers)
{
int i=TethysGame::GetRand(4);  // get a random position for player 1

if (numPlayers==2)
{
  pos[0]=i;
  pos[1]=3-i;   // place player 2 opposite of player 1
}
else      // randomize ALL players
{
  for (int x=0; x<numPlayers; ++x)
   pos[x]=(i+x)%4;
}
}



int InitProc()
{
int i;

GetStartingLocations(4);

// Place all bases on the map
for (i = 0; i < TethysGame::NoPlayers(); i++)
{
  InitPlayerResources(i);

  StartLocation &sLoc = startLocation[pos[i]];
  CreateBase(i, sLoc.x, sLoc.y, pos[i]);
  Player[i].CenterViewOn(sLoc.x, sLoc.y);
}

...
}

BaseData.h
Change the struct StartLocation startLocation difinition to this:
Code: [Select]
LOCATION startLocation[] = {
{ 49,  14},
{142,  14},
{ 49, 112},
{142, 112}
};
It should reflect the 3 correct starting locations!

I'll leave it to you to test if it works correctly. Be advised this ONLY works for 4 players max, so you should put in a test if (numPlayers>4) give error warning
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 Leviathan

  • Hero Member
  • *****
  • Posts: 4055
Player Placement
« Reply #2 on: April 24, 2005, 12:04:57 PM »
Ill send u my map code because it now includes more than Hoovile.

RandomizeStartingLocationsWithSF(autosize(startLocation), playerFacLoc);

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Player Placement
« Reply #3 on: April 24, 2005, 05:04:04 PM »
Replace your code like this:
Code: [Select]
Unit factory;
// int i contains the playernumber

if (PlayerBuildingEnum(i,mapStructureFactory).GetNext(factory))
{
  factory.SetFactoryCargo(0, mapTokamak,mapNone);
  factory.SetFactoryCargo(1, mapNursery,mapNone);
  factory.SetFactoryCargo(2, mapUniversity,mapNone);
  factory.SetFactoryCargo(3, mapVehicleFactory,mapNone);
  factory.SetFactoryCargo(4, mapRobotCommand,mapNone);
  factory.SetFactoryCargo(5, mapResidence,mapNone);
}
The enum will find ALL SF's of that player. Since the player has only 1 SF - if won't go wrong.
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: 4954
Player Placement
« Reply #4 on: April 24, 2005, 06:01:34 PM »
Just a few comments. That 4 player randomization doesn't truely randomize all locations. It just randomizes the first location and fills in the other locations by going around in a circle. People will always find themseleves in the same relative order.

Also, that code for the structure factory, doesn't set the contents for all SF. Just the first one it finds. (You're using an IF, not a loop).


And lastly. Please, PLEASE, don't make changes to things in the Outpost2DLL, or OP2Helper folders. This creates some real compatilbility issues if you need to send your code to someone else to look at. It will also create problems if we release a new SDK update. The idea behind those folders is that it's standardized code that is the same across different levels. If you're making your own custom changes to it, that just defeats the purpose. If you really feel you must make changes, COPY the code to your own .cpp/.h files and change the name! Don't modify the original. If you have updates, error corrections, new stuff, whatever, that you'd like included or feel should be included, or even stuff you don't know how to write yourself but think should be there, could you please send a PM to Hacker and me. (The one change that is safe to make to the Outpost2DLL folder only, is to add parameter names where they are missing, but again, tell us about it so we can include the change in future SDK versions.)
 

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Player Placement
« Reply #5 on: April 24, 2005, 06:41:38 PM »
Quote
That 4 player randomization doesn't truely randomize all locations
.. this is what he requested

Quote
Also, that code for the structure factory, doesn't set the contents for all SF. Just the first one it finds
.. as by my remark :) anyway: he has only 1 SF in his code.

Quote
don't make changes to things in the Outpost2DLL, or OP2Helper folders
.. i didn't  :angry: i send him changes on BaseData.h and Main.cpp (or Template.cpp as its called on my version of Hooville)
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: 4954
Player Placement
« Reply #6 on: April 24, 2005, 08:05:38 PM »
Hmm, I may have misread a little.

Btw, the StartLocation structure definition has changed a little and for some reason I though you were implying that it be changed again. (I took the word "definition" a little too seriously when you said to change it.) But still, I stand by that warning because I know some people have done it.

I also took what you wrote about the Enum to mean something completely different from what you've evidently intended. Enums can traverse over all units of a certain type, but only if you tell them to. It sounded like you were saying it would traverse over more SFs if they existed. But that's not the case. It would only ever find the first one and ignore any others. I guess it was just a wording issue here.

As for that 4 player setup. Lev, you were trying to just show the layout of the start locations? Or did you really mean to keep the players in the same relative order? I took it as just a diagram of where they were so he could illustrate the two player setup idea.


And btw, it's "Hooville" not "Hoovile". I feel like some kind of evil monster here.  :(
 
« Last Edit: April 24, 2005, 08:06:30 PM by Hooman »

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Player Placement
« Reply #7 on: April 25, 2005, 02:44:29 PM »
lol.. u may be a monster, but not evil
And, yes.. i think i DID change some things about OP2helper before :blush: You should see the version i have here .. anyway: juz helping out a friend
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 Leviathan

  • Hero Member
  • *****
  • Posts: 4055
Player Placement
« Reply #8 on: April 25, 2005, 03:35:01 PM »
Not geting very far with this, just errors.

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Player Placement
« Reply #9 on: April 25, 2005, 04:36:36 PM »
Code: [Select]
int InitProc()
{
int i;

  GetStartingLocations(TethysGame::NoPlayers());

  // Place all bases on the map
  for (i = 0; i < TethysGame::NoPlayers(); i++)
  {
   InitPlayerResources(i);

   LOCATION sLoc = startLocation[pos[i]];
   CreateBase(i, sLoc.x, sLoc.y, base[pos[i]]);
   Player[i].CenterViewOn(sLoc.x, sLoc.y);

  Player[i].MarkResearchComplete(3401); // Cybernetic Teleoperation
  Player[i].MarkResearchComplete(3305); // Research Training Programs
  Player[i].MarkResearchComplete(3304); // Offspring Enhancement
  Player[i].MarkResearchComplete(3303); // Health Maintenance
  
  Unit factory;
  // int i contains the playernumber
  if (PlayerBuildingEnum(i,mapStructureFactory).GetNext(factory))
  {
   factory.SetFactoryCargo(0, mapTokamak,mapNone);
   factory.SetFactoryCargo(1, mapNursery,mapNone);
   factory.SetFactoryCargo(2, mapUniversity,mapNone);
   factory.SetFactoryCargo(3, mapVehicleFactory,mapNone);
   factory.SetFactoryCargo(4, mapRobotCommand,mapNone);
   factory.SetFactoryCargo(5, mapResidence,mapNone);
  }
}
// Misc initialization
TethysGame::ForceMoraleGood(-1);
if (TethysGame::UsesMorale())
  TethysGame::FreeMoraleLevel(-1);
TethysGame::SetDaylightEverywhere(TethysGame::UsesDayNight() == 0);
TethysGame::SetDaylightMoves(0);
GameMap::SetInitialLightLevel(-32);

//CreateLastOneStandingVictoryCondition();

return 1; // return 1 if OK; 0 on failure

//TethysGame::AddMessage(int -1, int -1, char *Good Luck, Have Fun., int -1, int 93);
}
}
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