Welcome, Guest. Please login or register.

Author Topic: System for randomized sequence for teleports  (Read 3035 times)

Offline SintaxError

  • Admin
  • Elder Statesman
    of the Surf
  • *****
  • Posts: 1,731
  • There's an error in your sintax.
    • View Profile
    • SolidSurf
System for randomized sequence for teleports
« on: April 18, 2010, 05:20:59 AM »
Inspired by: http://forums.solidsurf.info/index.php/topic,2827.msg39176.html

I haven't tested this in Hammer yet, but this should allow for a sequence of teleports of arbitrary length to be randomized.

Hopefully I made the pseudo code understandable.  I'll probably work on implementing this with hammer some time during the week if I get some free time

Code: [Select]
Copyright (c) 2010 SolidSurf
-------------------------------------------------

#num_destinations = 16

info_teleport_destination  destinations[every num_destinations]
point_teleport desinationLoc[every num_destinations]
ai_changetarget changeDestToActive[every num_destinations]
ai_changetarget changeDestToInactive[every num_destinations]

logic_relay tryAssign
logic_case randomChance[every num_destinations]
logic_branch locationAssigned[every num_destinations]
logic_branch_listener whenAssigned
logic_relay doAssign[every num_destinations]


//Will start the assignment sequence for each
logic_relay tryAssign
{
OnTrigger->randomChance[0]->PickRandomShuffle
}

logic_case randomChance[every num_destinations]
{
//The 0..n will be variable.
//Assuming 16 total outputs, 0..7 set to true and 8..16 false will
//Give a 50/50
OnCase(0..n)->locationAssigned[this]->Test //Succeed and assign
unless(this == last)
{
OnCase(n+1..16)->randomChance[this+1]->PickRandomShuffle
}
else
{
Oncase(n+1..16)->randomChance[0]->PickRandomShuffle
}

}

//perfom awhether or not a location has been assigned
logic_branch locationAssigned[every num_destinations]
{
OnFalse->doAssign[this]->Trigger
unless last
{
OnTrue->randomChance[this+1]->PickRandomShuffle
}
else
{
OnTrue->randomChance[0]->PickRandomShuffle
}
}

logic_branch_listener whenAssigned
{
//Should Listen to all branches
Branch01: locationAssigned*
OnMixed->TryAssign->Trigger after 5ms
}

logic_relay doAssign[every num_destinations]
{
OnTrigger->
{
changeDestToActive[this]->Activate
changeDestToInactive[this]->Activate after 1ms
destinations[this]->Teleport
}
}

ai_changetarget changeDestToActive[every num_destinations]
{
target: destinations[this]
m_iszNewTarget: activeTPDest
}

ai_changetarget changeDestToInactive[every num_destinations]
{
target: activeTPDest
m_iszNewTarget: destinations[this]
}

//Static locations of the start of each level
point_teleport desinationLoc[every num_destinations]
{
target: activeTPDest
}

I might also offer up an explanation later, but feel free to investigate it yourself for now.

edit: shit, code is small... I recommend copying to a text editor.
« Last Edit: May 14, 2010, 09:47:24 PM by SintaxError »

Offline SintaxError

  • Admin
  • Elder Statesman
    of the Surf
  • *****
  • Posts: 1,731
  • There's an error in your sintax.
    • View Profile
    • SolidSurf
Re: System for randomized sequence for teleports
« Reply #1 on: April 18, 2010, 05:41:02 AM »
Explanation:

Basically, given an amount, num_destinations, you iterate that many times, each time picking a new destination to set.

Each iteration starts at the first randomized destination.  First, the logic_case has to pick a winning number, and you can set the chances of winning.  If it's a winner, then you test if the info_teleport_destination has not yet been assigned.  If not, move the info_t_d with a point_teleport and some ai_changetarget trickery.

If the destination was already assigned, try the same thing for the next destination.  Do this until all destinations are assigned.  

To do until all are assigned, we use a logic_branch_listener, which fires after a locationAssigned entity is changed, as long as they are not all true or not all false (they will be all true at the end).

Using this system, the map could come to an almost ordered system, or it could come to a very randomized system. And you can easily change the scattering probabilities.
« Last Edit: April 18, 2010, 05:43:31 AM by SintaxError »

Offline SintaxError

  • Admin
  • Elder Statesman
    of the Surf
  • *****
  • Posts: 1,731
  • There's an error in your sintax.
    • View Profile
    • SolidSurf
Re: System for randomized sequence for teleports
« Reply #2 on: April 19, 2010, 12:26:28 AM »
Just working on implementing this right now.  It's not quite right.

Edit: Maybe not... I have a headache atm and can't think straight.
« Last Edit: April 19, 2010, 12:48:58 AM by SintaxError »

Offline pand3mic

  • Modders
  • Full Member
  • *
  • Posts: 233
  • 0.0
    • View Profile
Re: System for randomized sequence for teleports
« Reply #3 on: July 26, 2010, 10:59:08 PM »
and how does someone put this in a surf map...
I don't want a signature

Offline -[Element]-

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
Re: System for randomized sequence for teleports
« Reply #4 on: August 01, 2010, 11:31:41 PM »
and how does someone put this in a surf map...

If you have to ask, don't bother  \

Offline SintaxError

  • Admin
  • Elder Statesman
    of the Surf
  • *****
  • Posts: 1,731
  • There's an error in your sintax.
    • View Profile
    • SolidSurf
Re: System for randomized sequence for teleports
« Reply #5 on: August 03, 2010, 05:45:40 AM »
If you have to ask, don't bother  \

Ha, true, but it deserves a bit of an explanation I guess.  You basically have to translate it into an entity system in Hammer by hand.  Paste special will do wonders to help you along.

So, say you had 16 destinations...

Code: [Select]
info_teleport_destination  destinations[every num_destinations]

means you should make an info_teleport_destination for each one, and name them as destinations0, destinations1, etc.

The properties and outputs of each group of entities are described in the sets of curly braces. 

For example, this block defines the properties to give each locationAssigned:

Code: [Select]
//perfom whether or not a location has been assigned
logic_branch locationAssigned[every num_destinations]
{
OnFalse->doAssign[this]->Trigger
unless last
{
OnTrue->randomChance[this+1]->PickRandomShuffle
}
else
{
OnTrue->randomChance[0]->PickRandomShuffle
}
}

So, the first of them might look like this:

name: locationAssigned0
Outputs:
OnFalse->doAssign0->Trigger
OnTrue->randomChance2->PickRandomShuffle

the unless/else is for the person creating the system to handle.  The last in the chain of entities has to continue with the first one instead of the next one... so it would look like

name: locationAssigned16
OnFalse->doAssign16->Trigger
OnTrue->randomChance0->PickRandomShuffle

Offline DESE

  • Sr. Member
  • ****
  • Posts: 425
    • View Profile
Re: System for randomized sequence for teleports
« Reply #6 on: August 04, 2010, 08:24:40 PM »
it is called scripting
--
Quote
I'm serious, be productive or gtfo.
--
[/