Skip to content

Commit

Permalink
Fix the astyle command in DEVINFO and run it again, so now the plugin…
Browse files Browse the repository at this point in the history
…s and tools get fixed.
  • Loading branch information
blast007 committed Jul 27, 2018
1 parent 4c43e78 commit f46a334
Show file tree
Hide file tree
Showing 48 changed files with 7,336 additions and 6,716 deletions.
4 changes: 2 additions & 2 deletions DEVINFO
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ follow the BZFlag style if you want your contribution included.
BZFlag is formated using the Allman Style, and this is enforced
with the artistic styler, astyle, using these command line options:

astyle --style=allman -nxjz1 --convert-tabs --max-code-length=120 \
--recursive /path/to/code/*.cxx,*.h,*.c
astyle --style=allman -nxj --convert-tabs --max-code-length=120 \
--recursive './*.cxx' './*.cpp' './*.h'

The source code serves for examples of the following rules.

Expand Down
8 changes: 4 additions & 4 deletions misc/Template.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
/*
* Local Variables: ***
* mode: C++ ***
* tab-width: 8 ***
* c-basic-offset: 2 ***
* indent-tabs-mode: t ***
* tab-width: 4 ***
* c-basic-offset: 4 ***
* indent-tabs-mode: nil ***
* End: ***
* ex: shiftwidth=2 tabstop=8
* ex: shiftwidth=4 tabstop=4
*/
14 changes: 7 additions & 7 deletions misc/Template.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// Template.h
// A short description of the module's function

#ifndef TEMPLATE_H
#define TEMPLATE_H
#ifndef __TEMPLATE_H__
#define __TEMPLATE_H__


#include "common.h"
Expand All @@ -27,15 +27,15 @@



#endif // TEMPLATE_H
#endif // __TEMPLATE_H__


/*
* Local Variables: ***
* mode: C++ ***
* tab-width: 8 ***
* c-basic-offset: 2 ***
* indent-tabs-mode: t ***
* tab-width: 4 ***
* c-basic-offset: 4 ***
* indent-tabs-mode: nil ***
* End: ***
* ex: shiftwidth=2 tabstop=8
* ex: shiftwidth=4 tabstop=4
*/
182 changes: 91 additions & 91 deletions plugins/CustomZoneSample/CustomZoneSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,134 +9,134 @@
class MsgZone : public bz_CustomZoneObject
{
public:
// Our custom constructor will call the parent constructor so we can setup default positions
// for the zone
MsgZone() : bz_CustomZoneObject(), flag("US")
{
}

// Custom fields that are unique to our zone so we can build on top of the class we're extending
std::string message;
std::string flag;
// Our custom constructor will call the parent constructor so we can setup default positions
// for the zone
MsgZone() : bz_CustomZoneObject(), flag("US")
{
}

// Custom fields that are unique to our zone so we can build on top of the class we're extending
std::string message;
std::string flag;
};

class CustomZoneSample : public bz_Plugin, bz_CustomMapObjectHandler
{
public:
virtual const char* Name () {return "Custom Zone Sample";}
virtual void Init ( const char* config );
virtual void Event ( bz_EventData *eventData );
virtual void Cleanup ( void );
virtual const char* Name ()
{
return "Custom Zone Sample";
}
virtual void Init ( const char* config );
virtual void Event ( bz_EventData *eventData );
virtual void Cleanup ( void );

virtual bool MapObject (bz_ApiString object, bz_CustomMapObjectInfo *data);
virtual bool MapObject (bz_ApiString object, bz_CustomMapObjectInfo *data);

std::vector<MsgZone> msgZones;
std::vector<MsgZone> msgZones;

bool messageSentTo[256];
bool messageSentTo[256];
};

BZ_PLUGIN(CustomZoneSample)

void CustomZoneSample::Init (const char* /*commandLine*/)
{
Register(bz_ePlayerUpdateEvent);
Register(bz_ePlayerUpdateEvent);

// Whenever a player enters a zone and is carrying a specified flag, they will receive the specified message
bz_registerCustomMapObject("msgzone", this);
// Whenever a player enters a zone and is carrying a specified flag, they will receive the specified message
bz_registerCustomMapObject("msgzone", this);
}

void CustomZoneSample::Cleanup (void)
{
Flush();
Flush();

bz_removeCustomMapObject("msgzone");
bz_removeCustomMapObject("msgzone");
}

bool CustomZoneSample::MapObject (bz_ApiString object, bz_CustomMapObjectInfo *data)
{
if (object != "MSGZONE" || !data)
return false;

// The new zone we just found and we'll be storing in our vector of zones
MsgZone newZone;

// This function will parse the attributes that are handled by bz_CustomZoneObject which
// handles rectangular and circular zones
//
// For rectangular zones:
// - position
// - size
// - rotation
//
// For circular zones:
// - position
// - height
// - radius
//
// This also handles BBOX and CYLINDER fields but they have been deprecated and will be
// removed in the future
newZone.handleDefaultOptions(data);

// Loop through the object data
for (unsigned int i = 0; i < data->data.size(); i++)
{
std::string line = data->data.get(i).c_str();

bz_APIStringList *nubs = bz_newStringList();
nubs->tokenize(line.c_str(), " ", 0, true);

if (nubs->size() > 0)
if (object != "MSGZONE" || !data)
return false;

// The new zone we just found and we'll be storing in our vector of zones
MsgZone newZone;

// This function will parse the attributes that are handled by bz_CustomZoneObject which
// handles rectangular and circular zones
//
// For rectangular zones:
// - position
// - size
// - rotation
//
// For circular zones:
// - position
// - height
// - radius
//
// This also handles BBOX and CYLINDER fields but they have been deprecated and will be
// removed in the future
newZone.handleDefaultOptions(data);

// Loop through the object data
for (unsigned int i = 0; i < data->data.size(); i++)
{
std::string key = bz_toupper(nubs->get(0).c_str());

// These are our custom fields in the MsgZone class
if (key == "MESSAGE" && nubs->size() > 1)
{
newZone.message = nubs->get(1).c_str();
}
else if (key == "FLAG" && nubs->size() > 1)
{
newZone.flag = nubs->get(1).c_str();
}
}
std::string line = data->data.get(i).c_str();

bz_deleteStringList(nubs);
}
bz_APIStringList *nubs = bz_newStringList();
nubs->tokenize(line.c_str(), " ", 0, true);

msgZones.push_back(newZone);
if (nubs->size() > 0)
{
std::string key = bz_toupper(nubs->get(0).c_str());

return true;
// These are our custom fields in the MsgZone class
if (key == "MESSAGE" && nubs->size() > 1)
newZone.message = nubs->get(1).c_str();
else if (key == "FLAG" && nubs->size() > 1)
newZone.flag = nubs->get(1).c_str();
}

bz_deleteStringList(nubs);
}

msgZones.push_back(newZone);

return true;
}

void CustomZoneSample::Event (bz_EventData *eventData)
{
switch (eventData->eventType)
{
switch (eventData->eventType)
{
case bz_ePlayerUpdateEvent: // This event is called each time a player sends an update to the server
{
bz_PlayerUpdateEventData_V1* updateData = (bz_PlayerUpdateEventData_V1*)eventData;

// Loop through all of our custom zones
for (unsigned int i = 0; i < msgZones.size(); i++)
{
// Use the pointInZone(float pos[3]) function provided by the bz_CustomZoneObject to check if the position
// of the player is inside of the zone. This function will automatically handle the logic if the zone is a
// rectangle (even if it's rotated) or a circle
if (msgZones[i].pointInZone(updateData->state.pos) && bz_getPlayerFlagID(updateData->playerID) >= 0)
{
// If the player has the flag specified in the zone, send them a message and remove their flag
if (strcmp(bz_getPlayerFlag(updateData->playerID), msgZones[i].flag.c_str()) == 0)
{
bz_sendTextMessage(BZ_SERVER, updateData->playerID, msgZones[i].message.c_str());
bz_removePlayerFlag(updateData->playerID);
}
}
}
bz_PlayerUpdateEventData_V1* updateData = (bz_PlayerUpdateEventData_V1*)eventData;

// Loop through all of our custom zones
for (unsigned int i = 0; i < msgZones.size(); i++)
{
// Use the pointInZone(float pos[3]) function provided by the bz_CustomZoneObject to check if the position
// of the player is inside of the zone. This function will automatically handle the logic if the zone is a
// rectangle (even if it's rotated) or a circle
if (msgZones[i].pointInZone(updateData->state.pos) && bz_getPlayerFlagID(updateData->playerID) >= 0)
{
// If the player has the flag specified in the zone, send them a message and remove their flag
if (strcmp(bz_getPlayerFlag(updateData->playerID), msgZones[i].flag.c_str()) == 0)
{
bz_sendTextMessage(BZ_SERVER, updateData->playerID, msgZones[i].message.c_str());
bz_removePlayerFlag(updateData->playerID);
}
}
}
}
break;

default: break;
}
default:
break;
}
}

// Local Variables: ***
Expand Down
Loading

0 comments on commit f46a334

Please sign in to comment.