Author Topic: Game Crash Of Mission O' Mine  (Read 3446 times)

Offline Venera

  • Full Member
  • ***
  • Posts: 120
Game Crash Of Mission O' Mine
« on: May 08, 2011, 10:21:22 PM »
My side project of a colonylos thing keeps crashing the game.  It's the only mission that does so.  I can't seem to be able to find the source of the crash in the code.  Could someone help me?

Code: [Select]

#define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers
#include <windows.h>

// Include important header files needed to interface with Outpost 2
#include "..\Outpost2DLL\Outpost2DLL.h"
// Include header files to make it easier to build levels
#include "..\OP2Helper\OP2Helper.h"



// Note: These exports are required by Outpost2.exe from every level
//   DLL. They give values for the map and tech trees used by the
//   level and a description to place in the level listbox. The
//   last export is used to define characteristics of the level.
//   See RequiredExports.h for more details.
//   ** Be sure to set these when you build your own level**

char MapName[]   = "aof.map";       // The .map file used for this level
char LevelDesc[]  = "2P - LoS - Colony - Arena Of Fire";// Description appearing in the game list box
char TechtreeName[]  = "MULTITEK.TXT";      // File to use for the tech tree
SDescBlock DescBlock = { Colony, 2, 12, 0 }; // Important level details



// Note: This is the DLL entry point which is called by Windows when the
//   DLL is first loaded into a processes address space or unloaded
//   from the process address space. This function also be called for
//   each thread owned by the process, but this has been disabled
//   for efficiency reasons by the DisableThreadLibraryCalls during
//   the first time the method is run.
// Note: You most likely do NOT need to edit this and unless you really
//   know what you're doing you probably shouldn't.

BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
  DisableThreadLibraryCalls(hinstDLL);
}

    return TRUE;
}

// Note: The following function is called once by Outpost2.exe when the
//   level is first initialized. This is where you want to create
//   all the initial units and structures as well as setup any
//   map/level environment settings such as day and night.

int InitProc()
{
short i;

//Set Human to Eden and other stats
Player[0].GoEden();
Player[0].SetColorNumber(TethysGame::GetRand(6));
Player[1].GoPlymouth();
Player[1].SetColorNumber(7);

//Do Difficulty Settings
for (i = 0; i < TethysGame::NoPlayers(); i++)
{
  switch(Player[i].Difficulty() )
  {
  case 0:
    Player[i].SetKids(22);
    Player[i].SetWorkers(30);
    Player[i].SetScientists(19);
    Player[i].SetOre(4500);
    Player[i].SetFoodStored(1900);
    break;

  case 1:
    Player[i].SetKids(19);
    Player[i].SetWorkers(26);
    Player[i].SetScientists(16);
    Player[i].SetOre(3000);
    Player[i].SetFoodStored(1500);
    break;
  case 2:
    Player[i].SetKids(17);
    Player[i].SetWorkers(22);
    Player[i].SetScientists(14);
    Player[i].SetOre(3000);
    Player[i].SetFoodStored(1200);
    break;
  }
}
if (Player[0].Difficulty() == 0)
{
  //Common Unit Variable
  Unit x;
  //Command Centers
  Unit friendlycc;
  Unit enemycc;
  //Research Ceratin Techs
  Player[0].MarkResearchComplete(3401); //Cybernetic Teleoperation
  Player[0].MarkResearchComplete(3304); //Offspring Enhancement
  Player[0].MarkResearchComplete(3305); //Research Training Programs
  Player[1].MarkResearchComplete(3401);
  Player[1].MarkResearchComplete(3304);
  Player[1].MarkResearchComplete(3305);
  //Build Friendly Structures
  TethysGame::CreateUnit(x, mapVehicleFactory, LOCATION(4+32, 24-1), 0, mapNone, 0);
  TethysGame::CreateUnit(x, mapTokamak, LOCATION(9+32, 24-1), 0, mapNone, 0);
  TethysGame::CreateUnit(x, mapTokamak, LOCATION(12+32, 24-1), 0, mapNone, 0);
  TethysGame::CreateUnit(friendlycc, mapCommandCenter, LOCATION(3+32, 32-1), 0, mapNone, 0);
  TethysGame::CreateUnit(x, mapRobotCommand, LOCATION(8+32, 32-1), 0, mapNone, 0);
  TethysGame::CreateUnit(x, mapNursery, LOCATION(8+32, 29-1), 0, mapNone, 0);
  TethysGame::CreateUnit(x, mapStandardLab, LOCATION(12+32, 32-1), 0, mapNone, 0);
  TethysGame::CreateUnit(x, mapAgridome, LOCATION(12+32, 29-1), 0, mapNone, 0);
  TethysGame::CreateUnit(x, mapAgridome, LOCATION(12+32, 35-1), 0, mapNone, 0);
  TethysGame::CreateUnit(x, mapUniversity, LOCATION(8+32, 35-1), 0, mapNone, 0);
  TethysGame::CreateUnit(x, mapCommonOreSmelter, LOCATION(12+32, 39-1), 0, mapNone, 0);
  TethysGame::CreateUnit(x, mapStructureFactory, LOCATION(4+32, 39-1), 0, mapNone, 0);
  //Build Friendly Vehicles
  TethysGame::CreateUnit(x, mapRoboDozer, LOCATION(3+32, 35-1), 0, mapNone, 0);
  x.DoSetLights(1);
  TethysGame::CreateUnit(x, mapEarthworker, LOCATION(5+32, 35-1), 0, mapNone, 0);
  x.DoSetLights(1);
  TethysGame::CreateUnit(x, mapConVec, LOCATION(2+32, 42-1), 0, mapNone, 0);
  x.DoSetLights(1);
  TethysGame::CreateUnit(x, mapConVec, LOCATION(4+32, 42-1), 0, mapNone, 0);
  x.DoSetLights(1);
  TethysGame::CreateUnit(x, mapConVec, LOCATION(6+32, 42-1), 0, mapNone, 0);
  x.DoSetLights(1);
  TethysGame::CreateUnit(x, mapCargoTruck, LOCATION(10+32, 42-1), 0, mapNone, 0);
  x.DoSetLights(1);
  TethysGame::CreateUnit(x, mapCargoTruck, LOCATION(12+32, 42-1), 0, mapNone, 0);
  x.DoSetLights(1);
  TethysGame::CreateUnit(x, mapCargoTruck, LOCATION(14+32, 42-1), 0, mapNone, 0);
  x.DoSetLights(1);
  TethysGame::CreateUnit(x, mapRoboMiner, LOCATION(10+32, 44-1), 0, mapNone, 0);
  x.DoSetLights(1);
  TethysGame::CreateUnit(x, mapRoboSurveyor, LOCATION(12+32, 44-1), 0, mapNone, 0);
  x.DoSetLights(1);
  //Create Friendly Tubes
  CreateTubeOrWallLine(4+32, 27-1, 4+32, 30-1, mapTube);
  TethysGame::CreateWallOrTube(6+32, 32-1, -1, mapTube);
  TethysGame::CreateWallOrTube(10+32, 32-1, -1, mapTube);
  CreateTubeOrWallLine(3+32, 37-1, 3+32, 34-1, mapTube);
  CreateTubeOrWallLine(7+32, 39-1, 9+32, 39-1, mapTube);

  //Build Enemy Structures
  Unit esmelt1;
  TethysGame::CreateUnit(x, mapTokamak, LOCATION(115+32, 24-1), 1, mapNone, 0);
  TethysGame::CreateUnit(x, mapTokamak, LOCATION(118+32, 24-1), 1, mapNone, 0);
  TethysGame::CreateUnit(x, mapVehicleFactory, LOCATION(125+32, 24-1), 1, mapNone, 0);
  TethysGame::CreateUnit(x, mapAgridome, LOCATION(116+32, 29-1), 1, mapNone, 0);
  TethysGame::CreateUnit(x, mapNursery, LOCATION(121+32, 29-1), 1, mapNone, 0);
  TethysGame::CreateUnit(x, mapStandardLab, LOCATION(116+32, 32-1), 1, mapNone, 0);
  TethysGame::CreateUnit(x, mapRobotCommand, LOCATION(121+32, 32-1), 1, mapNone, 0);
  TethysGame::CreateUnit(enemycc, mapCommandCenter, LOCATION(125+32, 32-1), 1, mapNone, 0);
  TethysGame::CreateUnit(x, mapAgridome, LOCATION(116+32, 35-1), 1, mapNone, 0);
  TethysGame::CreateUnit(x, mapUniversity, LOCATION(121+32, 35-1), 1, mapNone, 0);
  TethysGame::CreateUnit(esmelt1, mapCommonOreSmelter, LOCATION(117+32, 39-1), 1, mapNone, 0);
  TethysGame::CreateUnit(x, mapStructureFactory, LOCATION(125+32, 39-1), 1, mapNone, 0);
  //Create Enemy Tubes
  CreateTubeOrWallLine(125+32, 27-1, 125+32, 30-1, mapTube);
  TethysGame::CreateWallOrTube(119+32, 32-1, 0, mapTube);
  TethysGame::CreateWallOrTube(123+32, 32-1, 0, mapTube);
  CreateTubeOrWallLine(125+32, 34-1, 125+32, 37-1, mapTube);
  CreateTubeOrWallLine(120+32, 39-1, 122+32, 39-1, mapTube);
  //Create Enemy Units
  Unit esurv;
  Unit eminer;
  Unit convec1;
  Unit convec2;
  Unit convec3;
  TethysGame::CreateUnit(x, mapRoboDozer, LOCATION(125+32, 35-1), 1, mapNone, 0);
  x.DoSetLights(1);
  TethysGame::CreateUnit(x, mapEarthworker, LOCATION(123+32, 35-1), 1, mapNone, 0);
  x.DoSetLights(1);
  TethysGame::CreateUnit(esurv, mapRoboSurveyor, LOCATION(116+32, 44-1), 1, mapNone, 0);
  esurv.DoSetLights(1);
  TethysGame::CreateUnit(eminer, mapRoboMiner, LOCATION(118+32, 44-1), 1, mapNone, 0);
  eminer.DoSetLights(1);
  TethysGame::CreateUnit(convec1, mapConVec, LOCATION(125+32, 42-1), 1, mapNone, 0);
  convec1.DoSetLights(1);
  TethysGame::CreateUnit(convec2, mapConVec, LOCATION(123+32, 42-1), 1, mapNone, 0);
  convec2.DoSetLights(1);
  TethysGame::CreateUnit(convec3, mapConVec, LOCATION(127+32, 42-1), 1, mapNone, 0);
  convec3.DoSetLights(1);
  //Let AI have infinite stuff
  while (1==1) {
   if (Player[0].Ore() < 10000) {
    Player[0].SetOre(1000);
   }
  }
}
if (Player[0].Difficulty() == 1)
{
  //Common Unit Variable
  Unit x;
  TethysGame::CreateUnit(x, mapScorpion, LOCATION(4+32, 4-1), 0, mapEMP, 0);
}
if (Player[0].Difficulty() == 2)
{
  //Common Unit Variable
  Unit x;
  TethysGame::CreateUnit(x, mapScorpion, LOCATION(4+32, 4-1), 0, mapAcidCloud, 0);
}
//Create beacons1
TethysGame::CreateBeacon(mapMiningBeacon, 29+32, 8-1, 1, -1, -1);
TethysGame::CreateBeacon(mapFumarole, 36+32, 12-1, -1, -1, -1);
TethysGame::CreateBeacon(mapMiningBeacon, 33+32, 20-1, 0, -1, -1);
TethysGame::CreateBeacon(mapMiningBeacon, 14+32, 47-1, 0, -1, -1);
TethysGame::CreateBeacon(mapFumarole, 36+32, 51-1, -1, -1, -1);
TethysGame::CreateBeacon(mapMiningBeacon, 29+32, 57-1, 1, -1, -1);
TethysGame::CreateBeacon(mapMiningBeacon, 100+32, 8-1, 1, -1, -1);
TethysGame::CreateBeacon(mapFumarole, 93+31, 12-1, -1, -1, -1);
TethysGame::CreateBeacon(mapMiningBeacon, 96+32, 20-1, 0, -1, -1);
    TethysGame::CreateBeacon(mapMiningBeacon, 119+32, 47-1, 0, -1, -1);
TethysGame::CreateBeacon(mapFumarole, 93+31, 51-1, -1, -1, -1);
TethysGame::CreateBeacon(mapMiningBeacon, 100+32, 57-1, 1, -1, -1);
return 1; // return 1 if OK; 0 on failure
}


// Note: The following function seems to be intended for use in
//   controlling an AI. It is called once every game cycle.
//   Use it for whatever code needs to run on a continual basis.
// Note: The standard level DLLs released by Sierra leave this function
//   empty and handle all AI controls through triggers.

void AIProc()
{
}


// Note: This function is called by Outpost2.exe to obtain a description
//   of a buffer that is saved to saved game files. Outpost2.exe
//   calls this function and passes it a pointer to a structure
//   which describes this buffer. This function is required to set
//   the fields of this structure. If no buffer needs to be saved
//   to a saved game file, then the buffer pointer needs to be set
//   to 0, and the length should also be set to 0.
// Note: This function is called once when the DLL is first initialized.
//   This means that all data to be saved must have space reserved
//   ahead of time at the start of the level. (Static sized storage)
//   In other words, there is no way to dynamically grow the size of
//   the buffer if more space is needed than originally specified.
// Note: You can probably stretch the above limitation by saving the
//   pointer to the buffer description passed by Outpost2.exe. This
//   may allow you to increase the buffer size dynamically but the
//   idea is yet untested. Keep in mind that you have no idea when
//   a game may be saved (or just loaded).

void __cdecl GetSaveRegions(struct BufferDesc &bufDesc)
{
bufDesc.bufferStart = 0; // Pointer to a buffer that needs to be saved
bufDesc.length = 0;   // sizeof(buffer)
}





// Note: These last two functions aren't absolutely required by a level
//   but they found in almost all DLLs anyways.


// Note: This export usually exists, but does nothing other than return 0.
//   It's use may have been for checking for victory/failure conditions
//   that are not easily checked for by using triggers.

int StatusProc()
{
return 0; // must return 0
}


// Note: This is a trigger callback function. This function is
//   intentionally left empty and is used as the trigger
//   callback function for triggers that don't want or need
//   any special callback function.
// Note: The use of SCRIPT_API is used by all trigger functions
//   to ensure they are exported correctly. (Although,
//   technically it's not needed in this case since this
//   function has a function prototype defined in
//   RequiredExports.h which contains the SCRIPT_API macro
//   in it. However, most other trigger callback functions
//   won't have a function prototype anywhere (and you really
//   don't need to declare a function prototype since you
//   should never be calling a callback function yourself)
//   so you should use the SCRIPT_API macro when you define
//   the function.
//   Might as well set a good example. =)

SCRIPT_API void NoResponseToTrigger()
{
}

Offline jcj94

  • Sr. Member
  • ****
  • Posts: 407
    • http://techfusion-279.com
Game Crash Of Mission O' Mine
« Reply #1 on: May 08, 2011, 10:31:57 PM »
Looks as though you forgot to set a number for your short, i, and your repeatedly calling it.
 
« Last Edit: May 08, 2011, 10:32:15 PM by jcj94 »

Offline Spikerocks101

  • Hero Member
  • *****
  • Posts: 711
Game Crash Of Mission O' Mine
« Reply #2 on: May 09, 2011, 12:18:55 AM »
No, "short i;" is declared alright (thou, it would be *nicer* to have "short i = 0;" or something). The problem is probably these lines:
Code: [Select]
 while (1==1) {
  if (Player[0].Ore() < 10000) {
   Player[0].SetOre(1000);
  }
 }
Try changing it to just this (getting rid of the while):
Code: [Select]
 
  if (Player[0].Ore() < 1000)
        Player[0].SetOre(1000);
You had "while(1==1)", which causes an infinite loop, and since you had not "break;" statements in the loop, the program just gets stuck there.
I AM YOUR PET ROCK!!!!!!

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Game Crash Of Mission O' Mine
« Reply #3 on: May 09, 2011, 02:02:29 AM »
Yeah, that while loop will cause the game to hang (which is not the same thing as a crash).
 

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Game Crash Of Mission O' Mine
« Reply #4 on: May 13, 2011, 07:01:58 AM »
Yes, the while loop was the problem.
Put such a check (as spike edited for you) in AIProc(), since instructions in AIProc execute once every 4 game ticks (which is pretty often).
"Nothing from nowhere, I'm no one at all"

Offline Venera

  • Full Member
  • ***
  • Posts: 120
Game Crash Of Mission O' Mine
« Reply #5 on: May 13, 2011, 04:31:13 PM »
Okay thanks.  I found CreateTimeTrigger works too.  But what would be better? AIProc() or CreateTimeTrigger()?

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
Game Crash Of Mission O' Mine
« Reply #6 on: May 14, 2011, 01:15:45 AM »
Generally you don't want to use a TimeTrigger, because the total number of Triggers in a mission is limited and you might want to use Triggers where they can't be replaced so easily.