ProximityMine - What UselessMine should have been

Expand and mod your server.
Post Reply
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

ProximityMine - What UselessMine should have been

Post by Enigma »

ProximityMine 0.2 "Good Enough for Now"

Author: Devin DeLong
BZFlag Name: Enigma
Required BZFlag Version: 2.0.10


The ProximityMine plug-in is essentially an improved version of the UselessMine plug-in. Some of the improvements include the ability to give points for using mines, the ability to remove mines from around a base on flag capture, and the ability to only let the enemy trigger mines. The biggest improvement, however, is under the hood; the code is much nicer than the code in the UselessMine project. In addition, there are two new types of mines: a super bullet mine and a bad flag mine. The super bullet mine is essentially the same as the SR mine, except the shot type is SB, and the bad flag mine tries to give a bad flag instead of killing. There has to be some bad flags on the map for the bad flag mine to work.

Usage

If you type /mine without any parameters, this is what you will see:

Code: Select all

/mine <type>

 sw - Shock wave mine.
 cr - Fast bullet mine (cylindrical pattern)
 sr - Fast bullet mine (spherical pattern)
 bf - Bad flag mine (gives a bad flag)
 sb - Super bullet mine (Spherical pattern)

Options:
show - The server sends information about the mines currently on the map
        (position, type, player ID)
count - Shows the number of mines on the field

set <variable> <value> (not implemented yet)

  Variables:
    spawnSafety (bool) - If true, removes mines from around a base on flag capture
    teamKillSafety (bool) - If true, teammates cannot cause mines to blow up
Please note that even though the set command has not been implemented yet, the variables spawnSafety and teamKillSafety do exist. By default they are set to true, and to change them, you have to recompile.

Compiling

This plugin requires the Boost library to compile. The Boost library is available at http://boost.org/, and is basically an extension to the C++ Standard Library. The parts of the Boost library that are used include: bind, ptr_vector, format, algorithm/string, array, and lexical_cast.

When you rerun autogen.sh and configure, make sure you add the paths to your boost library during the configure step. The used Boost libraries are header only, so you do not have to link to anything. Here is an example:

Code: Select all

	./configure --enable-shared --enable-plugins CPPFLAGS="-I/opt/local/include/boost-1_34_1"
Known Problems (These problems also exist in UselessMine)

One minor problem is that only one of each mine can blow up at once. This is due to how shot IDs are handled; the shot IDs are reused for each mine, and BZFlag does not allow multiple shots with the same ID to exist at once. This, however, is fairly insignificant, since mines blow up quickly.

Sometimes BZFlag will create a shot with an id withing the range [kMineShotIDMin, kMineShotIDMax], resulting in a call to sendKilledMessage(), which shouldn't be called. This, however, from past experience and testing, seems to be a rare event.

Also, the mines are invisible. Unfortunately it is not possible to add temporary objects to the world.

Sometimes mines mysteriously blow up. This seems to happen at the instant a player presses 'i' or right clicks, in order to spawn.
Attachments
ProximityMine-source.tar
(170 KiB) Downloaded 844 times
ProximityMine-Mac-Binary.tar
PowerPC
(160 KiB) Downloaded 571 times
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Post by Enigma »

Here are a few screenshots...

Of all of these photos, Picture 2 is the most significant, as it shows how much better ProximityMine integrates into the game. Scores are finally updated, even the TKs, and the got-killed-messages are no longer server messages. They appear as white text in the console, just like in normal gameplay. Now players will not get spammed by server messages.

In addition, Picture 3 illustrates a slightly more descriptive way of getting the number of mines on the field. In the UselessMine plug-in, this was a number displayed at the end of a got-killed-message sent by the server. It was merely an artifact left over from when I was testing the plug-in and making sure the mines were getting removed when they should. It is, however, nice to know how many mines there are, which is why it is included in the ProximityMine plug-in.

Photo 4 illustrates the new /mine show command. This command may or may not be useful, but it was added and will remain as a part of the plug-in for now. The format is " (x, y, z) : mineType : playerID."

Other Improvements

In the above post, I mentioned that the ProximityMine plug-in has better or nicer code than the UselessMine plug-in that I wrote. This is true; however, explaining everything will most likely take a significant amount of time, so here is an example instead:

Code: Select all

void cleanupMineList()
{
  ml_iterator begin = mineList.begin();
  ml_iterator end = mineList.end();
  
  while(begin != end) {
    UMMinePtr mine = *begin;
    if(!mine->exists) {
      mineList.erase(begin);
      end = mineList.end();
    }
    
    if(begin != end)
      ++begin;
  }
}
This little bit of code is gross; it is resizing a vector while iterating through it. In addition, it is called at the end of every update event, regardless of whether or not mines need to be removed. In ProximityMine, however, mines are removed when they need to be removed, and vectors are not being resized while iterating through them. Here is all of the code in the PlayerPartEvent:

Code: Select all

 Global::mineList.erase_if(std::bind2nd(equal_to<Mine>(), 
                                             eData->playerID));
This is also much easier to read and understand.

(equal_to<Mine> actually has a second template parameter, but the webpage keeps removing it)

Memory Leaks

There should not be any memory leaks in ProximityMine. In UselessMine there were some memory leaks, or at least one that I know of. Thumper, A Delusion, and Constitution (I believe) were kind enough to fix the plug-in and post it on the forums. Many thanks!
Attachments
New killed messages; they aren't sent by the server, cluttering the chatbox
New killed messages; they aren't sent by the server, cluttering the chatbox
Picture 2.png (87.24 KiB) Viewed 6150 times
How &amp;quot;/mine count&amp;quot; looks.
How &quot;/mine count&quot; looks.
Picture 3.png (36.15 KiB) Viewed 6273 times
How &amp;quot;/mine show&amp;quot; looks.  Only admins can use it.
How &quot;/mine show&quot; looks. Only admins can use it.
Picture 4.png (46.93 KiB) Viewed 6283 times
User avatar
jftsang
Private First Class
Private First Class
Posts: 64
Joined: Sat Mar 03, 2007 11:32 am
Location: United Kingdom
Contact:

Post by jftsang »

It looks promising. How about a Windows binary?

JeffM compiled one earlier for Windows; it does not appear to work on my BZFS and appeared to cause BZFS to disconnect whenever I grab a flag or send a message. Apparently it works for JeffM; I will try to try again.
User avatar
Gabriel G
Private First Class
Private First Class
Posts: 73
Joined: Thu Apr 12, 2007 1:03 am
Location: North Carolina
Contact:

Post by Gabriel G »

Great Job Enigma :)
Use the Search and Edit buttons as your question may have already been answered/posted.

Image
Image


Image
User avatar
macsforme
General
General
Posts: 2069
Joined: Wed Mar 01, 2006 5:43 am

Post by macsforme »

I propose the following enhancement: have the plugin check spawn positions for players requesting them and ensure that they do not spawn near a mine. I believe this is possible, but haven't looked closely at the API recently...
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Post by Enigma »

What about this?

Code: Select all


case bz_eGetPlayerSpawnPosEvent:
    {
      bzf::GetPlayerSpawnPosEventData* data = 
        dynamic_cast<bzf::GetPlayerSpawnPosEventData*>(eventData);
      
      if(Global::mineList.size() == 0)
        return;
      
      float safeRadius = 1.2 * float(bz_getBZDBDouble("_shockOutRadius"));
      
      boost::ptr_vector<Mine>::iterator mine = Global::mineList.begin();
      boost::ptr_vector<Mine>::iterator end = Global::mineList.end();
      
      std::size_t numTries = 3;
      
      while(mine != end) {
        
        bz_eTeamType mineTeam = Global::players.get(mine->playerID()).team;
        
        if(data->team == mineTeam &&
           data->team != eRogueTeam && Global::teamKillSafety) {
          ++mine;
          continue;
        }
        
        if(numTries == 0)
          break;
        
        if( distance3f(mine->position().data(), data->pos) < safeRadius ) {
          bz_getStandardSpawn(data->playerID, data->pos, &data->rot);
          --numTries;
          
          // Start over to check the new spawn position.
          // The loop will finish when it is safe or when
          // the number of tries has been used up.
          mine = Global::mineList.begin();
          continue;
        }
        
        ++mine;
      }
      
      if(numTries == 3)
        data->handled = false;
      else
        data->handled = true;
      
    }
      break;
It compiles, but will it work...

Some stuff has changed in my copy of the plug-in. The two lines

Code: Select all

bz_eTeamType mineTeam = Global::players.get(mine->playerID()).team;
and

Code: Select all

bzf::GetPlayerSpawnPosEventData
won't work in the plug-in posted here.

The first line is just a class that keeps PlayerRecords of all the players connected to the server. Its purpose is to reduce memory allocation and deallocation. I'm not sure if this is a good idea though. The second line is just a typedef that helps me compile the same code on different API versions.

I'm guessing that bz_getStandardSpawn() returns a different spawn position every time it's called.

I would like to do this differently, but using bz_getStandardSpawn() is the only way I know how to keep players from spawning in buildings.
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Post by Enigma »

jftsang wrote:It looks promising. How about a Windows binary?

JeffM compiled one earlier for Windows; it does not appear to work on my BZFS and appeared to cause BZFS to disconnect whenever I grab a flag or send a message. Apparently it works for JeffM; I will try to try again.
I will eventually post a win32 binary. I just installed Visual Studio C++ Express 2008, but I need some time to figure out this environment. Even using "C:/" instead of "/" is odd to me. Once I familiarize myself with the Command Prompt or install the Bash shell (if it's possible), things should move along quickly.
User avatar
jftsang
Private First Class
Private First Class
Posts: 64
Joined: Sat Mar 03, 2007 11:32 am
Location: United Kingdom
Contact:

Post by jftsang »

Here's a Windows binary
Attachments
ProximityMine.zip
ProximityMine Windows binary
(89.74 KiB) Downloaded 516 times
User avatar
SpringTank
Private First Class
Private First Class
Posts: 41
Joined: Sun Nov 02, 2008 11:11 pm
Location: Texas
Contact:

need help

Post by SpringTank »

I can't get it to work for me. I says "error: exception handling disabled, use -fexceptions to enable"

Were do i use -fexceptions?
Last edited by SpringTank on Thu May 14, 2009 3:58 am, edited 1 time in total.
More than likely there is a species out there that can naturally detect radio. I can only imagine that they are quite annoyed by us.
KF5QEK
I also fly stuff sometimes.
Anxuiz
Private First Class
Private First Class
Posts: 31
Joined: Fri Sep 05, 2008 3:38 am

Re: ProximityMine - What UselessMine should have been

Post by Anxuiz »

I compiled another DLL for ProximityMine and changed things around with the source (deleted mac specific files and changed the vcproj file so it includes what it should). NOTE: This zip package is for WINDOWS users ONLY. The package includes:
  • Boost license (LICENSE_1_0.txt)
  • Visual C++ 8 project files.
  • README
  • Source files.
  • ProximityMine.dll (built against the BZFlag2.0.10 API)
EDIT: I've been trying it on my server...but it doesn't work?
Attachments
ProximityMine.zip
Win32 package, DLL + Source
(112.84 KiB) Downloaded 286 times
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Re: ProximityMine - What UselessMine should have been

Post by Enigma »

Yassen wrote: EDIT: I've been trying it on my server...but it doesn't work?
Well that sucks. I suppose I could make this a weekend project before classes start. There are a few things that have been keeping me from even looking at this plug-in though.

One is BZFlag itself. At first I stopped writing plug-ins for the 2.0 branch, as I kept getting some "cycle in dylib" error. Just recently, however, I found that this was due to linking against x11, according to some document at OpenSceneGraph.org. As a result, I started writing plug-ins for the 3.0 branch, but that didn't last long; many things were not working (but this is expected), which made it difficult to test the plug-ins. Every once in a while I compile BZFlag3.0, but I have not written any plug-ins since the summer.

In addition, I am not sure where to go with this plug-in. It started as a small experiment to learn the API. Initially I wanted to make a shock wave blast when a shot ends, similar to new real-world ammunition that you can shoot through a window and it explodes over the enemy's head. This was not possible though. Anyways, I settled on mines. I feel there are too many different types of mines and would like to simplify the plug-in, but I am not sure how I should simplify it. I have, however, been meaning to ask what people would like to see happen to this plug-in.

These are some ideas I have for the plug-in:
  • Stick to one type of mine.
  • Add a random delay time so that mines are less perfect at killing.
  • Remove the Boost library dependency.
  • Make my crappy code nice.
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Re: ProximityMine - What UselessMine should have been

Post by Enigma »

Yassen, maybe just try running make clean on the plug-in and rebuilding it. Also, make sure you used the included Makefile.am, since there are multiple source files; the default Makefile.am file will not work. If you can elaborate on the problems you are having, rather than "it is not working," I could help you more.

I am re-writing this plug-in for BZFlag3.0 and will not make any modifications to the 2.0 code.

In addition, I mentioned I might remove the Boost library dependency. After some thought, I decided I would simply include the boost library with the plug-in. After all, this plug-in only requires the header-only Boost libraries. No compiling is needed.
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Re: need help

Post by Enigma »

TheFish wrote:I can't get it to work for me. I says "error: exception handling disabled, use -fexceptions to enable"

Were do i use -fexceptions?
Assuming you really have to enable exceptions, you would have to pass -fexceptions to configure. I suppose you could just do

Code: Select all

./configure CXXFLAGS="$CXXFLAGS -fexceptions"

Sorry for responding so late.
User avatar
Dontkillme
Private First Class
Private First Class
Posts: 69
Joined: Thu May 15, 2008 4:42 pm
Location: Germany

Re: ProximityMine - What UselessMine should have been

Post by Dontkillme »

If I join the server my bzfs.exe shows an error.
Attachments

[The extension bmp has been deactivated and can no longer be displayed.]

User avatar
blast
General
General
Posts: 4931
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Re: ProximityMine - What UselessMine should have been

Post by blast »

Dont kill my im a beginer wrote:If I join the server my bzfs.exe shows an error.
That means it crashed. Compile your own version with VC7.1, or (if you don't have 7.1) build a new binary of bzfs with Visual C++ 2005 Express and build the plugin against that binary.
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image
User avatar
SpringTank
Private First Class
Private First Class
Posts: 41
Joined: Sun Nov 02, 2008 11:11 pm
Location: Texas
Contact:

Re: need help

Post by SpringTank »

Enigma wrote:
TheFish wrote:I can't get it to work for me. I says "error: exception handling disabled, use -fexceptions to enable"

Were do i use -fexceptions?
Assuming you really have to enable exceptions, you would have to pass -fexceptions to configure. I suppose you could just do

Code: Select all

./configure CXXFLAGS="$CXXFLAGS -fexceptions"

Sorry for responding so late.

Thanks Enigma, it works now.

I heard you can't have temporary objects in BZFlag to show were the mine is, what about a bullet?
When you place a mine it places a "rouge" bullet in its place to indicate were the mine is, when the mine explodes the bullet explodes. Just a thought.


.
Last edited by SpringTank on Thu May 14, 2009 3:58 am, edited 1 time in total.
More than likely there is a species out there that can naturally detect radio. I can only imagine that they are quite annoyed by us.
KF5QEK
I also fly stuff sometimes.
Anxuiz
Private First Class
Private First Class
Posts: 31
Joined: Fri Sep 05, 2008 3:38 am

Re: ProximityMine - What UselessMine should have been

Post by Anxuiz »

Enigma:

Yeah, I was looking at the code and it looks a bit overly complex :P
I might try rewriting it with a little bit of Yassen simplicity for a project soon :)

TheFish:

I like the bullet idea...but I would do a shockwave and make it have a delay to it. I'm also not sure there is a bz_endShot(shotID) function, but I have an idea to find a way past it.

-Yassen
MATSTERMIND
Private
Private
Posts: 4
Joined: Wed Jun 24, 2009 3:32 pm

Re: ProximityMine - What UselessMine should have been

Post by MATSTERMIND »

Yassen wrote:I compiled another DLL for ProximityMine and changed things around with the source (deleted mac specific files and changed the vcproj file so it includes what it should). NOTE: This zip package is for WINDOWS users ONLY. The package includes:
  • Boost license (LICENSE_1_0.txt)
  • Visual C++ 8 project files.
  • README
  • Source files.
  • ProximityMine.dll (built against the BZFlag2.0.10 API)
EDIT: I've been trying it on my server...but it doesn't work?
how do i install it to bzflag?
User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5196
Joined: Fri Dec 13, 2002 4:11 am

Re: ProximityMine - What UselessMine should have been

Post by JeffM »

It is a plug-in for the server. You get the correct version for your OS, and add -loadplugin then the path to the plug-in file to your server config.

Plug-ins are not used by the game client.
ImageJeffM
MATSTERMIND
Private
Private
Posts: 4
Joined: Wed Jun 24, 2009 3:32 pm

Re: ProximityMine - What UselessMine should have been

Post by MATSTERMIND »

i have a windows xp, i don't know how to "add -loadplugin then the path to the plug-in file to your server config." i have the right version (i think).
User avatar
blast
General
General
Posts: 4931
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Re: ProximityMine - What UselessMine should have been

Post by blast »

Then you shouldn't be running a server.
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image
Post Reply