PDA

View Full Version : Script Help - Read damaged objects into file


von Pilsner
05-23-2012, 10:52 PM
I suspect this has already been accomplished, but I can not find it through Google or Forum Search so I figure I will ask here...

I have a mission.cs script that I have been using, it starts with the usual:
using System;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using maddox.GP;

public class Mission : maddox.game.AMission

What I would like it to do is write (append actually) to a file named 'destroyed.ini' (in the same directory as my mission) as static objects get destroyed so during the course of a mission the file may fill up like:
[Static]
Stationary.Environment.JP3_Generator_15_KW_UK1 gb 178768.08 197313.52 105.00, 2
Artillery.3_inch_20_CWT_QF_Mk_I_StandAlone2 gb 136914.39 198372.09 -60.00, 2
Stationary.Ammo_Vehicles.3inch_QF_AA_composition3_ UK1 nn 136921.30 198377.00 -90.00, 2

THe coordinates are important because they will be used later to determine if it is the exact same static object that was destroyed. The suffix ',2' is just a placeholder but I would like it to end up in the file as well.

I would then like to use a separate script (my overall campaign.cs) to parse the file and use the list to not create static objects in the next mission.

I used to do C programming (command line), but the object model of C# is taking me some time to wrap my head around. If someone could help me write the objects to a file I believe I have the skills to parse the file and use the data in my own (campaign) script.

The reason I would like it in a mission script is because it is for single player use.

Thanks,
von Pilsner

p.s. - I have read through the basic tutorials and script examples so if that is all you are able to suggest, I'm doing that right now... ;)

salmo
05-23-2012, 11:09 PM
Destruction of actors (moving ships, vehicles, planes) can be tracked via the OnActorDestroyed method, but there's no method that exposes the destruction of statics objects.

von Pilsner
05-23-2012, 11:22 PM
Destruction of actors (moving ships, vehicles, planes) can be tracked via the OnActorDestroyed method, but there's no method that exposes the destruction of statics objects.

Thanks, that is what I was afraid of...

hc_wolf
05-24-2012, 01:27 AM
It totally blows! Two little fixes. Track destruction of Static Objects and Track destruction of pre-loaded objects (houses) on Maps. Then we can have fun with carpet bombing and attacking London and other cities without placing a Blue or Red static object within it to mimic destruction.

Smokeynz
05-24-2012, 01:55 AM
I have the following code in my current "work in progress" script
My intension was simple plane spawning limits and mission completion.

The limitation works but mission completion has issues.
However what I have found is relationships between various aspects.
Destroyed can be killed or removed by various means.
Killed is different to destroyed.

I created the following so I could see what is going on. Doesnt really help objects though.


/*=========================================*/

#region Resource Counters

/*=========================================*/

int ActorsCreated;
int ActorsCreatedLast;
int ActorsDestroyed;
int ActorsDestroyedLast;
int ActorsDead;
int ActorsDeadLast;

int AircraftLanded;
int AircraftLandedLast;
int AircraftCrashed;
int AircraftCrashedLast;
int AircraftKilled;
int AircraftKilledLast;

int BlueActors;
int BlueDOA;
int BlueAircraftInService;
int BlueAircraftLost;
int BlueReserve;// = 300;//config list once setup

int RedActors;
int RedDOA;
int RedAircraftInService;
int RedAircraftLost;
int RedReserve;// = 300;

int PlaneLimit; //total aircraft in game at any one time

private void ActorResources(AiActor actor)
{
if (ActorsCreated > ActorsCreatedLast)
{
if (actor.Army() == 1)
{
RedActors++;
RedAircraftInService++;
RedReserve--;
}
if (actor.Army() == 2)
{
BlueActors++;
BlueAircraftInService++;
BlueReserve--;
}
ActorsCreatedLast = ActorsCreated;
}
if (ActorsDestroyed > ActorsDestroyedLast)
{
if (actor.Army() == 1)
{
RedAircraftInService--;
RedReserve++;
}
if (actor.Army() == 2)
{
BlueAircraftInService--;
BlueReserve++;
}
ActorsDestroyedLast = ActorsDestroyed;
}

if (ActorsDead > ActorsDeadLast)
{
if (actor.Army() == 1)
{
RedAircraftInService--;
RedDOA++;
}
if (actor.Army() == 2)
{
BlueAircraftInService--;
BlueDOA++;
}
ActorsDeadLast = ActorsDead;
}

LimitPlanes();
}

private void AircraftResources(AiAircraft aircraft)
{
if (AircraftLanded > AircraftLandedLast)
{
if (aircraft.Army() == 1)
{
RedAircraftInService--;
RedReserve++;
}
if (aircraft.Army() == 2)
{
BlueAircraftInService--;
BlueReserve++;
}
AircraftLandedLast = AircraftLanded;
}
if (AircraftCrashed > AircraftCrashedLast)
{
if (aircraft.Army() == 1)
{
RedAircraftInService--;
RedAircraftLost++;
//RedReserve--;
}
if (aircraft.Army() == 2)
{
BlueAircraftInService--;
BlueAircraftLost++;
//BlueReserve--;
}
AircraftCrashedLast = AircraftCrashed;
}

if (AircraftKilled > AircraftKilledLast)
{
if (aircraft.Army() == 1)
{
RedAircraftInService--;
RedAircraftLost++;
}
if (aircraft.Army() == 2)
{
BlueAircraftInService--;
BlueAircraftLost++;
}
AircraftKilledLast = AircraftKilled;
}

LimitPlanes();
}

private void LimitPlanes()
{
if (RedAircraftInService > PlaneLimit)
{
rl = 1;
gl = 3;
GamePlay.gpLogServer(null, "Red Ingame limit reached: PlaneLimit:{0} InService:{1}", new object[] { PlaneLimit, RedAircraftInService });
}
else { rl = 0; gl = 0; }
if (BlueAircraftInService > PlaneLimit)
{
bl = 2;
gl = 3;
GamePlay.gpLogServer(null, "Blue Ingame limit reached: PlaneLimit:{0} InService:{1}", new object[] { PlaneLimit, BlueAircraftInService });
}
else { bl = 0; gl = 0;}
}

public override void OnActorDestroyed(int missionNumber, string shortName, AiActor actor)
{
base.OnActorDestroyed(missionNumber, shortName, actor);
if (actor != null)
{
if (actor is AiAircraft)
{
ActorsDestroyed++;
ActorResources(actor);
}
}
}

public override void OnActorDead(int missionNumber, string shortName, AiActor actor, System.Collections.Generic.List<DamagerScore> damages)
{
base.OnActorDead(missionNumber, shortName, actor, damages);
if (actor != null)
{
if (actor is AiAircraft)
{
ActorsDead++;
ActorResources(actor);
}
}
}

public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftLanded(missionNumber, shortName, aircraft);
if (aircraft != null)
{
AircraftLanded++;
AircraftResources(aircraft);
}
}

public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);
if (aircraft != null)
{
AircraftCrashed++;
AircraftResources(aircraft);
}
}

public override void OnAircraftKilled(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftKilled(missionNumber, shortName, aircraft);
if (aircraft != null)
{
AircraftKilled++;
AircraftResources(aircraft);
}
}

/*=========================================*/

#endregion

/*=========================================*/




This goes in ticktimer section to report the results



// Mission config collection cycle
if (Time.tickCounter() % 1800 == 900)
{
GamePlay.gpLogServer(null, "-------------------------------------------------", null);
GamePlay.gpLogServer(null, " [Overall Resources Count]", null);
GamePlay.gpLogServer(null, " Actors:: Created:{0} Destroyed:{1} Dead:{2}", new object[] { ActorsCreated, ActorsDestroyed, ActorsDead });
GamePlay.gpLogServer(null, "Aircraft:: Landed:{0} Crashed:{1} Killed:{2}", new object[] { AircraftLanded, AircraftCrashed, AircraftKilled });
GamePlay.gpLogServer(null, "-------------------------------------------------", new object[] { });
GamePlay.gpLogServer(null, " [Blue Resources]", null);
GamePlay.gpLogServer(null, " Pilots:: Actors:{0} DOA:{1}", new object[] { BlueActors, BlueDOA });
GamePlay.gpLogServer(null, "Aircraft:: InService:{0} Lost:{1} Reserve:{2}", new object[] { BlueAircraftInService, BlueAircraftLost, BlueReserve });
GamePlay.gpLogServer(null, "-------------------------------------------------", null);
GamePlay.gpLogServer(null, " [Red Resources]", null);
GamePlay.gpLogServer(null, " Pilots:: Actors:{0} DOA:{1}", new object[] { RedActors, RedDOA });
GamePlay.gpLogServer(null, "Aircraft:: InService:{0} Lost:{1} Reserve:{2}", new object[] { RedAircraftInService, RedAircraftLost, RedReserve });
GamePlay.gpLogServer(null, " ------------------------------------------------", null);
}

FG28_Kodiak
05-24-2012, 04:34 AM
@pilsner
You can "register" the destroying of a static object (not all, no house for example) only with TGroundDestroyed Trigger. So you must add a TGroundDestroyed to every static you wana check, at the moment.

von Pilsner
05-25-2012, 02:14 AM
Very helpful, Thanks! :D