Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Looking 360 degrees?
Looking 360 degrees?
2004-12-09, 5:20 PM #1
What's the best and quickest method for finding everything within x-radius, 360 degrees around a target thing?
</sarcasm>
<Anovis> mmmm I wanna lick your wet, Mentis.
__________
2004-12-09, 6:34 PM #2
I've never done thoughrough testing on this code to make sure it catches everything within 360 degrees, but there's no reason it shouldn't work.

Code:
   victim = FirstThingInView(player, 180, 10, 0x404);
   while(victim != -1)
   {
      if(
         HasLOS(player, victim) &&
         (victim != player) &&
         (VectorDist(GetThingPos(player), GetThingPos(potential)) <= 1) &&
         !(GetThingFlags(victim) & 0x200) &&
         !(GetActorFlags(victim) & 0x100) &&
         !((jkGetFlags(victim) & 0x20) && !IsInvActivated(player, 23))
        )
      {
          // Do Stuff To Victim Or Record Victim For Later Use
      }
      victim = NextThingInView();
   }
   SetThingLook(player, VectorScale(GetThingLVec(player), -1));
   victim = FirstThingInView(player, 180, 10, 0x404);
   while(victim != -1)
   {
      if(
         HasLOS(player, victim) &&
         (victim != player) &&
         (VectorDist(GetThingPos(player), GetThingPos(potential)) <= 1) &&
         !(GetThingFlags(victim) & 0x200) &&
         !(GetActorFlags(victim) & 0x100) &&
         !((jkGetFlags(victim) & 0x20) && !IsInvActivated(player, 23))
        )
      {
          // Do Stuff To Victim Or Record Victim For Later Use
      }
      victim = NextThingInView();
   }
   SetThingLook(player, VectorScale(GetThingLVec(player), -1));


Another way to do it would be something as follows, but I've never even checked the syntax for correctness with the following code
Code:
   for(x=0; x<GetSectorCount(); x=x+1)
   {
      for(y=FirstThingInSector(x), z=0; z<GetSectorThingCount(x); y=NextThingInSector(y), z=z+1)
      {
         if((GetThingType(y) == DesiredType) &&
         (y != player) &&
         (HasLOS(player, y) &&
         (VectorDist(GetThingPos(player), GetThingPos(y)) <= 1))
         {
            // Do Stuff To y Or Record y For Later Use
         }
      }
   }


Quote:
360 degrees around a target thing?

If you want 360 degrees around something besides the player, replace the word player with whatever the thing is you want to use.

QM

Edit: forgot HasLOS
2004-12-11, 6:28 AM #3
Quib: Does that produce any noticeable 'flicker' as the player is turned around?

Also, if you are using MotS, the bubble verbs and the sendmessageradius() verb work well here.
-El Scorcho

"Its dodgeball time!" -Stormy Waters
2004-12-11, 12:08 PM #4
^^ If it does you could fire a ghost instead, look, then destroy.
May the mass times acceleration be with you.
2004-12-11, 6:18 PM #5
I tried the first bit of code, and it doesn't 100% work all the time but it's good enough. Thanks
</sarcasm>
<Anovis> mmmm I wanna lick your wet, Mentis.
__________

↑ Up to the top!