Вы находитесь на странице: 1из 6

Defines:

Lower_Nybble
Get_Hi_Nybble (amount to shift by)
Omni range
Direct range
Detonate range
Omni range distance
Direct range distance
LED Display time

Module functions:
ParseData
checkRange

Module variables:
Address
Source sub
Source station
Act_head
Data
Num teams
Our team num
Strike location
Bool no echo sent
Bool heard sync
GameStatus struct
LEDS message
WE_DEAD message
SENT_ECHO message

struct GameStatus{ //defined in .h file

bool ConnActive; //Things we set


bool SonarActive;
bool TorpedoActive;

uint8_t OurTeamNum;
uint8_t NumSlots; //Derived from NumTeams
uint8_t NumTeams;

bool WeOmniPinged;
bool WeDirectPinged;
bool WeLaunched;
uint8_t DistanceToDetonate;
MovePossibilities_t NextConnMove;

uint8_t OurPositionX; //Everything from here down is derived


uint8_t OurPositionY;
uint8_t OurHeading;

uint8_t ExpectedNextSlotNumber;
uint8_t Turn;
bool WeAreAlive;

uint8_t OtherTeamPositionX[MAX_TEAMS];
uint8_t OtherTeamPositionY[MAX_TEAMS];
uint8_t TeamPosUpdate;
uint32_t OtherStationOnlineStatus;
uint8_t TheyAreAlive;
uint8_t Launched;
//uint8_t NumNextTurnsInARow;
//uint8_t NumNoActionsInARow;
//uint8_t NumSyncsInARow;
uint8_t NumMoveOnsInARow;
bool JustMoveOnAlready;
bool onlyHeardNextTurns;
};

Function: setNumTeams
Params: uint8_t numteams
Returns: none
Set module variable NUM_TEAMS to value in parameter
End setNumTeams

Function: setTeamNum
Params: uint8_t teamnum
Returns: none
Set module variable Our_team_num to value in parameter
End setTeamNum

Function: InitializeGameStatus
Params: none
Returns: none
Set all values in struct at the beginning of the game
End InitializeGameStatus

Function: resetGameStatus
Params: none
Returns: none
reset all values in struct at the end of every turn
End resetGameStatus

Function: getPointerToGameStatus
Params: none
Returns: pointer to game status
Return pointer to gamestatus; allows other functions to edit GameStatus
End getPointerToGameStatus

Function: SetStrikeLocation
Params: uint8_t StrikeLoc
Returns: none
Set module variable StrikeLocation to value in parameter
End SetStrikeLocation

Function: ConvertToPacket
Params: uint8_t address, uint8_t source, uint8_t act_head
Returns: uint32_t packet
Create packet based on input parameters
Start with MSB and shift left as information is added
If event is echo or hit, set LEDs
End ConvertToPacket

Function: ConvertFromPacket
Params: uint32_t packet
Returns: none
Parses packet based on input data received
Start with LSB and shift right as information is stored in module variables
Parse received data
End ConvertToPacket

Function: ParseData
Params: none
Returns: none

Get slot number from data received


Set ExpectedNextSlotNumber to received value
If WeAreAlive
If our transmission
If addressed to enemy
If NEXT_TURN, RIP, or SYNC
Increment numMoveOnsInARow
Else if HIT
Turn on LEDs
Set WeAreAlive to false
Set NumMoveOnsInARow to 0
Set OnlyHeardNextTurns to false
Print Gamestatus
Endif
Else (addressed to OWN)
If NEXT_TURN or RIP
Increment numMoveOnsInARow
Else
If Pos update
Update our position and heading
Print game status
Else if HIT
Turn on LEDs
Set WeAreAlive to false
Set NumMoveOnsInARow to 0
Set OnlyHeardNextTurns to false
Print Gamestatus
Else if POS_REQUEST and Conn is active
Transmit POS_UPDATE
Endif
Set NumMoveOnsInARow to 0
Set OnlyHeardNextTurns to false
Endif
Endif
Else (not our teams transmission
If addressed to enemy
If NEXT_TURN, RIP, or SYNC
Increment numMoveOnsInARow
Else
If PING_OMNI and we are in range
If ConnActive and NoEchoSent
Transmit echo
Set noEchoSent to false
Else
Print “No echo”
Endif
Else if PING_DIRECTED and we are in range
If ConnActive and NoEchoSent
Transmit echo
Set no echo sent to false
Else
Print “No echo”
Endif
Else if ECHO
If we direct pinged and we are in range
Or if we omni pinged and we are in range
Update other teams position
Endif
Else if HIT
Set LEDs (other sub hit)
Clear appropriate bit in theyAreAlive
Else if DETONATE and we are in range
We died!
Set LEDS
Set WeAreAlive to false
If Conn active
Transmit HIT
Endif
Print game status
Else if LAUNCHED
Update enemy sub position and their launch status
Endif
Set numMoveOnsInARow to 0
Set onlyHeardNextTurns to false
Endif
Else (Addressed to OWN -- from enemy)
If NEXT_TURN or RIP
Increment NumMoveOnsInARow
Else
If HIT
Set LEDs
Clear appropriate bit in TheyAreAlive
Endif
Set numMoveOnsInARow to 0
Set onlyHeardNextTurns to false
Endif
Endif
Endif
Update otherstationonlinestatus
endif

End of ParseData

Function: printGameStatus
Params: bool Full
Returns: none
Print out the following after “GSC”, delimited by spaces:
WeAreAlive
Turn
TeamPosUpdate
OtherTeamPositionX,Y
TheyAreAlive
Launched
WeLaunched
OurHeading
OurPositionX,Y
End printGameStatus

Function: checkRange
Params: uint8_t rangeType
Returns: bool (true if in range, false otherwise)
Get enemy X,Y
Calculate our distance from enemy X,Y,Z
Calculate absolute distance from enemy
If rangeType is Omni range
If we are in range
If sonar is active
Update other team’s position
PrintGameStatus
Endif
Return true
endif
Else if rangeType is detonate
If distX and distY are 0 return true
Else return false
Else if rangeType is DirectRange
Get enemy heading
If we are not in range along heading, return false
If sonar is active
update other team’s position
Print GameStatus
Endif
Return true
Endif
Return false (default)
End checkRange

Вам также может понравиться