File: transfer.c

package info (click to toggle)
acm 5.0-29.2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 8,596 kB
  • sloc: ansic: 42,445; makefile: 710; cpp: 293; perl: 280; sh: 198
file content (71 lines) | stat: -rw-r--r-- 2,060 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 *  acm : an aerial combat simulator for X
 *  Copyright (C) 1991-1998  Riley Rainey
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 dated June, 1991.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program;  if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave., Cambridge, MA 02139, USA.
 */

#include <pm.h>

#define RESULT_REQUEST_OK 0
#define RESULT_UNABLE     1

/*
 *
 *  t r a n s f e r C o n t r o l R e q u e s t H a n d l e r 
 *
 *  This routine is responsible for handling entity transfer control requests
 *  at the simulation level.  It determines if the control transfer is
 *  feasible, adjusts simulation level data structures as needed, and returns
 *  an indication to the caller (the DIS interface) whether the request
 *  should proceed, or not.
 */

int
transferControlRequestHandler (Entity_t *e, dis_transfer_control_pdu *pdu)
{
	int result = RESULT_UNABLE;
	craftType *cinfo;

	switch (pdu->transfer_type) {

	/*
	 *  Someone would like use to take control of an entity
     *
     *  If it is an aircraft we can model, then make it a drone.
     */

	case DISTransferTypeEntityControllerRequest:
		cinfo = lookupCraftByEntityType( &e->entityType );
		if ( cinfo != NULL ) {
			e->c->type = CT_DRONE;
			e->c->cinfo = cinfo;
			/* TODO: provision the aircraft; landing gear, etc */
			result = RESULT_REQUEST_OK;
		}
		break;

	/*
	 *  Control of this entity is requested by someone else.
     *
     *  Change type to DIS aircraft and we're done.
	 */

	case DISTransferTypeEntityRequest:
		result = RESULT_REQUEST_OK;
		e->c->type = CT_DIS_PLANE;
	}

	return result;
}