Support for grouping check structures. E.g. it is now possible to
have more than one lap line, which will always be in synch (i.e. if one is triggered, all will be set to inactive). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6161 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
3d66c17292
commit
4b4bddf35e
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
CheckManager::CheckManager(const XMLNode &node, Track *track)
|
CheckManager::CheckManager(const XMLNode &node, Track *track)
|
||||||
{
|
{
|
||||||
|
bool lap_line_found = false;
|
||||||
for(unsigned int i=0; i<node.getNumNodes(); i++)
|
for(unsigned int i=0; i<node.getNumNodes(); i++)
|
||||||
{
|
{
|
||||||
const XMLNode *check_node = node.getNode(i);
|
const XMLNode *check_node = node.getNode(i);
|
||||||
@ -37,9 +38,13 @@ CheckManager::CheckManager(const XMLNode &node, Track *track)
|
|||||||
{
|
{
|
||||||
CheckLine *cl = new CheckLine(this, *check_node, i);
|
CheckLine *cl = new CheckLine(this, *check_node, i);
|
||||||
m_all_checks.push_back(cl);
|
m_all_checks.push_back(cl);
|
||||||
if(cl->getType()==CheckStructure::CT_NEW_LAP)
|
// Only record the first lap line to be used to compute
|
||||||
|
// start coordinates with. The track exporter always exports
|
||||||
|
// the one based on the quads first.
|
||||||
|
if(cl->getType()==CheckStructure::CT_NEW_LAP && !lap_line_found)
|
||||||
{
|
{
|
||||||
track->setStartCoordinates(cl->getLine2D());
|
track->setStartCoordinates(cl->getLine2D());
|
||||||
|
lap_line_found = true;
|
||||||
}
|
}
|
||||||
} // checkline
|
} // checkline
|
||||||
else if(type=="check-sphere")
|
else if(type=="check-sphere")
|
||||||
|
@ -42,13 +42,16 @@ CheckStructure::CheckStructure(CheckManager *check_manager,
|
|||||||
{
|
{
|
||||||
printf("Unknown check structure '%s' - ignored.\n", kind.c_str());
|
printf("Unknown check structure '%s' - ignored.\n", kind.c_str());
|
||||||
}
|
}
|
||||||
m_activate_check_index = -1;
|
m_check_structures_to_change_state.clear();
|
||||||
node.get("other-id", &m_activate_check_index);
|
node.get("other-ids", &m_check_structures_to_change_state);
|
||||||
if( (m_check_type==CT_TOGGLE || m_check_type==CT_ACTIVATE) &&
|
// Backwards compatibility to tracks exported with older versions of
|
||||||
m_activate_check_index==-1)
|
// the track exporter
|
||||||
{
|
if(m_check_structures_to_change_state.size()==0)
|
||||||
printf("Unknown other-id in checkline.\n");
|
node.get("other-id", &m_check_structures_to_change_state);
|
||||||
}
|
|
||||||
|
m_same_group.clear();
|
||||||
|
node.get("same-group", &m_same_group);
|
||||||
|
|
||||||
m_active_at_reset=true;
|
m_active_at_reset=true;
|
||||||
node.get("active", &m_active_at_reset);
|
node.get("active", &m_active_at_reset);
|
||||||
} // CheckStructure
|
} // CheckStructure
|
||||||
@ -103,45 +106,76 @@ void CheckStructure::trigger(unsigned int kart_index)
|
|||||||
{
|
{
|
||||||
switch(m_check_type)
|
switch(m_check_type)
|
||||||
{
|
{
|
||||||
case CT_NEW_LAP : World::getWorld()->newLap(kart_index);
|
case CT_NEW_LAP :
|
||||||
m_is_active[kart_index] = false;
|
World::getWorld()->newLap(kart_index);
|
||||||
if(UserConfigParams::m_check_debug)
|
m_is_active[kart_index] = false;
|
||||||
{
|
if(UserConfigParams::m_check_debug)
|
||||||
printf("CHECK: %s new lap %d triggered, now deactivated.\n",
|
{
|
||||||
World::getWorld()->getKart(kart_index)->getIdent().c_str(),
|
printf("CHECK: %s new lap %d triggered, now deactivated.\n",
|
||||||
m_index);
|
World::getWorld()->getKart(kart_index)->getIdent().c_str(),
|
||||||
}
|
m_index);
|
||||||
break;
|
}
|
||||||
case CT_ACTIVATE: {
|
// Set all checkstructures of the same group to the same state.
|
||||||
CheckStructure *cs=
|
// This is to avoid e.g. only deactivating one of many new lap
|
||||||
m_check_manager->getCheckStructure(m_activate_check_index);
|
// counters, which could enable the user to cheat by crossing
|
||||||
cs->m_is_active[kart_index] = true;
|
// all different lap counting lines.
|
||||||
if(UserConfigParams::m_check_debug)
|
for(unsigned int i=0; i<m_same_group.size(); i++)
|
||||||
{
|
{
|
||||||
printf("CHECK: %s %d triggered, activating %d.\n",
|
CheckStructure *cs =
|
||||||
World::getWorld()->getKart(kart_index)->getIdent().c_str(),
|
m_check_manager->getCheckStructure(m_same_group[i]);
|
||||||
m_index, m_activate_check_index);
|
cs->m_is_active[kart_index] = false;
|
||||||
}
|
printf("CHECK: also deactivating index %d\n", m_same_group[i]);
|
||||||
break;
|
}
|
||||||
}
|
break;
|
||||||
case CT_TOGGLE: {
|
case CT_ACTIVATE:
|
||||||
CheckStructure *cs=
|
{
|
||||||
m_check_manager->getCheckStructure(m_activate_check_index);
|
for(unsigned int i=0; i<m_check_structures_to_change_state.size();
|
||||||
cs->m_is_active[kart_index] = !cs->m_is_active[kart_index];
|
i++)
|
||||||
if(UserConfigParams::m_check_debug)
|
{
|
||||||
{
|
int check_index = m_check_structures_to_change_state[i];
|
||||||
// At least on gcc 4.3.2 we can't simply print
|
CheckStructure *cs=
|
||||||
// cs->m_is_active[kart_index] ("cannot pass objects of
|
m_check_manager->getCheckStructure(check_index);
|
||||||
// non-POD type ‘struct std::_Bit_reference’ through ‘...’;
|
// We don't have to activate all members of the group of
|
||||||
// call will abort at runtime"). So we use this somewhat
|
// cs, since this check line's m_check_structure_to_change
|
||||||
// unusual but portable construct.
|
// will include the full groups.
|
||||||
printf("CHECK: %s %d triggered, setting %d to %d.\n",
|
cs->m_is_active[kart_index] = true;
|
||||||
World::getWorld()->getKart(kart_index)->getIdent().c_str(),
|
if(UserConfigParams::m_check_debug)
|
||||||
m_index, m_activate_check_index,
|
{
|
||||||
cs->m_is_active[kart_index]==true);
|
printf("CHECK: %s %d triggered, activating %d.\n",
|
||||||
}
|
World::getWorld()->getKart(kart_index)->getIdent().c_str(),
|
||||||
break;
|
m_index, check_index);
|
||||||
}
|
}
|
||||||
|
} // for i<m_check_structures_to_change_state.size()
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CT_TOGGLE:
|
||||||
|
{
|
||||||
|
for(unsigned int i=0; i<m_check_structures_to_change_state.size();
|
||||||
|
i++)
|
||||||
|
{
|
||||||
|
int check_index = m_check_structures_to_change_state[i];
|
||||||
|
CheckStructure *cs=
|
||||||
|
m_check_manager->getCheckStructure(check_index);
|
||||||
|
// We don't have to toggle all members of the group of
|
||||||
|
// cs, since this check line's m_check_structure_to_change
|
||||||
|
// will include the full groups. This esp. avoids toggling
|
||||||
|
// cs more than once!
|
||||||
|
cs->m_is_active[kart_index] = !cs->m_is_active[kart_index];
|
||||||
|
if(UserConfigParams::m_check_debug)
|
||||||
|
{
|
||||||
|
// At least on gcc 4.3.2 we can't simply print
|
||||||
|
// cs->m_is_active[kart_index] ("cannot pass objects of
|
||||||
|
// non-POD type ‘struct std::_Bit_reference’ through ‘...’;
|
||||||
|
// call will abort at runtime"). So we use this somewhat
|
||||||
|
// unusual but portable construct.
|
||||||
|
printf("CHECK: %s %d triggered, setting %d to %d.\n",
|
||||||
|
World::getWorld()->getKart(kart_index)->getIdent().c_str(),
|
||||||
|
m_index, check_index,
|
||||||
|
cs->m_is_active[kart_index]==true);
|
||||||
|
}
|
||||||
|
} // for i < m_check_structures_to_change_state
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: break;
|
default: break;
|
||||||
} // switch m_check_type
|
} // switch m_check_type
|
||||||
} // trigger
|
} // trigger
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// $Id: check_structure.hpp 1681 2008-04-09 13:52:48Z hikerstk $
|
// $Id: check_structure.hpp 1681 2008-04-09 13:52:48Z hikerstk $
|
||||||
//
|
//
|
||||||
// SuperTuxKart - a fun racing game with go-kart
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
// Copyright (C) 2009 Joerg Henrichs
|
// Copyright (C) 2009-2010 Joerg Henrichs
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or
|
// This program is free software; you can redistribute it and/or
|
||||||
// modify it under the terms of the GNU General Public License
|
// modify it under the terms of the GNU General Public License
|
||||||
@ -53,7 +53,7 @@ public:
|
|||||||
/** Different types of check structures:
|
/** Different types of check structures:
|
||||||
* ACTIVATE: Activates another check structure (independent of
|
* ACTIVATE: Activates another check structure (independent of
|
||||||
* the state that check structure is in)
|
* the state that check structure is in)
|
||||||
* TOGGLE: Switches (or inverts) the state of another check structure.
|
* TOGGLE: Switches (inverts) the state of another check structure.
|
||||||
* NEW_LAP: On crossing a new lap is counted.
|
* NEW_LAP: On crossing a new lap is counted.
|
||||||
* AMBIENT_SPHERE: Modifies the ambient color.
|
* AMBIENT_SPHERE: Modifies the ambient color.
|
||||||
* A combination of an activate and new_lap line are used to
|
* A combination of an activate and new_lap line are used to
|
||||||
@ -86,8 +86,17 @@ private:
|
|||||||
bool m_active_at_reset;
|
bool m_active_at_reset;
|
||||||
|
|
||||||
/** If this is a CT_ACTIVATE or CT_SWITCH type, this will contain
|
/** If this is a CT_ACTIVATE or CT_SWITCH type, this will contain
|
||||||
* the index of the corresponding check structure that is triggered. */
|
* the indices of the corresponding check structures that get their
|
||||||
int m_activate_check_index;
|
* state changed (activated or switched). */
|
||||||
|
std::vector<int> m_check_structures_to_change_state;
|
||||||
|
|
||||||
|
/** A list of check lines that should be activated/switched when this
|
||||||
|
* lines is activated/switched. I.e. can be used if more than one lap
|
||||||
|
* counting line is used to make sure they are all in synch, otherwise
|
||||||
|
* players could cross first one then the other lap counting line
|
||||||
|
* as huge shortcuts. */
|
||||||
|
std::vector<int> m_same_group;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CheckStructure(CheckManager *check_manager, const XMLNode &node,
|
CheckStructure(CheckManager *check_manager, const XMLNode &node,
|
||||||
unsigned int index);
|
unsigned int index);
|
||||||
|
Loading…
Reference in New Issue
Block a user