Server Help

Bot Questions - Problem.

Martian Manhunter - Sun Mar 19, 2006 3:44 am
Post subject: Problem.
what is wrong with this plugin?

Code: Show/Hide
#include "spawn.h"

#include "..\algorithms.h"

#include "..\dllcore.cpp"
#include "..\datatypes.cpp"
#include "..\algorithms.cpp"
#include "..\player.cpp"
#include "..\commtypes.cpp"

#define UNASSIGNED 0xffff


//////// Bot list ////////

_linkedlist <botInfo> botlist;

botInfo *findBot(CALL_HANDLE handle)
{
   _listnode <botInfo> *parse = botlist.head;

   while (parse)
   {
      botInfo *item = parse->item;

      if (item->validate(handle))
         return item;

      parse = parse->next;
   }

   return 0;
}


//////// DLL "import" ////////

void botInfo::tell(BotEvent event)
{
   if (callback && handle)
   {
      event.handle = handle;
      callback(event);
   }
}

void botInfo::gotEvent(BotEvent &event)
{
   if (CONNECTION_DENIED) return;

   switch (event.code)
   {
//////// Periodic ////////
   case EVENT_Tick:
      {
         for (int i = 0; i < 4; ++i)
            --countdown[i];
      }
      break;
//////// Arena ////////
   case EVENT_ArenaEnter:
      {
         arena = (char*)event.p[0];
         me = (Player*)event.p[1];   // if(me) {/*we are in the arena*/}
         bool biller_online = *(bool*)&event.p[2];
      }
      break;
   case EVENT_ArenaSettings:
      {
         settings = (arenaSettings*)event.p[0];
      }
      break;
   case EVENT_ArenaLeave:
      {
         me = 0;
         killTags();
      }
      break;
   case EVENT_ArenaListEntry:
      {
         char *name = (char*)event.p[0];
         bool current = *(bool*)&event.p[1];
         int population = *(int*)&event.p[2];
      }
      break;
   case EVENT_ArenaListEnd:
      {
         char *name = (char*)event.p[0];
         bool current = *(bool*)&event.p[1];
         int population = *(int*)&event.p[2];
      }
      break;
//////// Flag ////////
   case EVENT_FlagGrab:
      {
         Player *p = (Player*)event.p[0];
         Flag *f = (Flag*)event.p[1];
      }
      break;
   case EVENT_FlagDrop:
      {
         Player *p = (Player*)event.p[0];
      }
      break;
   case EVENT_FlagMove:
      {
         Flag *f = (Flag*)event.p[0];
      }
      break;
   case EVENT_FlagVictory:
      {
         int team = *(int*)&event.p[0];
         int reward = *(int*)&event.p[1];
      }
      break;
   case EVENT_FlagGameReset:
      {
      }
      break;
   case EVENT_FlagReward:
      {
         int team = *(int*)&event.p[0];
         int reward = *(int*)&event.p[1];
      }
      break;
//////// Timed ////////
   case EVENT_TimedGameOver:
      {
         Player *p[5];
         for (int i = 0; i < 5; i++)
            p[i] = (Player*)event.p[i];
      }
      break;
//////// Soccer ////////
   case EVENT_SoccerGoal:
      {
         int team = *(int*)&event.p[0];
         int reward = *(int*)&event.p[1];
      }
      break;
   case EVENT_BallMove:
      {
         PBall *ball = (PBall*)event.p[0];
      }
      break;
//////// File ////////
   case EVENT_File:
      {
         char *name = (char*)event.p[0];
      }
      break;
//////// Player ////////
   case EVENT_PlayerEntering:
      {
         Player *p = (Player*)event.p[0];
         sendPrivate(p,"Hi, " + (String) p->name + " with " + (String) p->score.killPoints + " kill points, how are you?");
      }
      break;
   case EVENT_PlayerMove:
      {
         Player *p = (Player*)event.p[0];
      }
      break;
   case EVENT_PlayerWeapon:
      {
         Player *p = (Player*)event.p[0];
         weaponInfo wi;
         wi.n = *(Uint16*)&event.p[1];
      }
      break;
   case EVENT_WatchDamage:
      {
         Player *p = (Player*)event.p[0];   // player
         Player *k = (Player*)event.p[1];   // attacker
         weaponInfo wi;
         wi.n = *(Uint16*)&event.p[2];
         Uint16 energy = *(Uint16*)&event.p[3];
         Uint16 damage = *(Uint16*)&event.p[4];
      }
      break;
   case EVENT_PlayerDeath:
      {
         Player *p = (Player*)event.p[0],
               *k = (Player*)event.p[1];
         Uint16 bounty = (Uint16)(Uint32)event.p[2];
         Uint16 flags = (Uint16)event.p[3];
      }
      break;
   case EVENT_BannerChanged:
      {
         Player *p = (Player*)event.p[0];
      }
      break;
   case EVENT_PlayerScore:
      {
         Player *p = (Player*)event.p[0];
      }
      break;
   case EVENT_PlayerPrize:
      {
         Player *p = (Player*)event.p[0];
         int prize = *(int *)&event.p[1];
      }
      break;
   case EVENT_PlayerShip:
      {
         Player *p = (Player*)event.p[0];
         Uint16 oldship = (Uint16)(Uint32)event.p[1];
         Uint16 oldteam = (Uint16)(Uint32)event.p[2];
      }
      break;
   case EVENT_PlayerSpec:
      {
         Player *p = (Player*)event.p[0];
         Uint16 oldteam = (Uint16)(Uint32)event.p[1];
         Uint16 oldship = (Uint16)(Uint32)event.p[2];
      }
      break;
   case EVENT_PlayerTeam:
      {
         Player *p = (Player*)event.p[0];
         Uint16 oldteam = (Uint16)(Uint32)event.p[1];
         Uint16 oldship = (Uint16)(Uint32)event.p[2];
      }
      break;
   case EVENT_PlayerLeaving:
      {
         Player *p = (Player*)event.p[0];

         killTags(p);
      }
      break;
//////// Selfish ////////
   case EVENT_SelfShipReset:
      {
      }
      break;
   case EVENT_SelfPrize:
      {
         Uint16 prize = (Uint16)(Uint32)event.p[0];
         Uint16 count = (Uint16)(Uint32)event.p[1];
      }
      break;
   case EVENT_SelfUFO:
      {
      }
      break;
   case EVENT_PositionHook:
      {
      }
      break;
//////// Bricks ////////
   case EVENT_BrickDropped:
      {
         int x1 = *(int*)&event.p[0];
         int y1 = *(int*)&event.p[1];
         int x2 = *(int*)&event.p[2];
         int y2 = *(int*)&event.p[3];
         int team = *(int*)&event.p[4];
      }
      break;
//////// LVZ ////////
   case EVENT_ObjectToggled:
      {
         objectInfo obj;
         obj.n = (Uint16)(Uint32)event.p[0];
      }
      break;
//////// Turret ////////
   case EVENT_CreateTurret:
      {
         Player *turreter = (Player*)event.p[0];
         Player *turretee = (Player*)event.p[1];
      }
      break;
   case EVENT_DeleteTurret:
      {
         Player *turreter = (Player*)event.p[0];
         Player *turretee = (Player*)event.p[1];
      }
      break;
//////// Chat ////////
   case EVENT_Chat:
      {
         int type  = *(int*)&event.p[0];
         int sound = *(int*)&event.p[1];
         Player *p = (Player*)event.p[2];
         char *msg = (char*)event.p[3];

         switch (type)
         {
         case MSG_Arena:
            {
            }
            break;
         case MSG_PublicMacro:      if (!p) break;
            {
            }
            break;
         case MSG_Public:         if (!p) break;
            {
            }
            break;
         case MSG_Team:            if (!p) break;
            {
            }
            break;
         case MSG_TeamPrivate:      if (!p) break;
            {
            }
            break;
         case MSG_Private:         if (!p) break;
            {
            }
            break;
         case MSG_PlayerWarning:      if (!p) break;
            {
            }
            break;
         case MSG_RemotePrivate:
            {
            }
            break;
         case MSG_ServerError:
            {
            }
            break;
         case MSG_Channel:
            {
            }
            break;
         };
      }
      break;
   case EVENT_LocalCommand:
      {
         Player *p = (Player*)event.p[0];
         Command *c = (Command*)event.p[1];

         gotCommand(p, c);
      }
      break;
   case EVENT_LocalHelp:
      {
         Player *p = (Player*)event.p[0];
         Command *c = (Command*)event.p[1];

         gotHelp(p, c);
      }
      break;
   case EVENT_RemoteCommand:
      {
         char *p = (char*)event.p[0];
         Command *c = (Command*)event.p[1];
         Operator_Level o = *(Operator_Level*)&event.p[2];

         gotRemote(p, c, o);
      }
      break;
   case EVENT_RemoteHelp:
      {
         char *p = (char*)event.p[0];
         Command *c = (Command*)event.p[1];
         Operator_Level o = *(Operator_Level*)&event.p[2];

         gotRemoteHelp(p, c, o);
      }
      break;
//////// Containment ////////
   case EVENT_Init:
      {
         int major   = HIWORD(*(int*)&event.p[0]);
         int minor   = LOWORD(*(int*)&event.p[0]);
         callback   = (CALL_COMMAND)event.p[1];
         playerlist   = (CALL_PLIST)event.p[2];
         flaglist   = (CALL_FLIST)event.p[3];
         map         = (CALL_MAP)event.p[4];
         bricklist   = (CALL_BLIST)event.p[5];

         if (major > CORE_MAJOR_VERSION)
         {
            tell(makeEcho("DLL plugin cannot connect.  This plugin is out of date."));

            CONNECTION_DENIED = true;

            return;
         }
         else if ((major < CORE_MAJOR_VERSION) || (minor < CORE_MINOR_VERSION))
         {
            tell(makeEcho("DLL plugin cannot connect.  This plugin requires the latest version of MERVBot."));

            CONNECTION_DENIED = true;

            return;
         }
         else
            tell(makeEcho("DLL plugin connected."));

      }
      break;
   case EVENT_Term:
      {
         tell(makeEcho("DLL plugin disconnected."));
      }
      break;
   };
}


//////// DLL export ////////

_declspec(dllexport) void __stdcall talk(BotEvent &event)
{
   botInfo *bot;

   bot = findBot(event.handle);

   if (!bot)
   {
      bot = new botInfo(event.handle);
      botlist.append(bot);
   }

   if (bot) bot->gotEvent(event);
}


//////// Tag emulation ////////

int botInfo::get_tag(Player *p, int index)
{
   _listnode <PlayerTag> *parse = taglist.head;
   PlayerTag *tag;

   while (parse)
   {
      tag = parse->item;

      if (tag->p == p)
      if (tag->index == index)
         return tag->data;

      parse = parse->next;
   }

   return 0;
}

void botInfo::set_tag(Player *p, int index, int data)
{
   _listnode <PlayerTag> *parse = taglist.head;
   PlayerTag *tag;

   while (parse)
   {
      tag = parse->item;

      if (tag->p == p)
      if (tag->index == index)
      {
         tag->data = data;
         return;
      }

      parse = parse->next;
   }

   tag = new PlayerTag;
   tag->p = p;
   tag->index = index;
   tag->data = data;
   taglist.append(tag);
}

void botInfo::killTags(Player *p)
{
   _listnode <PlayerTag> *parse = taglist.head;
   PlayerTag *tag;

   while (parse)
   {
      tag = parse->item;
      parse = parse->next;

      if (tag->p != p) continue;

      taglist.kill(tag);
   }
}

void botInfo::killTags()
{
   taglist.clear();
}


//////// LVZ Object Toggling ////////

void botInfo::clear_objects()
{
   num_objects = 0;
}

void botInfo::object_target(Player *p)
{
   object_dest = p;
}

void botInfo::toggle_objects()
{
   Player *p = object_dest;

   if (!p)   tell(makeToggleObjects(UNASSIGNED, (Uint16 *)object_array, num_objects));
   else   tell(makeToggleObjects(p->ident, (Uint16 *)object_array, num_objects));

   num_objects = 0;
}

void botInfo::queue_enable(int id)
{
   if (num_objects == MAX_OBJECTS)
      toggle_objects();

   object_array[num_objects].id = id;
   object_array[num_objects].disabled = false;
   ++num_objects;
}

void botInfo::queue_disable(int id)
{
   if (num_objects == MAX_OBJECTS)
      toggle_objects();

   object_array[num_objects].id = id;
   object_array[num_objects].disabled = true;
   ++num_objects;
}


//////// Chatter ////////

void botInfo::sendPrivate(Player *player, BYTE snd, char *msg)
{
   tell(makeSay(MSG_Private, snd, player->ident, msg));
}

void botInfo::sendPrivate(Player *player, char *msg)
{
   tell(makeSay(MSG_Private, 0, player->ident, msg));
}

void botInfo::sendTeam(char *msg)
{
   tell(makeSay(MSG_Team, 0, 0, msg));
}

void botInfo::sendTeam(BYTE snd, char *msg)
{
   tell(makeSay(MSG_Team, snd, 0, msg));
}

void botInfo::sendTeamPrivate(Uint16 team, char *msg)
{
   tell(makeSay(MSG_TeamPrivate, 0, team, msg));
}

void botInfo::sendTeamPrivate(Uint16 team, BYTE snd, char *msg)
{
   tell(makeSay(MSG_TeamPrivate, snd, team, msg));
}

void botInfo::sendPublic(char *msg)
{
   tell(makeSay(MSG_Public, 0, 0, msg));
}

void botInfo::sendPublic(BYTE snd, char *msg)
{
   tell(makeSay(MSG_Public, snd, 0, msg));
}

void botInfo::sendPublicMacro(char *msg)
{
   tell(makeSay(MSG_PublicMacro, 0, 0, msg));
}

void botInfo::sendPublicMacro(BYTE snd, char *msg)
{
   tell(makeSay(MSG_PublicMacro, snd, 0, msg));
}

void botInfo::sendChannel(char *msg)
{
   tell(makeSay(MSG_Channel, 0, 0, msg));
}

void botInfo::sendRemotePrivate(char *msg)
{
   tell(makeSay(MSG_RemotePrivate, 0, 0, msg));
}

void botInfo::sendRemotePrivate(char *name, char *msg)
{
   String s;
   s += ":";
   s += name;
   s += ":";
   s += msg;

   sendRemotePrivate(s);
}


Mod Note: Use 'preview' button in the future. -MGB
SamHughes - Sun Mar 19, 2006 10:40 am
Post subject: Re: Problem.
Martian Manhunter wrote:
what is wrong with this plugin?


Its code wasn't posted using [code] tags and you haven't explained the errors you've been getting.
Muskrat - Sun Mar 19, 2006 11:58 am
Post subject: Re: Problem.
Code: Show/Hide
   sendPrivate(p,"Hi, " + (String) p->name + " with " + (String) p->score.killPoints + " kill points, how are you?");

Is this the only thing you changed from the plain plugin? Just post only this, next time, to make everyone's job a ton easier.
Martian Manhunter - Sun Mar 19, 2006 12:13 pm
Post subject:
lol yes thats the one I changed
Martian Manhunter - Sun Mar 19, 2006 12:18 pm
Post subject:
it says "Compile error: Expected:
If or ElseIf or End or EndIf or Const
Muskrat - Sun Mar 19, 2006 12:23 pm
Post subject:
sounds like a spawn.h problem, make sure you have a matching #endif at the end of the file for those at the top? just a guess.
Martian Manhunter - Sun Mar 19, 2006 12:25 pm
Post subject:
ok do the file have to be in a specific folder so Visual Studio could read it, I have all three files in a new folder on my desktop.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group