Esempio n. 1
0
// setup link acknowledgement on both sides
short int setupLink(short int side) {
	short int setupgood = 1, mycalc = CALCULATOR;

	if (side == LINKBLACK) {
		// black recives then sends
		
		if (!recvCalc(mycalc)) {
			setupgood = 0;
		}
		
		LIO_SendData(&mycalc,2);
	} else if (side == LINKRED) {
		// red sends then receives
		
		LIO_SendData(&mycalc,2);
		
		if (!recvCalc(mycalc)) {
			setupgood = 0;
		}
	}
	
	// if we have any problems, this will return 0 (FALSE)
	return setupgood;
}
Esempio n. 2
0
/* Communicates between the Host and the Joining Calc all of the necessary data 
   while a game is running */
void Transfer_Data(void) {
	char Control = FALSE, Other_Control;
	unsigned char a;
	
	// Must send three plrs separately
	for(a = 3; a--;) {
		if (g->Calc == Host) {
			if (LIO_SendData(&Team2->plrs[a]->Control, sizeof(char)))
				ERROR(LINK_ERROR);
			if (LIO_RecvData(&Other_Control, sizeof(char), 30))
				ERROR(LINK_ERROR);
			
			/* After a lot of trial and error, this is the only way I found that 
			will allow for one player to take the puck from another player */
			if (Other_Control < 0 && Team1->plrs[a]->Control >= 0)
				Team1->plrs[a]->Control = Other_Control;
			
			if (LIO_SendData((char*)Team1->plrs[a], sizeof(Plr)))  // Send Plr on Team1
				ERROR(LINK_ERROR);
			if (LIO_RecvData((char*)Team2->plrs[a], sizeof(Plr), 30))  // Receive Plr on Team2
				ERROR(LINK_ERROR);
		} else {
			if (LIO_RecvData(&Other_Control, sizeof(char), 30))
				ERROR(LINK_ERROR);
			if (LIO_SendData(&Team1->plrs[a]->Control, sizeof(char)))
				ERROR(LINK_ERROR);
			
			if (Other_Control < 0 && Team2->plrs[a]->Control >= 0)
				Team2->plrs[a]->Control = Other_Control;
			
			if (LIO_RecvData((char*)Team1->plrs[a], sizeof(Plr), 30))  // Receive Plr on Team1
				ERROR(LINK_ERROR);
			if (LIO_SendData((char*)Team2->plrs[a], sizeof(Plr)))  // Send Plr on Team2
				ERROR(LINK_ERROR);
		}
		
		// If the puck is controlled by the other calc, make sure g->Is_Controlled is set 
		// to the correct value and only one player has Control of the puck
		if (Control == FALSE) {
			if (Team1->plrs[a]->Control > 0) {  // Puck controlled by team 1
				g->Is_Controlled = 1;
				if (Team2->plrs[a]->Control > 0)
					Team2->plrs[a]->Control = -1;
				Control = 1;
			} else if (Team2->plrs[a]->Control > 0) {  // Puck controlled by team 2
				g->Is_Controlled = 2;
				Control = 2;
			} else g->Is_Controlled = FALSE;  // Puck is not being controlled by a player
		} else {  // Make sure two players cannot have the puck at the same time
			if (Team1->plrs[a]->Control > 0)
				Team1->plrs[a]->Control = -1;
			if (Team2->plrs[a]->Control > 0)
				Team2->plrs[a]->Control = -1;
		}
	}
	
	// Send or Receive Puck Data, depending on which team has Control of the puck
	if (g->Last_Controlled == 2 && g->Is_Controlled == 0) {
		if (g->Calc == Host && LIO_RecvData((char*)&g->Is_Controlled, 7*sizeof(short), 30))
			ERROR(LINK_ERROR);
		else if (g->Calc == Join && LIO_SendData((char*)&g->Is_Controlled, 7*sizeof(short)))
			ERROR(LINK_ERROR);
	} else if (g->Calc == Host) {
		if (g->Is_Controlled != 2) {
			if (LIO_SendData((char*)&g->Is_Controlled, 7*sizeof(short)))
				ERROR(LINK_ERROR);
		} else if (LIO_RecvData((char*)&g->Is_Controlled, 7*sizeof(short), 30))
			ERROR(LINK_ERROR);
	} else if (g->Calc == Join) {
		if (g->Is_Controlled == 2) {
			if (LIO_SendData((char*)&g->Is_Controlled, 7*sizeof(short)))
				ERROR(LINK_ERROR);
		} else if (LIO_RecvData((char*)&g->Is_Controlled, 7*sizeof(short), 30))
			ERROR(LINK_ERROR);
	}
	
	
	/*if (g->Last_Controlled == 2 && g->Is_Controlled == 0) {
		if (g->Calc == Host && LIO_RecvData((char*)&g->Is_Controlled, sizeof(short)*7, 30))
			ERROR(LINK_ERROR);
		else if (g->Calc == Join && LIO_SendData((char*)&g->Is_Controlled, sizeof(short)*7))
			ERROR(LINK_ERROR);
	} else if (g->Calc == g->Is_Controlled) {
		if (LIO_SendData((char*)&g->Is_Controlled, sizeof(short)*7))
			ERROR(LINK_ERROR);
	} else if (LIO_RecvData((char*)&g->Is_Controlled, sizeof(short)*7, 30))
		ERROR(LINK_ERROR);*/
	
	/*if (g->Calc == Host) {
		if (g->Is_Controlled != 2) {
			if ()
				ERROR(LINK_ERROR);
		} else if (LIO_RecvData((char*)&g->Is_Controlled, sizeof(short)*7, 30))
			ERROR(LINK_ERROR);
	} else if (g->Calc == Join) {
		if (g->Is_Controlled == 2) {
			if (LIO_SendData((char*)&g->Is_Controlled, sizeof(short)*7))
				ERROR(LINK_ERROR);
		} else if (LIO_RecvData((char*)&g->Is_Controlled, sizeof(short)*7, 30))
			ERROR(LINK_ERROR);
	}*/
	// Remember who had the puck last frame
	g->Last_Controlled = g->Is_Controlled;
}