summaryrefslogtreecommitdiff
path: root/src/uqm/battlecontrols.c
blob: 0f241e6c9cb0f2d14147cea966e54b3130f52e13 (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 *  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; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "battlecontrols.h"

#include "intel.h"
		// For computer_intelligence()
#include "tactrans.h"
		// For battleEndReady*
#include "init.h"
		// For NUM_PLAYERS
#include "libs/memlib.h"
		// For HMalloc(), HFree()
#ifdef NETPLAY
#	include "supermelee/netplay/netmelee.h"
#endif  /* NETPLAY */

InputContext *PlayerInput[NUM_PLAYERS];

BattleInputHandlers ComputerInputHandlers = {
	/* .frameInput     = */ (BattleFrameInputFunction) computer_intelligence,
	/* .selectShip     = */ (SelectShipFunction) selectShipComputer,
	/* .battleEndReady = */ (BattleEndReadyFunction) battleEndReadyComputer,
	/* .deleteContext  = */ InputContext_delete,
};

BattleInputHandlers HumanInputHandlers = {
	/* .frameInput     = */ (BattleFrameInputFunction) frameInputHuman,
	/* .selectShip     = */ (SelectShipFunction) selectShipHuman,
	/* .battleEndReady = */ (BattleEndReadyFunction) battleEndReadyHuman,
	/* .deleteContext  = */ InputContext_delete,
};

#ifdef NETPLAY
BattleInputHandlers NetworkInputHandlers = {
	/* .frameInput     = */ (BattleFrameInputFunction) networkBattleInput,
	/* .selectShip     = */ (SelectShipFunction) selectShipNetwork,
	/* .battleEndReady = */ (BattleEndReadyFunction) battleEndReadyNetwork,
	/* .deleteContext  = */ InputContext_delete,
};
#endif


void
InputContext_init (InputContext *context, BattleInputHandlers *handlers,
		COUNT playerNr)
{
	context->handlers = handlers;
	context->playerNr = playerNr;
}

void
InputContext_delete (InputContext *context)
{
	HFree (context);
}

ComputerInputContext *
ComputerInputContext_new (COUNT playerNr)
{
	ComputerInputContext *result = HMalloc (sizeof (ComputerInputContext));
	InputContext_init ((InputContext *) result,
			&ComputerInputHandlers, playerNr);
	return result;
}

HumanInputContext *
HumanInputContext_new (COUNT playerNr)
{
	HumanInputContext *result = HMalloc (sizeof (HumanInputContext));
	InputContext_init ((InputContext *) result,
			&HumanInputHandlers, playerNr);
	return result;
}

#ifdef NETPLAY
NetworkInputContext *
NetworkInputContext_new (COUNT playerNr)
{
	NetworkInputContext *result = HMalloc (sizeof (NetworkInputContext));
	InputContext_init ((InputContext *) result,
			&NetworkInputHandlers, playerNr);
	return result;
}
#endif