Re #924: handle dashboard commands and pit request in human robots
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6251 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 0f04c7b527725de524e213c776b164ebec385fef Former-commit-id: 4f827ea329e05e9a939916331d903650cdf6e4c8
This commit is contained in:
parent
d3e788d1ca
commit
cae541787b
1 changed files with 102 additions and 9 deletions
|
@ -116,6 +116,7 @@ typedef struct HumanContext
|
||||||
tControlCmd *cmdControl;
|
tControlCmd *cmdControl;
|
||||||
bool mouseControlUsed;
|
bool mouseControlUsed;
|
||||||
int lightCmd;
|
int lightCmd;
|
||||||
|
int dashboardCounter;
|
||||||
|
|
||||||
// simuV4 ...
|
// simuV4 ...
|
||||||
bool useESP;
|
bool useESP;
|
||||||
|
@ -222,7 +223,11 @@ static const tControlCmd CmdControlRef[] = {
|
||||||
{HM_ATT_HBOX_X, GFCTRL_TYPE_NOT_AFFECTED, -1, NULL, 0.0, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0},
|
{HM_ATT_HBOX_X, GFCTRL_TYPE_NOT_AFFECTED, -1, NULL, 0.0, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0},
|
||||||
{HM_ATT_HBOX_Y, GFCTRL_TYPE_NOT_AFFECTED, -1, NULL, 0.0, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0},
|
{HM_ATT_HBOX_Y, GFCTRL_TYPE_NOT_AFFECTED, -1, NULL, 0.0, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0},
|
||||||
{HM_ATT_LEFTGLANCE, GFCTRL_TYPE_NOT_AFFECTED, -1, HM_ATT_L_GLANCE_MIN, 0.0, 0.0, HM_ATT_L_GLANCE_MAX, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0},
|
{HM_ATT_LEFTGLANCE, GFCTRL_TYPE_NOT_AFFECTED, -1, HM_ATT_L_GLANCE_MIN, 0.0, 0.0, HM_ATT_L_GLANCE_MAX, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0},
|
||||||
{HM_ATT_RIGHTGLANCE,GFCTRL_TYPE_NOT_AFFECTED, -1, HM_ATT_R_GLANCE_MIN, 0.0, 0.0, HM_ATT_R_GLANCE_MAX, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0}
|
{HM_ATT_RIGHTGLANCE,GFCTRL_TYPE_NOT_AFFECTED, -1, HM_ATT_R_GLANCE_MIN, 0.0, 0.0, HM_ATT_R_GLANCE_MAX, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0},
|
||||||
|
{HM_ATT_DASHB_NEXT ,GFCTRL_TYPE_NOT_AFFECTED, -1, HM_ATT_DASHB_NEXT_MIN, 0.0, 0.0, HM_ATT_DASHB_NEXT_MAX, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0},
|
||||||
|
{HM_ATT_DASHB_PREV ,GFCTRL_TYPE_NOT_AFFECTED, -1, HM_ATT_DASHB_PREV_MIN, 0.0, 0.0, HM_ATT_DASHB_PREV_MAX, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0},
|
||||||
|
{HM_ATT_DASHB_INC ,GFCTRL_TYPE_NOT_AFFECTED, -1, HM_ATT_DASHB_INC_MIN, 0.0, 0.0, HM_ATT_DASHB_INC_MAX, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0},
|
||||||
|
{HM_ATT_DASHB_DEC ,GFCTRL_TYPE_NOT_AFFECTED, -1, HM_ATT_DASHB_DEC_MIN, 0.0, 0.0, HM_ATT_DASHB_DEC_MAX, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0, NULL, 0.0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int NbCmdControl = sizeof(CmdControlRef) / sizeof(CmdControlRef[0]);
|
static const int NbCmdControl = sizeof(CmdControlRef) / sizeof(CmdControlRef[0]);
|
||||||
|
@ -1208,6 +1213,86 @@ static void common_drive(const int index, tCarElt* car, tSituation *s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// dashboard handling
|
||||||
|
if ((cmd[CMD_DASHB_NEXT].type == GFCTRL_TYPE_JOY_BUT && joyInfo->edgeup[cmd[CMD_DASHB_NEXT].val])
|
||||||
|
|| (cmd[CMD_DASHB_NEXT].type == GFCTRL_TYPE_MOUSE_BUT && mouseInfo->edgedn[cmd[CMD_DASHB_NEXT].val])
|
||||||
|
|| (cmd[CMD_DASHB_NEXT].type == GFCTRL_TYPE_KEYBOARD && keyInfo[lookUpKeyMap(cmd[CMD_DASHB_NEXT].val)].edgeDn)
|
||||||
|
|| (cmd[CMD_DASHB_NEXT].type == GFCTRL_TYPE_JOY_ATOB && cmd[CMD_DASHB_NEXT].deadZone != 0))
|
||||||
|
{
|
||||||
|
car->_dashboardActiveItem++;
|
||||||
|
if (car->_dashboardActiveItem >= car->_dashboardInstantNb + car->_dashboardRequestNb)
|
||||||
|
{car->_dashboardActiveItem = 0;}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((cmd[CMD_DASHB_PREV].type == GFCTRL_TYPE_JOY_BUT && joyInfo->edgeup[cmd[CMD_DASHB_PREV].val])
|
||||||
|
|| (cmd[CMD_DASHB_PREV].type == GFCTRL_TYPE_MOUSE_BUT && mouseInfo->edgedn[cmd[CMD_DASHB_PREV].val])
|
||||||
|
|| (cmd[CMD_DASHB_PREV].type == GFCTRL_TYPE_KEYBOARD && keyInfo[lookUpKeyMap(cmd[CMD_DASHB_PREV].val)].edgeDn)
|
||||||
|
|| (cmd[CMD_DASHB_PREV].type == GFCTRL_TYPE_JOY_ATOB && cmd[CMD_DASHB_PREV].deadZone != 0))
|
||||||
|
{
|
||||||
|
car->_dashboardActiveItem--;
|
||||||
|
if (car->_dashboardActiveItem < 0)
|
||||||
|
{car->_dashboardActiveItem = car->_dashboardInstantNb + car->_dashboardRequestNb - 1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
tDashboardItem *item;
|
||||||
|
if (car->_dashboardActiveItem < car->_dashboardInstantNb) {
|
||||||
|
item = &(car->_dashboardInstant[car->_dashboardActiveItem]);
|
||||||
|
} else {
|
||||||
|
item = &(car->_dashboardRequest[car->_dashboardActiveItem - car->_dashboardInstantNb]);
|
||||||
|
}
|
||||||
|
if ((cmd[CMD_DASHB_INC].type == GFCTRL_TYPE_JOY_BUT && joyInfo->edgeup[cmd[CMD_DASHB_INC].val])
|
||||||
|
|| (cmd[CMD_DASHB_INC].type == GFCTRL_TYPE_MOUSE_BUT && mouseInfo->edgedn[cmd[CMD_DASHB_INC].val])
|
||||||
|
|| (cmd[CMD_DASHB_INC].type == GFCTRL_TYPE_KEYBOARD && keyInfo[lookUpKeyMap(cmd[CMD_DASHB_INC].val)].edgeDn)
|
||||||
|
|| (cmd[CMD_DASHB_INC].type == GFCTRL_TYPE_JOY_ATOB && cmd[CMD_DASHB_INC].deadZone != 0))
|
||||||
|
{
|
||||||
|
HCtx[idx]->dashboardCounter = (int)(1.0/RCM_MAX_DT_ROBOTS);
|
||||||
|
item->setup->desired_value += item->setup->stepsize;
|
||||||
|
if (item->setup->desired_value > item->setup->max) {item->setup->desired_value = item->setup->max;}
|
||||||
|
item->setup->changed = TRUE;
|
||||||
|
car->ctrl.setupChangeCmd = item;
|
||||||
|
}
|
||||||
|
if ((cmd[CMD_DASHB_INC].type == GFCTRL_TYPE_JOY_BUT && joyInfo->levelup[cmd[CMD_DASHB_INC].val])
|
||||||
|
|| (cmd[CMD_DASHB_INC].type == GFCTRL_TYPE_MOUSE_BUT && mouseInfo->button[cmd[CMD_DASHB_INC].val])
|
||||||
|
|| (cmd[CMD_DASHB_INC].type == GFCTRL_TYPE_KEYBOARD && keyInfo[lookUpKeyMap(cmd[CMD_DASHB_INC].val)].state)
|
||||||
|
|| (cmd[CMD_DASHB_INC].type == GFCTRL_TYPE_JOY_ATOB && cmd[CMD_DASHB_INC].deadZone != 0))
|
||||||
|
{
|
||||||
|
if (HCtx[idx]->dashboardCounter > 0) {
|
||||||
|
HCtx[idx]->dashboardCounter--;
|
||||||
|
} else {
|
||||||
|
item->setup->desired_value += item->setup->stepsize;
|
||||||
|
if (item->setup->desired_value > item->setup->max) {item->setup->desired_value = item->setup->max;}
|
||||||
|
item->setup->changed = TRUE;
|
||||||
|
car->ctrl.setupChangeCmd = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((cmd[CMD_DASHB_DEC].type == GFCTRL_TYPE_JOY_BUT && joyInfo->edgeup[cmd[CMD_DASHB_DEC].val])
|
||||||
|
|| (cmd[CMD_DASHB_DEC].type == GFCTRL_TYPE_MOUSE_BUT && mouseInfo->edgedn[cmd[CMD_DASHB_DEC].val])
|
||||||
|
|| (cmd[CMD_DASHB_DEC].type == GFCTRL_TYPE_KEYBOARD && keyInfo[lookUpKeyMap(cmd[CMD_DASHB_DEC].val)].edgeDn)
|
||||||
|
|| (cmd[CMD_DASHB_DEC].type == GFCTRL_TYPE_JOY_ATOB && cmd[CMD_DASHB_DEC].deadZone != 0))
|
||||||
|
{
|
||||||
|
HCtx[idx]->dashboardCounter = (int)(1.0/RCM_MAX_DT_ROBOTS);
|
||||||
|
item->setup->desired_value -= item->setup->stepsize;
|
||||||
|
if (item->setup->desired_value < item->setup->min) {item->setup->desired_value = item->setup->min;}
|
||||||
|
item->setup->changed = TRUE;
|
||||||
|
car->ctrl.setupChangeCmd = item;
|
||||||
|
}
|
||||||
|
if ((cmd[CMD_DASHB_DEC].type == GFCTRL_TYPE_JOY_BUT && joyInfo->levelup[cmd[CMD_DASHB_DEC].val])
|
||||||
|
|| (cmd[CMD_DASHB_DEC].type == GFCTRL_TYPE_MOUSE_BUT && mouseInfo->button[cmd[CMD_DASHB_DEC].val])
|
||||||
|
|| (cmd[CMD_DASHB_DEC].type == GFCTRL_TYPE_KEYBOARD && keyInfo[lookUpKeyMap(cmd[CMD_DASHB_DEC].val)].state)
|
||||||
|
|| (cmd[CMD_DASHB_DEC].type == GFCTRL_TYPE_JOY_ATOB && cmd[CMD_DASHB_DEC].deadZone != 0))
|
||||||
|
{
|
||||||
|
if (HCtx[idx]->dashboardCounter > 0) {
|
||||||
|
HCtx[idx]->dashboardCounter--;
|
||||||
|
} else {
|
||||||
|
item->setup->desired_value -= item->setup->stepsize;
|
||||||
|
if (item->setup->desired_value < item->setup->min) {item->setup->desired_value = item->setup->min;}
|
||||||
|
item->setup->changed = TRUE;
|
||||||
|
car->ctrl.setupChangeCmd = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (cmd[CMD_BRAKE].type) {
|
switch (cmd[CMD_BRAKE].type) {
|
||||||
case GFCTRL_TYPE_JOY_AXIS:
|
case GFCTRL_TYPE_JOY_AXIS:
|
||||||
brake = joyInfo->ax[cmd[CMD_BRAKE].val];
|
brake = joyInfo->ax[cmd[CMD_BRAKE].val];
|
||||||
|
@ -1924,26 +2009,34 @@ int HumanDriver::pit_cmd(int index, tCarElt* car, tSituation *s)
|
||||||
const int idx = index - 1;
|
const int idx = index - 1;
|
||||||
|
|
||||||
HCtx[idx]->nbPitStops++; //Yet another pitstop
|
HCtx[idx]->nbPitStops++; //Yet another pitstop
|
||||||
tdble curr_fuel = car->_tank - car->_fuel; //Can receive max. this fuel
|
//tdble curr_fuel = car->_tank - car->_fuel; //Can receive max. this fuel
|
||||||
|
|
||||||
tdble planned_stops = 1.0
|
/*tdble planned_stops = 1.0
|
||||||
+ MAX(HCtx[idx]->nbPitStopProg - HCtx[idx]->nbPitStops, 0); //Planned pitstops still ahead
|
+ MAX(HCtx[idx]->nbPitStopProg - HCtx[idx]->nbPitStops, 0);*/ //Planned pitstops still ahead
|
||||||
|
|
||||||
//Need this amount of extra fuel to finish the race
|
//Need this amount of extra fuel to finish the race
|
||||||
tdble fuel =
|
/*tdble fuel =
|
||||||
( MaxFuelPerMeter
|
( MaxFuelPerMeter
|
||||||
* (curTrack->length * car->_remainingLaps + car->_trkPos.seg->lgfromstart)
|
* (curTrack->length * car->_remainingLaps + car->_trkPos.seg->lgfromstart)
|
||||||
+ 2.7f / 60.0f * MAX(s->_totTime, 0) )
|
+ 2.7f / 60.0f * MAX(s->_totTime, 0) )
|
||||||
/ planned_stops
|
/ planned_stops
|
||||||
- car->_fuel;
|
- car->_fuel;*/
|
||||||
|
|
||||||
//No need to check for limits as curr_fuel cannot be bigger
|
//No need to check for limits as curr_fuel cannot be bigger
|
||||||
//than the tank capacity
|
//than the tank capacity
|
||||||
car->_pitFuel = MAX(MIN(curr_fuel, fuel), 0);
|
//car->_pitFuel = MAX(MIN(curr_fuel, fuel), 0);
|
||||||
|
car->_pitFuel = car->setup.fuel.desired_value - car->_fuel;
|
||||||
|
|
||||||
HCtx[idx]->lastPitStopLap = car->_laps;
|
HCtx[idx]->lastPitStopLap = car->_laps;
|
||||||
|
|
||||||
car->_pitRepair = (int)car->_dammage;
|
//car->_pitRepair = (int)car->_dammage;
|
||||||
|
car->_pitRepair = car->setup.reqRepair.desired_value;
|
||||||
|
|
||||||
|
if (car->setup.reqPenalty.desired_value > 0.9) {
|
||||||
|
car->_pitStopType = RM_PIT_STOPANDGO;
|
||||||
|
} else {
|
||||||
|
car->_pitStopType = RM_PIT_REPAIR;
|
||||||
|
}
|
||||||
|
|
||||||
if (HCtx[idx]) {
|
if (HCtx[idx]) {
|
||||||
const tControlCmd *cmd = HCtx[idx]->cmdControl;
|
const tControlCmd *cmd = HCtx[idx]->cmdControl;
|
||||||
|
@ -1958,7 +2051,7 @@ int HumanDriver::pit_cmd(int index, tCarElt* car, tSituation *s)
|
||||||
}//for i
|
}//for i
|
||||||
}//if HCtx
|
}//if HCtx
|
||||||
|
|
||||||
return ROB_PIT_MENU; /* The player is able to modify the value by menu */
|
return ROB_PIT_IM; /* With dashboard no need for menu */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue