Read and Write for "bool"s
by Joseph Jonathan · in Torque Game Engine Advanced · 02/24/2010 (9:15 pm) · 3 replies
Hey guys another question about coding. (still learning but getting much better)
I am implementing the stealth function into my game atm. The basic idea is that when the stealth mode is activated the ship will not appear on other teams radar or their Reticule HUD.
What I am doing first is testing to find how the code will work.
I am using my weapon bay code and my damage meter code in place of the stealth code (which needs to still be added but is almost identical) and radar/hud (which is a more complicated process but the same basic idea)
Here is what I have. (I have included the code around it so you get a better idea of what is there)
In wheeledFlyingVehicle.h
in class WheeledFlyingVehicle: public Vehicle
in wheeledFlyingVehicle.cc
in WheeledFlyingVehicle::WheeledFlyingVehicle()
Then in my guiDamageHud.cc
I added:
I can get the console to print one or the other depending on what I spawn the ship as but it will not change when I change the mBayDoors with setBayDoors.
I know I am on the right track because I was able to get it to work using the S32 mThrottleLevel but I am not sure why this is not working.
Is anyone able to help me out?
I am implementing the stealth function into my game atm. The basic idea is that when the stealth mode is activated the ship will not appear on other teams radar or their Reticule HUD.
What I am doing first is testing to find how the code will work.
I am using my weapon bay code and my damage meter code in place of the stealth code (which needs to still be added but is almost identical) and radar/hud (which is a more complicated process but the same basic idea)
Here is what I have. (I have included the code around it so you get a better idea of what is there)
In wheeledFlyingVehicle.h
in class WheeledFlyingVehicle: public Vehicle
typedef Vehicle Parent;
enum MaskBits {
WheelMask = Parent::NextFreeMask << 0,
HoverHeight = Parent::NextFreeMask << 1,
BayMask = Parent::NextFreeMask << 2,
NextFreeMask = Parent::NextFreeMask << 3
};and later:}; S32 mThrottleLevel; bool mBayDoors; bool mWeaponsReady; U32 getCollisionMask(); public:and even later:
const char* getMode(); void setThrottleLevel(S32 level); S32 getThrottleLevel(); void setBayDoors(bool baydoors, WheeledFlyingVehicle* ship); bool getBayDoors(); void setWeaponsReady(bool ready, WheeledFlyingVehicle* ship); bool getWeaponsReady(); void openBayDoors(); void closeBayDoors(); void checkWeaponStatus(); void useCreateHeight(bool val); bool canChangeMode();
in wheeledFlyingVehicle.cc
in WheeledFlyingVehicle::WheeledFlyingVehicle()
mJetting = false; mDiving = false; mThrottleLevel = 0; mBayDoors = false; mWeaponsReady = false;Then in U32 WheeledFlyingVehicle::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
if (stream->writeFlag(mask & BayMask)) {
stream->writeFlag(mBayDoors);
}And then in void WheeledFlyingVehicle::unpackUpdate(NetConnection *con, BitStream *stream)if(stream->readFlag()) {
mBayDoors = stream->readFlag();
}then at the end my custom codes. (BTW these are still a work in progress)ConsoleMethod(WheeledFlyingVehicle, setBayDoors, void, 3, 3, "obj.setBayDoors(baydoors)")
{
WheeledFlyingVehicle* wv = static_cast<WheeledFlyingVehicle*>(object);
if (!wv) return;
wv->setBayDoors(dAtoi(argv[2]), wv);
}
void WheeledFlyingVehicle::setBayDoors(bool baydoors, WheeledFlyingVehicle* ship)
{
ShapeBase* control = dynamic_cast<ShapeBase*>(ship->getControlObject());
mBayDoors = baydoors;
ship->checkWeaponStatus();
setMaskBits(BayMask);
if (mBayDoors == true)
{
ship->openBayDoors();
}
else if (mBayDoors == false)
{
ship->closeBayDoors();
}
}
void WheeledFlyingVehicle::openBayDoors()
{
//Con::errorf("Bay Doors Open");
mJetting = false;
Con::executef(this, "openBayDoors", Con::getIntArg(getId()));
}
void WheeledFlyingVehicle::closeBayDoors()
{
//Con::errorf("Bay Doors Close");
Con::executef(this, "closeBayDoors", Con::getIntArg(getId()));
}
ConsoleMethod( WheeledFlyingVehicle, getBayDoors, bool, 2, 2, "Returns if the bay door is open.")
{
return object->getBayDoors();
}
bool WheeledFlyingVehicle::getBayDoors()
{
return mBayDoors;
}Then in my guiDamageHud.cc
I added:
#include "T3D/vehicles/wheeledFlyingVehicle.h" #include "T3D/vehicles/vehicle.h"Then here is the onRender code.
void GuiDamageHud::onRender(Point2I offset, const RectI &updateRect)
{
// Must have a connection and player control object
GameConnection* conn = GameConnection::getConnectionToServer();
if (!conn)
return;
WheeledFlyingVehicle* control = dynamic_cast<WheeledFlyingVehicle*>(conn->getControlObject());
if (!control || !(control->getType() & VehicleObjectType))
return;
// We'll just grab the damage right off the control object.
// Damage value 0 = no damage.
mValue = 1 - control->getDamageValue();
//WheeledFlyingVehicle* ship = static_cast<WheeledFlyingVehicle*>(control);
bool test = control->getBayDoors();
if(test == true)
{
Con::errorf("WORKING");
}
else
{
Con::errorf("NOT WORKING");
}
// Background first
if (mShowFill)
GFX->getDrawUtil()->drawRectFill(updateRect, mFillColor);I can get the console to print one or the other depending on what I spawn the ship as but it will not change when I change the mBayDoors with setBayDoors.
I know I am on the right track because I was able to get it to work using the S32 mThrottleLevel but I am not sure why this is not working.
Is anyone able to help me out?
#2
Thanks for the tip, could you tell me the difference between the two? I didn't know what it meant so I just put it in because it was in the other console functions.
02/25/2010 (6:26 am)
yes. I am calling %client.player.setBayDoors(bool) or if it is in the ship's onAdd function, %obj.setBayDoors(bool).function serverCmdOpenBayDoors(%client)
{
%obj = %client.player;
if (isObject(%obj))
{
%obj.setBayDoors(1);
}
}
function serverCmdCloseBayDoors(%client)
{
%obj = %client.player;
if (isObject(%obj))
{
%obj.setBayDoors(0);
}
}Thanks for the tip, could you tell me the difference between the two? I didn't know what it meant so I just put it in because it was in the other console functions.
#3
03/01/2010 (3:07 pm)
Is till haven't been able to figure this out can anyone help? I copied everything that had to do with Jetting writes and reads and made it mJammerOn. I still don't know how to get the GUI to know when mJammerOn is true or not.
Associate Rene Damm
Are you sure you are calling setBayDoors on the server object and not on the client's ghost?
BTW, in the setBayDoors console function, you probably want to use dAtob instead of dAtoi.