Server Help

Bot Questions - #include stuff for Merv

Samapico - Fri Sep 21, 2007 2:34 pm
Post subject: #include stuff for Merv
I have made some classes that I can use with many plugins... however, I'd like all my plugin projects to refer to the same file, instead of copying the file to 5 folders, and it's a pain when I need to update stuff, it gets all mixed up...

Here's the current situation:

lvzdisplay class needs a reference to botInfo to be able to use lvz toggling functions...

so in lvzdisplay.h i have:

Code: Show/Hide

class botInfo;
...

void setparent(botInfo * _parent) { parent = _parent; };


however, in lvzdisplay.cpp, I can't just #include lvzdisplay.h, because it needs the references to object_target(), queue_enable(...), queue_disable(...), and toggle_objects()
So I have to #include spawn.h in there...

Is there any way to just tell him that object_target() and the others are methods of botInfo?

If I could get rid of the whole #include spawn.h, I could really make this class independant of the plugin...

I was thinking something along the lines of
Code: Show/Hide
class botInfo;
void botInfo::clear_objects();
void botInfo::object_target(Player *p);
void botInfo::toggle_objects();
void botInfo::queue_enable(int id);
void botInfo::queue_disable(int id);
in my header, but that doesn't work...
Cyan~Fire - Sat Sep 22, 2007 1:30 am
Post subject:
Your only option would be to put your custom code in a subclass of botInfo so then your plugin-independent code could access it through polymorphism. I'm not sure how well that would work, though, it's been a while since I've used MERVBot.
k0zy - Sat Sep 22, 2007 12:48 pm
Post subject:
I don't get the problem...
You use Visual Studio, right?
Right-Click Project->Add...->Existing Item...

Doesn't copy the file just adds it to the project.
Make a folder "Common" put everything in there, add it to projects. Done.
Samapico - Sat Sep 22, 2007 1:06 pm
Post subject:
The thing is, because of the references to the botInfo class I need, my lvzdisplay.cpp (the code of the common class I want) needs #include spawn.h
... so for every plugin, the spawn.h path will be different
k0zy - Sat Sep 22, 2007 2:03 pm
Post subject:
Add spawn.h to the "Commons" dir and add it to Visual Studio's search path.
Bak - Sat Sep 22, 2007 2:46 pm
Post subject:
or use separate folders and "#include ../spawn.h"
Samapico - Sat Sep 22, 2007 2:56 pm
Post subject:
But won't it cry because of a 'class redefinition' ? It will have 2 botInfo classes to compile
k0zy - Sat Sep 22, 2007 3:24 pm
Post subject:
If, just remove the one not in the common folder.
It won't be needed anyways.

Now that I think about it.
You might not need to copy spawn.h at all as it's include in the project anyways.

Just try it out! tongue.gif
Cyan~Fire - Sun Sep 23, 2007 1:05 am
Post subject:
You guys don't really get it... the way MERVBot is setup you modify the actual botInfo class to make your bot do whatever it wants. Therefore you can't have one common class for all your plugins since it actually defines what your plugin does.

That's why I suggest reorganizing it a bit so that all the plugin-specific class inherit from botInfo.
Samapico - Sun Sep 23, 2007 3:54 am
Post subject:
yeah..but polymorphysm... inheritance... never done that before.. bleh
k0zy - Sun Sep 23, 2007 5:17 am
Post subject:
Cyan~Fire wrote:
You guys don't really get it... the way MERVBot is setup you modify the actual botInfo class to make your bot do whatever it wants. Therefore you can't have one common class for all your plugins since it actually defines what your plugin does.

That's why I suggest reorganizing it a bit so that all the plugin-specific class inherit from botInfo.


You didn't get the problem icon_smile.gif
You're right with what you said, but he didn't modify the botInfo class!
He made a class that has a pointer to a botInfo and therefore it will just work like I told him (if the methods are public).
All he needs to do is to tell the compiler what methods botInfo has.
Samapico - Sun Sep 23, 2007 1:17 pm
Post subject:
Quote:
You're right with what you said, but he didn't modify the botInfo class!
But I DO need to modify the botInfo class for each different plugins afterwards


Quote:
All he needs to do is to tell the compiler what methods botInfo has.
That's what I'd want to do...but how?
k0zy - Sun Sep 23, 2007 3:01 pm
Post subject:
Samapico wrote:
But I DO need to modify the botInfo class for each different plugins afterwards

But the code will be different for all plugins, if I got that correctly.
If not you can still put it into a function and put that function into commons.


Samapico wrote:
That's what I'd want to do...but how?

Take a look at what I wrote again. I already told you.

Anyways, I'm off to France for a week. Good Luck.
k0zy - Sun Sep 23, 2007 3:22 pm
Post subject:
Okay... one last post before I go to bed.

It might not compile, because I didn't try it out.
But it should work like that.

common.h
Code: Show/Hide
#pragma once
#include "spawn.h"

void doSomething(botInfo *bi, Player *p);


common.cpp
Code: Show/Hide
#include "common.h"

void doSomething(botInfo *bi, Player *p)
{
  bi->sendMessage(p, "It works");
  return;
}


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

void botInfo::EventTick() // I didn't code a plugin in a while
{
  doSomething(this, somePlayer);
}


Add common.h and common.cpp to project (not copying them).
If it's unable to find them, update the search path.

icon_smile.gif
Hope that helped.
Cyan~Fire - Mon Sep 24, 2007 9:11 pm
Post subject:
Oh, I see what you mean now Bob Dole. Yes, that would work, but that's very messy...
Solo Ace - Tue Sep 25, 2007 1:58 am
Post subject:
Who's Bob Dole?

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group