|
SPYSpheres
|
The class of the game object that you will use. More...
#include <ZRGame.h>
Public Member Functions | |
| float | getFuelRemaining () |
| void | sendMessage (unsigned char inputMsg) |
| unsigned char | receiveMessage () |
| bool | isFacingOther () |
| Check if the camera is pointed towards the other satellite. | |
| float | takePic () |
| Attempts to take a picture in the current position. | |
| float | getPicPoints () |
| Determines how many points a picture would give if taken immediately. | |
| int | getMemoryFilled () const |
| Returns how many memory slots are currently in use. | |
| int | getMemorySize () |
| Returns the total number of memory slots available to the satellite. | |
| float | uploadPics (void) |
| Attempts to upload pictures taken to Earth. | |
| bool | isCameraOn () |
| Makes sure the camera is on. | |
| float | getEnergy () |
| Tells how much energy the player has. | |
| float | getOtherEnergy () |
| Tells how much energy the opponent has, at a cost of 0 energy. | |
| bool | posInLight (float pos[]) |
| Returns true if the given coordinate is in the light zone. | |
| bool | posInDark (float pos[]) |
| Returns true if the given coordinate is in the dark zone. | |
| bool | posInGrey (float pos[]) |
| Returns true if the given coordinate is in a grey zone. | |
| int | posInArea (float pos[]) |
| Returns 1 if the given coordinate is in the light, -1 if in the dark, and 0 otherwise. | |
| float | getLightInterfacePosition () |
| Determines where the center of the grey zone at the tail end of the light zone is. | |
| float | getDarkGreyBoundary () |
| Determines where the boundary between the dark zone and the grey zone is. | |
| float | getLightGreyBoundary () |
| Determines where the boundary between the light zone and the grey zone is. | |
| float | getLightSwitchTime () |
| Determines how long until the light and dark zones next switch (2D/3D). | |
| int | getNumItem () |
| Returns the number of total items in play, whether they have been picked up yet or not. | |
| bool | useMirror () |
| Uses a held mirror item. | |
| int | getMirrorTimeRemaining () |
| Returns the amount of time left on your current mirror. | |
| int | getNumMirrorsHeld () |
| Returns the number of mirrors currently held and available for use. | |
| void | getItemLoc (float pos[], int itemID) |
| Copies the location of a given item into the given array. | |
| int | hasItem (int itemID) |
| Tells who has a given item. | |
| int | getItemType (int itemID) |
| Returns what the item does. | |
| float | getScore () |
| Returns the player's current score. | |
| float | getOtherScore () |
| Returns the opponent's current score. | |
| int | getCurrentTime () |
| Returns the time. | |
| ZeroRoboticsGame (ZeroRoboticsGameImpl &impl, ZeroRoboticsAPIImpl &apiImpl) | |
| Constructor for the game. The provided references should be singleton instances. | |
Static Public Member Functions | |
| static ZeroRoboticsGame & | instance () |
Private Attributes | |
| ZeroRoboticsGameImpl & | pimpl |
| REQUIRED: reference to the game implementation, do not delete! | |
| ZeroRoboticsAPIImpl & | apiImpl |
The class of the game object that you will use.
Contains publicly available member functions.
| ZeroRoboticsGame::ZeroRoboticsGame | ( | ZeroRoboticsGameImpl & | impl, |
| ZeroRoboticsAPIImpl & | apiImpl | ||
| ) |
| int ZeroRoboticsGame::getCurrentTime | ( | ) |
Returns the time.
Definition at line 460 of file ZRGameInternal.cpp.
{
return pimpl.challInfo.currentTime;
}
| float ZeroRoboticsGame::getDarkGreyBoundary | ( | ) |
| float ZeroRoboticsGame::getEnergy | ( | ) |
| float ZeroRoboticsGame::getFuelRemaining | ( | ) |
Tells the player how much fuel remains.
Definition at line 451 of file ZRGameInternal.cpp.
{
ZeroRoboticsGameImpl::ChallengeInfo& challInfo = pimpl.challInfo;
float total = PROP_ALLOWED_SECONDS-challInfo.me.fuelUsed;
total = MIN_FUEL(total, 0.0f); //~Prevents fuel from being less than 0.0f
total = MAX_FUEL(total, PROP_ALLOWED_SECONDS); //~Prevents fuel from being greater than MAX fuel in tank
return total;
}
| void ZeroRoboticsGame::getItemLoc | ( | float | pos[], |
| int | itemID | ||
| ) |
Copies the location of a given item into the given array.
| pos | A pointer to an array of size 3 which will be overwritten by the item location. |
| itemID | The integer identifier of a given item. |
Definition at line 101 of file ZRItems.cpp.
| int ZeroRoboticsGame::getItemType | ( | int | itemID | ) |
Returns what the item does.
Possible Item Types:
| itemID | The integer identifier of a given item. |
Definition at line 105 of file ZRItems.cpp.
{
if (itemID < NUM_ITEMS) return ITEM_TYPES[itemID];
return -1; // Error
}
| float ZeroRoboticsGame::getLightGreyBoundary | ( | ) |
Determines where the center of the grey zone at the tail end of the light zone is.
The tail end is at the lower Y-coordinate of the light zone, disregarding any portion that has wrapped around.
Definition at line 114 of file ZRLight.cpp.
| float ZeroRoboticsGame::getLightSwitchTime | ( | ) |
Determines how long until the light and dark zones next switch (2D/3D).
Definition at line 111 of file ZRLight.cpp.
{
return pimpl.challInfo.light.nextSwitchTime - pimpl.challInfo.currentTime;
}
| int ZeroRoboticsGame::getMemoryFilled | ( | ) | const |
Returns how many memory slots are currently in use.
Definition at line 43 of file ZRCamera.cpp.
{
return pimpl.challInfo.camera.memoryFilled;
}
| int ZeroRoboticsGame::getMemorySize | ( | ) |
Returns the total number of memory slots available to the satellite.
This includes both used and unused slots.
Definition at line 48 of file ZRCamera.cpp.
{
return pimpl.challInfo.camera.memorySize;
}
Returns the amount of time left on your current mirror.
Definition at line 120 of file ZRItems.cpp.
{
int mirrorEnd = pimpl.challInfo.me.mirrorTime + ITEM_MIRROR_DURATION;
int timeLeft = mirrorEnd - pimpl.challInfo.currentTime;
if(timeLeft > 0 && pimpl.challInfo.me.mirrorTime != 0)
return timeLeft;
return 0;
}
| int ZeroRoboticsGame::getNumItem | ( | ) |
Returns the number of total items in play, whether they have been picked up yet or not.
Definition at line 97 of file ZRItems.cpp.
{
return NUM_ITEMS;
}
| float ZeroRoboticsGame::getOtherEnergy | ( | ) |
Tells how much energy the opponent has, at a cost of 0 energy.
Definition at line 49 of file ZREnergy.cpp.
{
bool energyUsed = pimpl.tryToUseEnergy(ENERGY_COST_GET_OTHER_ENERGY);
if(energyUsed)
return pimpl.challInfo.other.energy;
return 0;
}
| float ZeroRoboticsGame::getOtherScore | ( | ) |
| float ZeroRoboticsGame::getPicPoints | ( | ) |
Determines how many points a picture would give if taken immediately.
Does not actually take a picture. Costs 0.1 energy.
Definition at line 61 of file ZRCamera.cpp.
{
if(!pimpl.challInfo.camera.cameraOn) {
return 0;
}
if (!pimpl.tryToUseEnergy(ENERGY_COST_GET_PIC_POINTS)) {
return 0;
}
return pimpl.picPointsImpl();
}
| float ZeroRoboticsGame::getScore | ( | ) |
| int ZeroRoboticsGame::hasItem | ( | int | itemID | ) |
Tells who has a given item.
| itemID | The integer identifier of a given item. |
Definition at line 88 of file ZRItems.cpp.
| ZeroRoboticsGame & ZeroRoboticsGame::instance | ( | ) | [static] |
Retrieves the singleton instance of the game API. Users are not allowed to construct a game instance, so the API must be retrieved through this interface.
Definition at line 43 of file ZRGameInternal.cpp.
{
static ZeroRoboticsGame gameInstance(ZeroRoboticsGameImpl::instance(), ZeroRoboticsAPIImpl::instance());
return gameInstance;
}
| bool ZeroRoboticsGame::isCameraOn | ( | ) |
| bool ZeroRoboticsGame::isFacingOther | ( | ) |
Check if the camera is pointed towards the other satellite.
Definition at line 192 of file ZRCamera.cpp.
{
return pimpl.isFacingOther();
}
| int ZeroRoboticsGame::posInArea | ( | float | pos[] | ) |
Returns 1 if the given coordinate is in the light, -1 if in the dark, and 0 otherwise.
| pos | An array of three floats in (x, y, z) order. |
Definition at line 127 of file ZRLight.cpp.
{
#ifdef ALLIANCE
return pimpl.sphereInMovingArea(position);
#else
return pimpl.sphereInSwitchingArea(position);
#endif
}
| bool ZeroRoboticsGame::posInDark | ( | float | pos[] | ) |
Returns true if the given coordinate is in the dark zone.
| pos | An array of three floats in (x, y, z) order. |
Definition at line 139 of file ZRLight.cpp.
{
return pimpl.sphereInDark(position);
}
| bool ZeroRoboticsGame::posInGrey | ( | float | pos[] | ) |
Returns true if the given coordinate is in a grey zone.
| pos | An array of three floats in (x, y, z) order. |
Definition at line 143 of file ZRLight.cpp.
{
return !pimpl.sphereInDark(position) && !pimpl.sphereInLight(position);
}
| bool ZeroRoboticsGame::posInLight | ( | float | pos[] | ) |
Returns true if the given coordinate is in the light zone.
| pos | An array of three floats in (x, y, z) order. |
Definition at line 135 of file ZRLight.cpp.
{
return pimpl.sphereInLight(position);
}
| unsigned char ZeroRoboticsGame::receiveMessage | ( | ) |
| void ZeroRoboticsGame::sendMessage | ( | unsigned char | inputMsg | ) |
| float ZeroRoboticsGame::takePic | ( | ) |
Attempts to take a picture in the current position.
The camera will be disabled for 3 seconds after an attempt, whether successful or not. Costs 1.0 energy.
Definition at line 53 of file ZRCamera.cpp.
| float ZeroRoboticsGame::uploadPics | ( | void | ) |
Attempts to upload pictures taken to Earth.
Will fail if not facing Earth (3D/Alliance). Disables camera for three seconds upon sucessful upload. Costs 1.0 energy.
Definition at line 202 of file ZRCamera.cpp.
{
float totalScore = 0.0;
if(!pimpl.tryToUseEnergy(ENERGY_COST_UPLOAD_PICTURES)) return 0.0;
GAME_TRACE(("[%d] trying to upload... ", apiImpl.api->getTime()));
// Need to check that the SPHERE isn't going too fast to upload.
float speed = mathVecMagnitude(&pimpl.challInfo.me.zrState[9],3);
if (speed>UPLOAD_ANG_VEL)
{
GAME_TRACE(("Rotating too fast, Upload Failed. Speed=%2.4f",speed));
return 0.0;
}
// Need to check if the SPHERE is pointing towards earth before running the code to upload pictures.
#ifndef ZR2D
if (!pimpl.isFacingEarth())
{
return totalScore;
GAME_TRACE(("Not Facing Earth, Upload Failed. "));
}
#endif
pimpl.challInfo.camera.uploadedPictures = true;
pimpl.disableCamera(); // For only three seconds.
for (unsigned int i = 0; i < pimpl.challInfo.camera.memoryFilled; i++)
{
if (pimpl.challInfo.camera.memory[i].picStored == true)
{
pimpl.challInfo.camera.memory[i].picStored = false;
pimpl.challInfo.me.score += pimpl.challInfo.camera.memory[i].value;
totalScore += pimpl.challInfo.camera.memory[i].value;
GAME_TRACE(("uploaded picture for %4.2f points | ", pimpl.challInfo.camera.memory[i].value));
}
}
pimpl.challInfo.camera.memoryFilled = 0;
return totalScore;
}
| bool ZeroRoboticsGame::useMirror | ( | ) |
ZeroRoboticsAPIImpl& ZeroRoboticsGame::apiImpl [private] |
ZeroRoboticsGameImpl& ZeroRoboticsGame::pimpl [private] |