PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/ghost/gameslot.cpp

http://ghostcb.googlecode.com/
C++ | 88 lines | 56 code | 10 blank | 22 comment | 3 complexity | 4ee2cd172b39f8971521596ed5c564a8 MD5 | raw file
 1/*
 2
 3   Copyright [2008] [Trevor Hogan]
 4
 5   Licensed under the Apache License, Version 2.0 (the "License");
 6   you may not use this file except in compliance with the License.
 7   You may obtain a copy of the License at
 8
 9       http://www.apache.org/licenses/LICENSE-2.0
10
11   Unless required by applicable law or agreed to in writing, software
12   distributed under the License is distributed on an "AS IS" BASIS,
13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   See the License for the specific language governing permissions and
15   limitations under the License.
16
17   CODE PORTED FROM THE ORIGINAL GHOST PROJECT: http://ghost.pwner.org/
18
19*/
20
21#include "ghost.h"
22#include "gameslot.h"
23
24//
25// CGameSlot
26//
27
28CGameSlot :: CGameSlot( BYTEARRAY &n )
29{
30	if( n.size( ) >= 7 )
31	{
32		m_PID = n[0];
33		m_DownloadStatus = n[1];
34		m_SlotStatus = n[2];
35		m_Computer = n[3];
36		m_Team = n[4];
37		m_Colour = n[5];
38		m_Race = n[6];
39
40		if( n.size( ) >= 8 )
41			m_ComputerType = n[7];
42		else
43			m_ComputerType = SLOTCOMP_NORMAL;
44
45		if( n.size( ) >= 9 )
46			m_Handicap = n[8];
47		else
48			m_Handicap = 100;
49	}
50	else
51	{
52		m_PID = 0;
53		m_DownloadStatus = 255;
54		m_SlotStatus = SLOTSTATUS_OPEN;
55		m_Computer = 0;
56		m_Team = 0;
57		m_Colour = 1;
58		m_Race = SLOTRACE_RANDOM;
59		m_ComputerType = SLOTCOMP_NORMAL;
60		m_Handicap = 100;
61	}
62}
63
64CGameSlot :: CGameSlot( unsigned char nPID, unsigned char nDownloadStatus, unsigned char nSlotStatus, unsigned char nComputer, unsigned char nTeam, unsigned char nColour, unsigned char nRace, unsigned char nComputerType, unsigned char nHandicap )
65    : m_PID( nPID ), m_DownloadStatus( nDownloadStatus ), m_SlotStatus( nSlotStatus ), m_Computer( nComputer ), m_Team( nTeam ), m_Colour( nColour ), m_Race( nRace ), m_ComputerType( nComputerType ), m_Handicap( nHandicap )
66{
67
68}
69
70CGameSlot :: ~CGameSlot( )
71{
72
73}
74
75BYTEARRAY CGameSlot :: GetByteArray( ) const
76{
77	BYTEARRAY b;
78	b.push_back( m_PID );
79	b.push_back( m_DownloadStatus );
80	b.push_back( m_SlotStatus );
81	b.push_back( m_Computer );
82	b.push_back( m_Team );
83	b.push_back( m_Colour );
84	b.push_back( m_Race );
85	b.push_back( m_ComputerType );
86	b.push_back( m_Handicap );
87	return b;
88}