Help adding additional defenses for the enemy in the campaign

Get some help with creating maps or modding.
Need a map editor or other tools, look here!
Post Reply
User avatar
Black Project
Regular
Regular
Posts: 745
Joined: 04 Apr 2008, 20:53

Help adding additional defenses for the enemy in the campaign

Post by Black Project » 10 Apr 2020, 02:23

I'm trying to figure out how to add extra structures for the enemy depending on the difficulty the play chooses.

For example: in the first beta mission, the Collective will have a few extra defenses (HMG Bunker) at their LZ depending on difficulty. Here's the code

Code: Select all

function addExtraStructs4Collective() // =========== Coding stuff to add extra defenses for Collective ===========
{
	if (difficulty === MEDIUM || difficulty === HARD || difficulty === INSANE )
	{
		addStructure("PillBox3", THE_COLLECTIVE, 119, 113);
		addStructure("PillBox3", THE_COLLECTIVE, 120, 114);
	}
	else if (difficulty === HARD || difficulty === INSANE)
	{
		addStructure("PillBox3", THE_COLLECTIVE, 119, 115);
		addStructure("PillBox3", THE_COLLECTIVE, 118, 114);
	}
	else if (difficulty === INSANE)
	{
		addStructure("PillBox1", THE_COLLECTIVE, 118, 119);
		addStructure("PillBox2", THE_COLLECTIVE, 119, 118);
		addStructure("PillBox3", THE_COLLECTIVE, 120, 119);
		addStructure("PillBox3", THE_COLLECTIVE, 119, 120);
	}
}

function eventStartLevel()
{
	const PLAYER_POWER = 5000;
	var startpos = getObject("startPosition");
	var lz = getObject("landingZone"); //player lz
	var enemyLz = getObject("COLandingZone");
	var tent = getObject("transporterEntry");
	var text = getObject("transporterExit");

	camSetStandardWinLossConditions(CAM_VICTORY_STANDARD, "SUB_2_1S");
	setReinforcementTime(LZ_COMPROMISED_TIME);

	centreView(startpos.x, startpos.y);
	setNoGoArea(lz.x, lz.y, lz.x2, lz.y2, CAM_HUMAN_PLAYER);
	setNoGoArea(enemyLz.x, enemyLz.y, enemyLz.x2, enemyLz.y2, THE_COLLECTIVE);
	startTransporterEntry(tent.x, tent.y, CAM_HUMAN_PLAYER);
	setTransporterExit(text.x, text.y, CAM_HUMAN_PLAYER);

	camSetArtifacts({
		"COCommandCenter": { tech: "R-Sys-Engineering02" },
		"COArtiPillbox": { tech: "R-Wpn-MG-ROF02" },
		"COArtiCBTower": { tech: "R-Sys-Sensor-Upgrade01" },
	});

	setMissionTime(camChangeOnDiff(camHoursToSeconds(1)));
	setPower(PLAYER_POWER, CAM_HUMAN_PLAYER);
	cam2Setup();

	//C2A_BASE2 is not really a base
	camSetEnemyBases({
		"CONorthBase": {
			cleanup: "CONorth",
			detectMsg: "C2A_BASE1",
			detectSnd: "pcv379.ogg",
			eliminateSnd: "pcv394.ogg",
		},
		"CONorthWestBase": {
			cleanup: "CONorthWest",
			detectMsg: "C2A_BASE2",
			detectSnd: "pcv379.ogg",
			eliminateSnd: "pcv394.ogg",
		},
	});

	camManageTrucks(THE_COLLECTIVE);
	truckDefense();
	setUnitRank(); //All pre-placed player droids are ranked.
	camPlayVideos("MB2A_MSG");
	startedFromMenu = false;

	//Only if starting Beta directly rather than going through Alpha
	if (enumDroid(CAM_HUMAN_PLAYER, DROID_TRANSPORTER).length === 0)
	{
		startedFromMenu = true;
		sendPlayerTransporter();
	}
	else
	{
		setReinforcementTime(camMinutesToSeconds(5)); // 5 min.
	}
	
	queue("camCallOnce", camSecondsToMilliseconds(0.5),  "addExtraStructs4Collective"); // =========== More coding stuff to add extra defenses for Collective ===========
	queue("secondVideo", camSecondsToMilliseconds(12));
	queue("truckDefense", camSecondsToMilliseconds(15));
	queue("groupPatrol", camChangeOnDiff(camMinutesToMilliseconds(1)));
	queue("vtolAttack", camChangeOnDiff(camMinutesToMilliseconds(3)));
	queue("sendCOTransporter", camChangeOnDiff(camMinutesToMilliseconds(4)));
	queue("mapEdgeDroids", camChangeOnDiff(camMinutesToMilliseconds(7)));
}
However, the intended defenses are not spawning, regardless of the intended difficulty. I tried to add all the defenses regardless of difficulty, but i've obtained no success so far.

I can't seem to figure out the mistake i did that stops me from adding the extra defenses.

User avatar
Berserk Cyborg
Code contributor
Code contributor
Posts: 874
Joined: 26 Sep 2016, 19:56

Re: Help adding additional defenses for the enemy in the campaign

Post by Berserk Cyborg » 10 Apr 2020, 05:38

Currently, the instructions are spawning structures way off out of viewing bounds near the top left corner of the map. This function expects "world coordinates" instead of map tiles (the numbers in the brackets when clicking on terrain when in debug mode). What you want to do is multiply the positions you chose by 128 if you want to work with only tiles.

BTW, anything inside eventStartLevel will only get called once per mission so you can simply use a plain queue on your function.

User avatar
Black Project
Regular
Regular
Posts: 745
Joined: 04 Apr 2008, 20:53

Re: Help adding additional defenses for the enemy in the campaign

Post by Black Project » 10 Apr 2020, 16:08

Ok, so i followed your advice, made a few more changes in the code, and now it properly works.

Code: Select all

function addExtraStructs4Collective() // =========== Coding stuff to add extra defenses for Collective ===========
{
	if (difficulty === MEDIUM )
	{
		addStructure("PillBox3", THE_COLLECTIVE, 128*119, 128*113);
		addStructure("PillBox3", THE_COLLECTIVE, 128*120, 128*114);
	}
	else if (difficulty === HARD )
	{
		addStructure("PillBox3", THE_COLLECTIVE, 128*119, 128*113);
		addStructure("PillBox3", THE_COLLECTIVE, 128*120, 128*114);
		addStructure("PillBox3", THE_COLLECTIVE, 128*119, 128*115);
		addStructure("PillBox3", THE_COLLECTIVE, 128*118, 128*114);
	}
	else if (difficulty === INSANE)
	{
		addStructure("PillBox3", THE_COLLECTIVE, 128*119, 128*113);
		addStructure("PillBox3", THE_COLLECTIVE, 128*120, 128*114);
		addStructure("PillBox3", THE_COLLECTIVE, 128*119, 128*115);
		addStructure("PillBox3", THE_COLLECTIVE, 128*118, 128*114);

		addStructure("PillBox1", THE_COLLECTIVE, 128*118, 128*119);
		addStructure("PillBox2", THE_COLLECTIVE, 128*119, 128*118);
		addStructure("PillBox3", THE_COLLECTIVE, 128*120, 128*119);
		addStructure("PillBox3", THE_COLLECTIVE, 128*119, 128*120);
	}
}

function eventStartLevel()
{
	const PLAYER_POWER = 5000;
	var startpos = getObject("startPosition");
	var lz = getObject("landingZone"); //player lz
	var enemyLz = getObject("COLandingZone");
	var tent = getObject("transporterEntry");
	var text = getObject("transporterExit");

	camSetStandardWinLossConditions(CAM_VICTORY_STANDARD, "SUB_2_1S");
	setReinforcementTime(LZ_COMPROMISED_TIME);

	centreView(startpos.x, startpos.y);
	setNoGoArea(lz.x, lz.y, lz.x2, lz.y2, CAM_HUMAN_PLAYER);
	setNoGoArea(enemyLz.x, enemyLz.y, enemyLz.x2, enemyLz.y2, THE_COLLECTIVE);
	startTransporterEntry(tent.x, tent.y, CAM_HUMAN_PLAYER);
	setTransporterExit(text.x, text.y, CAM_HUMAN_PLAYER);

	camSetArtifacts({
		"COCommandCenter": { tech: "R-Sys-Engineering02" },
		"COArtiPillbox": { tech: "R-Wpn-MG-ROF02" },
		"COArtiCBTower": { tech: "R-Sys-Sensor-Upgrade01" },
	});

	setMissionTime(camChangeOnDiff(camHoursToSeconds(1)));
	setPower(PLAYER_POWER, CAM_HUMAN_PLAYER);
	cam2Setup();

	//C2A_BASE2 is not really a base
	camSetEnemyBases({
		"CONorthBase": {
			cleanup: "CONorth",
			detectMsg: "C2A_BASE1",
			detectSnd: "pcv379.ogg",
			eliminateSnd: "pcv394.ogg",
		},
		"CONorthWestBase": {
			cleanup: "CONorthWest",
			detectMsg: "C2A_BASE2",
			detectSnd: "pcv379.ogg",
			eliminateSnd: "pcv394.ogg",
		},
	});

	camManageTrucks(THE_COLLECTIVE);
	truckDefense();
	setUnitRank(); //All pre-placed player droids are ranked.
	camPlayVideos("MB2A_MSG");
	startedFromMenu = false;

	//Only if starting Beta directly rather than going through Alpha
	if (enumDroid(CAM_HUMAN_PLAYER, DROID_TRANSPORTER).length === 0)
	{
		startedFromMenu = true;
		sendPlayerTransporter();
	}
	else
	{
		setReinforcementTime(camMinutesToSeconds(5)); // 5 min.
	}
	
	queue("addExtraStructs4Collective", camSecondsToMilliseconds(1)); // =========== More coding stuff to add extra defenses for Collective ===========
	queue("secondVideo", camSecondsToMilliseconds(12));
	queue("truckDefense", camSecondsToMilliseconds(15));
	queue("groupPatrol", camChangeOnDiff(camMinutesToMilliseconds(1)));
	queue("vtolAttack", camChangeOnDiff(camMinutesToMilliseconds(3)));
	queue("sendCOTransporter", camChangeOnDiff(camMinutesToMilliseconds(4)));
	queue("mapEdgeDroids", camChangeOnDiff(camMinutesToMilliseconds(7)));
}
Thanks for the help!

Post Reply