Skip to content

Commit

Permalink
Bindings: Added "multiplayer" binding state condition
Browse files Browse the repository at this point in the history
The new "multiplayer" condition allows specifying bindings that only
apply during multiplayer (i.e., network) games.

Modified the default bindings and the controls menu so that the
chat start commands only apply to multiplayer games.
  • Loading branch information
skyjake committed Jan 27, 2012
1 parent 5751c79 commit 90b5975
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 22 deletions.
6 changes: 5 additions & 1 deletion doomsday/engine/portable/include/b_util.h
Expand Up @@ -45,6 +45,7 @@ typedef enum ebstate_e {
} ebstate_t;

typedef enum stateconditiontype_e {
SCT_STATE, ///< Related to the state of the engine.
SCT_TOGGLE_STATE, ///< Toggle is in a specific state.
SCT_MODIFIER_STATE, ///< Modifier is in a specific state.
SCT_AXIS_BEYOND, ///< Axis is past a specific position.
Expand All @@ -55,10 +56,13 @@ typedef enum stateconditiontype_e {
typedef struct statecondition_s {
uint device; // Which device?
stateconditiontype_t type;
boolean negate; // Test the inverse (e.g., not in a specific state).
int id; // Toggle/axis/angle identifier in the device.
ebstate_t state;
float pos; // Axis position/angle condition.
struct {
uint negate:1; // Test the inverse (e.g., not in a specific state).
uint multiplayer:1; // Only for multiplayer.
} flags;
} statecondition_t;

boolean B_ParseToggleState(const char* toggleName, ebstate_t* state);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/b_main.c
Expand Up @@ -186,7 +186,7 @@ void B_Init(void)
B_NewContext(DEFAULT_BINDING_CONTEXT_NAME);

// Game contexts.
// FIXME: Obviously belong to the game, so shouldn't be here.
/// @todo Game binding context setup obviously belong to the game plugin, so shouldn't be here.
B_NewContext("map");
B_NewContext("map-freepan");
B_AcquireAll(B_NewContext("menu"), true);
Expand Down
30 changes: 25 additions & 5 deletions doomsday/engine/portable/src/b_util.c
Expand Up @@ -38,6 +38,8 @@
#include "b_util.h"
#include "b_context.h"

#include "net_main.h" // netGame

// MACROS ------------------------------------------------------------------

// TYPES -------------------------------------------------------------------
Expand Down Expand Up @@ -269,7 +271,13 @@ boolean B_ParseStateCondition(statecondition_t* cond, const char* desc)
// First, we expect to encounter a device name.
desc = Str_CopyDelim(str, desc, '-');

if(!Str_CompareIgnoreCase(str, "modifier"))
if(!Str_CompareIgnoreCase(str, "multiplayer"))
{
// This is only intended for multiplayer games.
cond->type = SCT_STATE;
cond->flags.multiplayer = true;
}
else if(!Str_CompareIgnoreCase(str, "modifier"))
{
cond->device = 0; // not used
cond->type = SCT_MODIFIER_STATE;
Expand Down Expand Up @@ -392,7 +400,7 @@ boolean B_ParseStateCondition(statecondition_t* cond, const char* desc)
desc = Str_CopyDelim(str, desc, '-');
if(!Str_CompareIgnoreCase(str, "not"))
{
cond->negate = true;
cond->flags.negate = true;
}

// Anything left that wasn't used?
Expand Down Expand Up @@ -442,11 +450,16 @@ boolean B_CheckAxisPos(ebstate_t test, float testPos, float pos)

boolean B_CheckCondition(statecondition_t* cond, int localNum, bcontext_t* context)
{
boolean fulfilled = !cond->negate;
boolean fulfilled = !cond->flags.negate;
inputdev_t* dev = I_GetDevice(cond->device, false);

switch(cond->type)
{
case SCT_STATE:
if(cond->flags.multiplayer && netGame)
return fulfilled;
break;

case SCT_MODIFIER_STATE:
if(context)
{
Expand Down Expand Up @@ -571,7 +584,14 @@ void B_AppendAnglePositionToString(float pos, ddstring_t* str)
*/
void B_AppendConditionToString(const statecondition_t* cond, ddstring_t* str)
{
if(cond->type == SCT_MODIFIER_STATE)
if(cond->type == SCT_STATE)
{
if(cond->flags.multiplayer)
{
Str_Append(str, "multiplayer");
}
}
else if(cond->type == SCT_MODIFIER_STATE)
{
Str_Appendf(str, "modifier-%i", cond->id - CTL_MODIFIER_1 + 1);
}
Expand All @@ -597,7 +617,7 @@ void B_AppendConditionToString(const statecondition_t* cond, ddstring_t* str)
}

// Flags.
if(cond->negate)
if(cond->flags.negate)
{
Str_Append(str, "-not");
}
Expand Down
10 changes: 5 additions & 5 deletions doomsday/plugins/common/src/g_controls.c
Expand Up @@ -349,11 +349,11 @@ D_CMD(DefaultGameBinds)
"bindcontrol walk joy-y-inverse",

// Chat events:
"bindevent key-t beginchat",
"bindevent key-g {beginchat 0}",
"bindevent key-y {beginchat 1}",
"bindevent key-r {beginchat 2}",
"bindevent key-b {beginchat 3}",
"bindevent key-t+multiplayer beginchat",
"bindevent key-g+multiplayer {beginchat 0}",
"bindevent key-y+multiplayer {beginchat 1}",
"bindevent key-r+multiplayer {beginchat 2}",
"bindevent key-b+multiplayer {beginchat 3}",
"bindevent chat:key-return chatcomplete",
"bindevent chat:key-escape chatcancel",
"bindevent chat:key-f1 {chatsendmacro 0}",
Expand Down
22 changes: 12 additions & 10 deletions doomsday/plugins/common/src/m_ctrl.c
Expand Up @@ -46,6 +46,7 @@
#define CCF_STAGED 0x4
#define CCF_REPEAT 0x8
#define CCF_SIDESTEP_MODIFIER 0x10
#define CCF_MULTIPLAYER 0x20

#define SMALL_SCALE .75f

Expand Down Expand Up @@ -162,20 +163,20 @@ static mndata_bindings_t controlConfig[] =
#endif

{ "Chat" },
{ "Open Chat", 0, 0, "beginchat" },
{ "Open Chat", 0, 0, "beginchat", CCF_MULTIPLAYER },

#if __JDOOM__ || __JDOOM64__
{ "Green Chat", 0, 0, "beginchat 0" },
{ "Indigo Chat", 0, 0, "beginchat 1" },
{ "Brown Chat", 0, 0, "beginchat 2" },
{ "Red Chat", 0, 0, "beginchat 3" },
{ "Green Chat", 0, 0, "beginchat 0", CCF_MULTIPLAYER },
{ "Indigo Chat", 0, 0, "beginchat 1", CCF_MULTIPLAYER },
{ "Brown Chat", 0, 0, "beginchat 2", CCF_MULTIPLAYER },
{ "Red Chat", 0, 0, "beginchat 3", CCF_MULTIPLAYER },
#endif

#if __JHERETIC__
{ "Green Chat", 0, 0, "beginchat 0" },
{ "Yellow Chat", 0, 0, "beginchat 1" },
{ "Red Chat", 0, 0, "beginchat 2" },
{ "Blue Chat", 0, 0, "beginchat 3" },
{ "Green Chat", 0, 0, "beginchat 0", CCF_MULTIPLAYER },
{ "Yellow Chat", 0, 0, "beginchat 1", CCF_MULTIPLAYER },
{ "Red Chat", 0, 0, "beginchat 2", CCF_MULTIPLAYER },
{ "Blue Chat", 0, 0, "beginchat 3", CCF_MULTIPLAYER },
#endif

{ "Send Message", "chat", 0, "chatcomplete" },
Expand Down Expand Up @@ -709,7 +710,8 @@ int MNBindings_PrivilegedResponder(mn_object_t* obj, event_t* ev)

if(binds->command)
{
sprintf(cmd, "bindevent {%s:%s} {%s}", bindContext, &symbol[5], binds->command);
const char* extraCondition = (binds->flags & CCF_MULTIPLAYER? " + multiplayer" : "");
sprintf(cmd, "bindevent {%s:%s%s} {%s}", bindContext, &symbol[5], extraCondition, binds->command);

// Check for repeats.
if(binds->flags & CCF_REPEAT)
Expand Down

0 comments on commit 90b5975

Please sign in to comment.