Author Topic: Outpost 2 Coding 101: Week 7  (Read 5614 times)

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Outpost 2 Coding 101: Week 7
« on: March 01, 2010, 03:22:41 PM »
Week 7
Advanced Triggers - What, You Expect Some Weird Catchphrase Everytime?

So we've already looked at some basic triggers in week 3 (the two time triggers and the one player left trigger).  But those triggers are boring.  So what other kinds of triggers are there?  Lots, it turns out!

Building Count Trigger - This trigger counts ALL buildings of any type owned by a specified player and compares them to some value.
Code: [Select]
CreateBuildingCountTrigger(enable, one-time, player number, number to compare to, comparison type, "Trigger Function");
// Example:
CreateBuildingCountTrigger(1, 1, 0, 10, cmpGreaterEqual, "PlayerHasAtLeastTenBuildings");
Valid comparison types:
Code: [Select]
cmpEqual
cmpLower
cmpGreater
cmpLowerEqual
cmpGreaterEqual
Those should be pretty self-explanitory.  Get to know them since you'll use them in a lot of triggers.

Vehicle Count Trigger - Same thing as above, but counts vehicles instead of structures.
Code: [Select]
CreateVehicleCountTrigger(enable, one-time, player number, number to compare to, comparison type, "Trigger Function");

Count Trigger - This is probably the most useful of the three count triggers as you can specify which type of unit we want to count.
Code: [Select]
CreateCountTrigger(enable, one-time, player number, unit to count, unit's cargo, number to compare to, comparison type, "Trigger Function");
// Example:
CreateCountTrigger(1, 1, 0, mapLynx, mapLaser, 7, cmpGreaterEqual, "HaveAtLeastSevenLaserLynx");

Attacked Trigger - This trigger fires when a unit group has been attacked.  We'll go into more detail about unit groups later.
Code: [Select]
CreateAttackedTrigger(enabled, one-time, Unit Group, "Trigger Function");
// Example:
// Create some units
TethysGame::CreateUnit(AILynx1, mapLynx, LOCATION(x, y), mapMicrowave, 1, 0);
...

// Setup the group
FightGroup AI_MicrowaveLynxGroup;

// Add the units to the group
AI_MicrowaveLynxGroup.TakeUnit(AILynx1);
...

CreateAttackedTrigger(1, 1, AI_MicrowaveLynxGroup, "AttackedAI");

Damaged Trigger - Fires after a group has taken a certain amount of damage? (I haven't really experimented with this trigger, but it would probably be useful for getting an AI unit to repair damaged structures.)
Code: [Select]
CreateDamagedTrigger(enabled, one-time, Unit Group, Damage Taken, "Trigger Function);
// Example:
CreateDamageTrigger(1, 0, AI_Tokamaks, 250, "RepairTokamaks");

Escape Trigger - Despite the name, all this checks is if you have X amount of units carrying Y amount of Z cargo in some location.
Code: [Select]
CreateEscapeTrigger(enabled, one-time, Player Number, Upper left corner of location (X), Upper left corner of location (Y), Location Width, Location Height, Number of Units Required, Unit Type, Cargo Type, Cargo Amount, "Trigger Function");

// Examples
CreateEscapeTrigger(1, 1, 0, 10+31, 7-1, 5, 5, 7, mapTiger, mapThorsHammer, 1, "Bring seven Thor's Hammer Tigers to the upper left corner of the map");

CreateEscapeTrigger(1, 0, 0, 58+31, 58-1, 6, 6, 3, mapCargoTruck, (map_id)truckFood, 3000, "Bring Cargo Trucks carrying 3000 units of food to the lower right corner of the map");

Evac Trigger - Use this to create a "Have enough Evacuation Transports for your population." trigger.
Code: [Select]
CreateEvacTrigger(enable, one-time, Player Number, "Trigger Function");

// Example
CreateEvacTrigger(1, 0, 0, "Player1HasEnoughETs");

Kit Trigger - Checks if you have a structure kit of the specified type (in factory storage or in a ConVec).
Code: [Select]
CreateKitTrigger(enabled, one-time, Player Number, Structure Kit Type, Minimum Amount Needed, "Trigger Function");

// Example
CreateKitTrigger(1, 0, 0, mapCommandCenter, 1, "Have a Command Center kit in storage.");

Midas Trigger - Used to create a victory condition for the Midas multiplayer gametype (duh).
Code: [Select]
CreateMidasTrigger(enabled, one-time, Game Time Limit, "Trigger Function");

// Example
CreateMidasTrigger(1, 1, 25000, "Have the more ore in storage by mark 250."); // I'm pretty sure time is in ticks...

One Player Left Trigger - Used for a standard Last One Standing victory condition.
See Week 3 Tutorial for more info.

Operational Trigger - This trigger fires if X amount of structure Y is active (meaning neither Disabled nor Idled).
Code: [Select]
CreateOperationalTrigger(enabled, one-time, Player Number, Structure Type, Comparison Number, Comparison Type, "Trigger Function");

// Example:
CreateOperationalTrigger(1, 0, 0, mapCommandCenter, 0, cmpEqual, "PlayerHasNoActiveCommandCenter");

Point Trigger - Detects whether a unit (any unit) owned by the specified player exists at the specified coordinates.
Code: [Select]
CreatePointTrigger(enabled, one-time, Player Number, X-Position, Y-Position, "Trigger Function");

// Example:
CreatePointTrigger(1, 1, 0, 50+31, 60-1, "UnitAtPoint");

Rect Trigger - Don't use this.  Use the Escape trigger instead; it gives you more control over what makes the trigger fire.

Research Trigger - Fires if the specified player researches the specified technology.
Code: [Select]
CreateResearchTrigger(enabled, one-time, Tech ID, Player Number, "Trigger Function");

// Example
CreateResearchTrigger(1, 1, 3851, 0, "MobileWeaponsPlatform_Researched");

Resource Trigger - Compares the player's resources to a specified value.
Code: [Select]
CreateResourceTrigger(enable, one-time, Resource Type, Comparison Amount, Player Number, Comparison Type, "Trigger Function");

// Example
CreateResourceTrigger(1, 0, resKids, 52, 0, cmpGreaterEqual, "Have at least 52 children");

// Valid Resource Types
resFood
resCommonOre
resRareOre
resKids
resWorkers
resScientists
resColonists

Time Triggers have already been covered extensively.  Refer to Weeks 3 and 4 if you need to review.

Special Target - Marks the specified unit as special and lets OP2 know that another unit can park next to it and do something to it (scan it, steal wreckage, hijack an RLV, etc.).
Code: [Select]
CreateSpecialTarget(enabled, one-time, Unit Handle, Unit Type to Interact With, "Trigger Function");

// Example
Unit Eden_Spaceport;
Trigger Steal_RLV;

TethysGame::CreateUnit(Eden_Spaceport, mapSpaceport, LOCATION(42+31, 5-1), 1, mapNone, 0);
Eden_Spaceport.SetFactoryCargo(0, mapRLV, mapNone);

Steal_RLV = CreateSpecialTarget(1, 1, Eden_Spaceport, mapSpider, "StealEdenRLV");

// Note: In the trigger function, I'd be sure to call Eden_Spaceport.ClearSpecialTarget();

Set Trigger - This is a fun one.  It lets you combine several triggers into one mega-trigger.
Code: [Select]
CreateSetTrigger(enabled, one-time, Total Triggers, Triggers Needed Before Set Trigger Fires, "Trigger Function", Subtrigger 1, Subtrigger 2, Subtrigger ...);

// Example

// Define a bunch of triggers here
Trigger WeaponsResearched, AttackTimeReached, PlayersDiscovered;

// ...

// Now create a set trigger that will fire if two of three conditions are met.
// Conditions: Players have researched weapons; Self-imposed attack mark has expired; Any player unit has been spotted
CreateSetTrigger(1, 1, 3, 2, "StartAttackingPlayers", WeaponsResearched, AttackTimeReached, PlayersDiscovered);

I think that's it!  It wasn't a particularly exciting lesson, but we'll need all of this for next week's lesson:
Your First Land Rush!

And if people ask, I'll post some mini examples.  Until then, see you next week.
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Outpost 2 Coding 101: Week 7
« Reply #1 on: March 07, 2010, 04:19:26 AM »
It seems you're doing a great job here, SirBomber...  Keep it up!
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 Angellus Mortis

  • Full Member
  • ***
  • Posts: 138
Outpost 2 Coding 101: Week 7
« Reply #2 on: August 08, 2010, 01:58:00 AM »
A good thing to mention is that for CreateSpecialTarget, you only use Unit.ClearSpecialTarget if CreateSpecialTarget is not on repeat. If you are using a scout to scan the status of what a building is doing, you will have the repeat on and Unit.ClearSpecialTarget will make the repeat ineffective.

Offline jcj94

  • Sr. Member
  • ****
  • Posts: 407
    • http://techfusion-279.com
Outpost 2 Coding 101: Week 7
« Reply #3 on: March 14, 2011, 09:47:06 PM »
Would there be a way to distribute a little.. AI town-pack, not necessarily a whole big thing, just a generic template for a standard AI attack...

And now that I think about it, I was wondering How in the world does the AI get so nice and nestled up an La Corrida?

Do Neutral units attack or just sit there? ( in Starcraft and other RTS games I play, sometimes they attack, sometimes they just sit.)

The simple AI town wouldn't be difficult to do i think, all you have to do is tweek X and Y vals for each map....

If you guys would like to help me with this.. (I am seriously thinking of makeing a notepad/ word doc with code like sirbomber puts) I'll be on IRC this sunday.. lat saturday as well.