Removal of duplicate code. No changes should be observed.

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3100 4a71c877-e1ca-e34f-864e-861f7616d084
master
Gerard Krol 2007-12-18 21:11:04 +00:00
parent 1e7bf56eba
commit 718bff04f9
11 changed files with 198 additions and 786 deletions

View File

@ -667,42 +667,17 @@ static void HandleDrag(void)
{
UDWORD dragX, dragY;
if(driveModeActive()) {
if(mouseDown(MOUSE_LMB)) {
if(buildState == BUILD3D_VALID)
{
if ((((STRUCTURE_STATS *)sBuildDetails.psStats)->type == REF_WALL
|| ((STRUCTURE_STATS *)sBuildDetails.psStats)->type == REF_DEFENSE)
&& !isLasSat((STRUCTURE_STATS *)sBuildDetails.psStats))
{
int dx,dy;
wallDrag.x2 = mouseTileX;
wallDrag.y2 = mouseTileY;
dx = abs(mouseTileX - wallDrag.x1);
dy = abs(mouseTileY - wallDrag.y1);
if(dx >= dy) {
wallDrag.y2 = wallDrag.y1;
} else if(dx < dy) {
wallDrag.x2 = wallDrag.x1;
}
wallDrag.status = DRAG_DRAGGING;
}
}
}
return;
}
if(mouseDrag(MOUSE_LMB, &dragX, &dragY) && !mouseOverRadar && !mouseDown(MOUSE_RMB))
if ( (driveModeActive() && mouseDown(MOUSE_LMB))
|| (mouseDrag(MOUSE_LMB, &dragX, &dragY) && !mouseOverRadar && !mouseDown(MOUSE_RMB)) )
{
dragBox3D.x1 = dragX;
dragBox3D.x2 = mouseXPos;
dragBox3D.y1 = dragY;
dragBox3D.y2 = mouseYPos;
if(!driveModeActive()) {
dragBox3D.x1 = dragX;
dragBox3D.x2 = mouseXPos;
dragBox3D.y1 = dragY;
dragBox3D.y2 = mouseYPos;
dragBox3D.status = DRAG_DRAGGING;
}
if(buildState == BUILD3D_VALID)
{
@ -727,7 +702,6 @@ static void HandleDrag(void)
wallDrag.status = DRAG_DRAGGING;
}
}
dragBox3D.status = DRAG_DRAGGING;
}
}

View File

@ -3925,126 +3925,66 @@ void setSelectedCommander(UDWORD commander)
selectedCommander = commander;
}
/* calculate muzzle tip location in 3d world
* Watermelon:note:only the 1st muzzleLocation is calculated,since WEAPON_IMD and WEAPON_MOUNT_IMD
* are #define pointing to asWeaps[0]...
*/
/**
* calculate muzzle tip location in 3d world
*/
BOOL calcDroidMuzzleLocation(DROID *psDroid, Vector3i *muzzle, int weapon_slot)
{
// UDWORD turretType;
// UDWORD bodyType;
Vector3i barrel;
iIMDShape *psShape, *psWeapon, *psWeaponMount;
CHECK_DROID(psDroid);
psShape = BODY_IMD(psDroid,psDroid->player);
//Watermelon:got rid of the macros...
//psWeapon = WEAPON_IMD(psDroid,psDroid->player);
//psWeaponMount = WEAPON_MOUNT_IMD(psDroid,psDroid->player);
if (weapon_slot >= 0)
psWeapon = (asWeaponStats[psDroid->asWeaps[weapon_slot].nStat]).pIMD;
psWeaponMount = (asWeaponStats[psDroid->asWeaps[weapon_slot].nStat]).pMountGraphic;
if(psShape && psShape->nconnectors)
{
psWeapon = (asWeaponStats[psDroid->asWeaps[weapon_slot].nStat]).pIMD;
psWeaponMount = (asWeaponStats[psDroid->asWeaps[weapon_slot].nStat]).pMountGraphic;
if(psShape && psShape->nconnectors)
pie_MatBegin();
pie_TRANSLATE(psDroid->pos.x,-(SDWORD)psDroid->pos.z,psDroid->pos.y);
//matrix = the center of droid
pie_MatRotY( DEG( (SDWORD)psDroid->direction ) );
pie_MatRotX( DEG( psDroid->pitch ) );
pie_MatRotZ( DEG( -(SDWORD)psDroid->roll ) );
pie_TRANSLATE( psShape->connectors[weapon_slot].x, -psShape->connectors[weapon_slot].z,
-psShape->connectors[weapon_slot].y);//note y and z flipped
//matrix = the gun and turret mount on the body
pie_MatRotY(DEG((SDWORD)psDroid->turretRotation[weapon_slot]));//+ve anticlockwise
pie_MatRotX(DEG(psDroid->turretPitch[weapon_slot]));//+ve up
pie_MatRotZ(DEG(0));
//matrix = the muzzle mount on turret
if( psWeapon && psWeapon->nconnectors )
{
pie_MatBegin();
pie_TRANSLATE(psDroid->pos.x,-(SDWORD)psDroid->pos.z,psDroid->pos.y);
//matrix = the center of droid
pie_MatRotY( DEG( (SDWORD)psDroid->direction ) );
pie_MatRotX( DEG( psDroid->pitch ) );
pie_MatRotZ( DEG( -(SDWORD)psDroid->roll ) );
// pie_TRANSLATE(100,0,0); // (left,-height,forward)
pie_TRANSLATE( psShape->connectors[weapon_slot].x, -psShape->connectors[weapon_slot].z,
-psShape->connectors[weapon_slot].y);//note y and z flipped
//matrix = the gun and turret mount on the body
pie_MatRotY(DEG((SDWORD)psDroid->turretRotation[weapon_slot]));//+ve anticlockwise
pie_MatRotX(DEG(psDroid->turretPitch[weapon_slot]));//+ve up
pie_MatRotZ(DEG(0));
//matrix = the muzzle mount on turret
if( psWeapon && psWeapon->nconnectors )
{
barrel.x = psWeapon->connectors->x;
barrel.y = -psWeapon->connectors->y;
barrel.z = -psWeapon->connectors->z;
}
else
{
barrel.x = 0;
barrel.y = 0;
barrel.z = 0;
}
pie_RotateTranslate3iv(&barrel, muzzle);
muzzle->z = -muzzle->z;
pie_MatEnd();
barrel.x = psWeapon->connectors->x;
barrel.y = -psWeapon->connectors->y;
barrel.z = -psWeapon->connectors->z;
}
else
{
muzzle->x = psDroid->pos.x;
muzzle->y = psDroid->pos.y;
muzzle->z = psDroid->pos.z+32;
barrel.x = 0;
barrel.y = 0;
barrel.z = 0;
}
pie_RotateTranslate3iv(&barrel, muzzle);
muzzle->z = -muzzle->z;
pie_MatEnd();
}
else
{
psWeapon = (asWeaponStats[psDroid->asWeaps[0].nStat]).pIMD;
psWeaponMount = (asWeaponStats[psDroid->asWeaps[0].nStat]).pMountGraphic;
if(psShape && psShape->nconnectors)
{
// This code has not been translated to the PSX Yet !!!! (sorry)
pie_MatBegin();
pie_TRANSLATE(psDroid->pos.x,-(SDWORD)psDroid->pos.z,psDroid->pos.y);
//matrix = the center of droid
pie_MatRotY( DEG( (SDWORD)psDroid->direction ) );
pie_MatRotX( DEG( psDroid->pitch ) );
pie_MatRotZ( DEG( -(SDWORD)psDroid->roll ) );
// pie_TRANSLATE(100,0,0); // (left,-height,forward)
pie_TRANSLATE( psShape->connectors->x, -psShape->connectors->z,
-psShape->connectors->y);//note y and z flipped
//matrix = the gun and turret mount on the body
//Watermelon:force it to use 0 thanks to the define weirdness...
pie_MatRotY(DEG((SDWORD)psDroid->turretRotation[0]));//+ve anticlockwise
pie_MatRotX(DEG(psDroid->turretPitch[0]));//+ve up
pie_MatRotZ(DEG(0));
//matrix = the muzzle mount on turret
if( psWeapon && psWeapon->nconnectors )
{
barrel.x = psWeapon->connectors->x;
barrel.y = -psWeapon->connectors->y;
barrel.z = -psWeapon->connectors->z;
}
else
{
barrel.x = 0;
barrel.y = 0;
barrel.z = 0;
}
pie_RotateTranslate3iv(&barrel, muzzle);
muzzle->z = -muzzle->z;
pie_MatEnd();
}
else
{
muzzle->x = psDroid->pos.x;
muzzle->y = psDroid->pos.y;
muzzle->z = psDroid->pos.z+32;
}
muzzle->x = psDroid->pos.x;
muzzle->y = psDroid->pos.y;
muzzle->z = psDroid->pos.z+32;
}
CHECK_DROID(psDroid);
return TRUE;
}
/* IF YOU USE THIS FUNCTION - NOTE THAT selectedPlayer's TEMPLATES ARE NOT USED!!!!
gets a template from its name - relies on the name being unique (or it will
return the first one it finds!! */

View File

@ -1700,52 +1700,6 @@ void intDisplayButtonHilight(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, P
UWORD ImageID;
GetButtonState(psWidget,&Hilight,&Down,&Grey);
// switch(psWidget->type) {
// case WIDG_FORM:
// if( ((W_CLICKFORM*)psWidget)->state & WCLICK_HILITE) {
// Hilight = TRUE;
// }
// if( ((W_CLICKFORM*)psWidget)->state & (WCLICK_DOWN | WCLICK_LOCKED | WCLICK_CLICKLOCK)) {
// Down = 1;
// }
// if( ((W_CLICKFORM*)psWidget)->state & WCLICK_GREY) {
// Grey = 1;
// }
// break;
//
// case WIDG_BUTTON:
// if( ((W_BUTTON*)psWidget)->state & WBUTS_HILITE) {
// Hilight = TRUE;
// }
// if( ((W_BUTTON*)psWidget)->state & (WBUTS_DOWN | WBUTS_LOCKED | WBUTS_CLICKLOCK)) {
// Down = 1;
// }
// if( ((W_BUTTON*)psWidget)->state & WBUTS_GREY) {
// Grey = 1;
// }
// break;
//
// case WIDG_EDITBOX:
// if( ((W_EDITBOX*)psWidget)->state & WEDBS_HILITE) {
// Hilight = TRUE;
// }
// break;
//
// case WIDG_SLIDER:
// if( ((W_SLIDER*)psWidget)->state & SLD_HILITE) {
// Hilight = TRUE;
// }
// if( ((W_SLIDER*)psWidget)->state & (WCLICK_DOWN | WCLICK_LOCKED | WCLICK_CLICKLOCK)) {
// Down = 1;
// }
// break;
//
// default:
// Hilight = FALSE;
// }
if(Grey) {
ImageID = UNPACKDWORD_TRI_A(psWidget->UserData);
Hilight = FALSE;
@ -1760,36 +1714,6 @@ void intDisplayButtonHilight(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, P
}
// Display one of two images depending on if the widget is hilighted by the mouse.
//
void intDisplayAltButtonHilight(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours)
{
UDWORD x = xOffset+psWidget->x;
UDWORD y = yOffset+psWidget->y;
BOOL Hilight = FALSE;
BOOL Grey = FALSE;
UDWORD Down = 0;
UWORD ImageID;
GetButtonState(psWidget,&Hilight,&Down,&Grey);
if(Grey) {
ImageID = UNPACKDWORD_TRI_A(psWidget->UserData);
Hilight = FALSE;
} else {
ImageID = UNPACKDWORD_TRI_C(psWidget->UserData) + Down;
}
iV_DrawImage(IntImages,ImageID,x,y);
if(Hilight) {
iV_DrawImage(IntImages,UNPACKDWORD_TRI_B(psWidget->UserData),x,y);
}
}
// Flash one of two images depending on if the widget is hilighted by the mouse.
//
void intDisplayButtonFlash(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours)

View File

@ -223,7 +223,6 @@ void intDisplayImage(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT
void intDisplayImageHilight(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
void intDisplayButtonHilight(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
void intDisplayAltButtonHilight(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
void intDisplayButtonFlash(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);

View File

@ -671,7 +671,7 @@ BOOL intAddOrder(BASE_OBJECT *psObj)
sButInit.formID = IDORDER_FORM;
sButInit.id = IDORDER_CLOSE+1;
sButInit.style = WBUT_PLAIN;
sButInit.pDisplay = intDisplayAltButtonHilight;
sButInit.pDisplay = intDisplayButtonHilight;
sButInit.FontID = font_regular;
sButInit.y = ORDER_BUTY;

View File

@ -860,88 +860,7 @@ UDWORD getRepairIdFromFlag(FLAG_POSITION *psFlag)
// check a base object exists for an ID
BOOL checkValidId(UDWORD id)
{
unsigned int i;
UDWORD player;
BASE_OBJECT *psObj;
DROID *psTrans;
for(i = 0; i < 7; ++i)
{
for(player = 0; player < MAX_PLAYERS; ++player)
{
switch (i)
{
case 0:
psObj=(BASE_OBJECT *)apsDroidLists[player];
break;
case 1:
psObj=(BASE_OBJECT *)apsStructLists[player];
break;
case 2:
if (player == 0)
{
psObj=(BASE_OBJECT *)apsFeatureLists[0];
}
else
{
psObj = NULL;
}
break;
case 3:
psObj=(BASE_OBJECT *)mission.apsDroidLists[player];
break;
case 4:
psObj=(BASE_OBJECT *)mission.apsStructLists[player];
break;
case 5:
if (player == 0)
{
psObj=(BASE_OBJECT *)mission.apsFeatureLists[0];
}
else
{
psObj = NULL;
}
break;
case 6:
if (player == 0)
{
psObj=(BASE_OBJECT *)apsLimboDroids[0];
}
else
{
psObj = NULL;
}
break;
default:
psObj = NULL;
break;
}
while (psObj)
{
if (psObj->id == id)
{
return TRUE;
}
// if transporter check any droids in the grp
if ((psObj->type == OBJ_DROID) && (((DROID*)psObj)->droidType == DROID_TRANSPORTER))
{
for(psTrans = ((DROID*)psObj)->psGroup->psList; psTrans != NULL; psTrans = psTrans->psGrpNext)
{
if (psTrans->id == id)
{
return TRUE;
}
}
}
psObj = psObj->psNext;
}
}
}
ASSERT(!"invalid ID for BASE_OBJ", "checkValidId() failed for id %d", id);
return FALSE;
return getBaseObjFromId(id) != NULL;
}

View File

@ -1442,130 +1442,61 @@ proj_ImpactFunc( PROJECTILE *psObj )
/* Store the radius cubed */
radCubed = psStats->radius * psStats->radius * psStats->radius;
/* Watermelon:air suppression */
if (psObj->airTarget)
for (i = 0; i < MAX_PLAYERS; i++)
{
for (i = 0; i < MAX_PLAYERS; i++)
for (psCurrD = apsDroidLists[i]; psCurrD; psCurrD = psNextD)
{
for (psCurrD = apsDroidLists[i]; psCurrD; psCurrD = psNextD)
/* have to store the next pointer as psCurrD could be destroyed */
psNextD = psCurrD->psNext;
/* see if psCurrD is hit (don't hit main target twice) */
if (((BASE_OBJECT *)psCurrD != psObj->psDest) &&
((SDWORD)psCurrD->pos.x >= tarX0) &&
((SDWORD)psCurrD->pos.x <= tarX1) &&
((SDWORD)psCurrD->pos.y >= tarY0) &&
((SDWORD)psCurrD->pos.y <= tarY1) &&
((SDWORD)psCurrD->pos.z >= tarZ0) &&
((SDWORD)psCurrD->pos.z <= tarZ1))
{
/* have to store the next pointer as psCurrD could be destroyed */
psNextD = psCurrD->psNext;
/* Watermelon:skip no vtol droids and landed votl's */
if (!vtolDroid(psCurrD) ||
(vtolDroid(psCurrD) && psCurrD->sMove.Status == MOVEINACTIVE))
/* Within the bounding box, now check the radius */
xDiff = psCurrD->pos.x - psObj->pos.x;
yDiff = psCurrD->pos.y - psObj->pos.y;
zDiff = psCurrD->pos.z - psObj->pos.z;
if ((xDiff*xDiff + yDiff*yDiff + zDiff*zDiff) <= radCubed)
{
continue;
}
/* see if psCurrD is hit (don't hit main target twice) */
if (((BASE_OBJECT *)psCurrD != psObj->psDest) &&
((SDWORD)psCurrD->pos.x >= tarX0) &&
((SDWORD)psCurrD->pos.x <= tarX1) &&
((SDWORD)psCurrD->pos.y >= tarY0) &&
((SDWORD)psCurrD->pos.y <= tarY1) &&
((SDWORD)psCurrD->pos.z >= tarZ0) &&
((SDWORD)psCurrD->pos.z <= tarZ1))
{
/* Within the bounding box, now check the radius */
xDiff = psCurrD->pos.x - psObj->pos.x;
yDiff = psCurrD->pos.y - psObj->pos.y;
zDiff = psCurrD->pos.z - psObj->pos.z;
if ((xDiff*xDiff + yDiff*yDiff + zDiff*zDiff) <= radCubed)
HIT_ROLL(dice);
if (dice < weaponRadiusHit(psStats, psObj->player))
{
HIT_ROLL(dice);
if (dice < weaponRadiusHit(psStats, psObj->player))
debug(LOG_NEVER, "Damage to object %d, player %d\n",
psCurrD->id, psCurrD->player);
damage = calcDamage(
weaponRadDamage(psStats, psObj->player),
psStats->weaponEffect, (BASE_OBJECT *)psCurrD);
if (bMultiPlayer)
{
debug(LOG_NEVER, "Damage to object %d, player %d\n",
psCurrD->id, psCurrD->player);
damage = calcDamage(weaponRadDamage(psStats, psObj->player), psStats->weaponEffect, (BASE_OBJECT *) psCurrD);
if (bMultiPlayer)
if (psObj->psSource && myResponsibility(psObj->psSource->player))
{
if (psObj->psSource && myResponsibility(psObj->psSource->player))
{
updateMultiStatsDamage(psObj->psSource->player, psCurrD->player, damage);
}
turnOffMultiMsg(TRUE);
updateMultiStatsDamage(psObj->psSource->player, psCurrD->player, damage);
}
//Watermelon:uses a slightly different check for angle,
// since fragment of a project is from the explosion spot not from the projectile start position
impactSide = getHitSide(psObj, (BASE_OBJECT *)psCurrD);
percentDamage = droidDamage(psCurrD, damage, psStats->weaponClass, psStats->weaponSubClass, impactSide);
turnOffMultiMsg(FALSE); // multiplay msgs back on.
proj_UpdateKills(psObj, percentDamage);
turnOffMultiMsg(TRUE);
}
//Watermelon:uses a slightly different check for angle,
// since fragment of a project is from the explosion spot not from the projectile start position
impactSide = getHitSide(psObj, (BASE_OBJECT *)psCurrD);
percentDamage = droidDamage(psCurrD, damage, psStats->weaponClass, psStats->weaponSubClass, impactSide);
turnOffMultiMsg(FALSE); // multiplay msgs back on.
proj_UpdateKills(psObj, percentDamage);
}
}
}
}
}
else
{
/* Do damage to everything in range */
for (i = 0; i < MAX_PLAYERS; i++)
if (!psObj->airTarget)
{
for (psCurrD = apsDroidLists[i]; psCurrD; psCurrD = psNextD)
{
/* have to store the next pointer as psCurrD could be destroyed */
psNextD = psCurrD->psNext;
if (vtolDroid(psCurrD) &&
(psCurrD->sMove.Status != MOVEINACTIVE))
{
// skip VTOLs in the air
continue;
}
/* see if psCurrD is hit (don't hit main target twice) */
if (((BASE_OBJECT *)psCurrD != psObj->psDest) &&
((SDWORD)psCurrD->pos.x >= tarX0) &&
((SDWORD)psCurrD->pos.x <= tarX1) &&
((SDWORD)psCurrD->pos.y >= tarY0) &&
((SDWORD)psCurrD->pos.y <= tarY1))
{
/* Within the bounding box, now check the radius */
xDiff = psCurrD->pos.x - psObj->pos.x;
yDiff = psCurrD->pos.y - psObj->pos.y;
if ((xDiff*xDiff + yDiff*yDiff) <= radCubed)
{
HIT_ROLL(dice);
if (dice < weaponRadiusHit(psStats, psObj->player))
{
debug(LOG_NEVER, "Damage to object %d, player %d\n",
psCurrD->id, psCurrD->player);
damage = calcDamage(
weaponRadDamage(psStats, psObj->player),
psStats->weaponEffect, (BASE_OBJECT *)psCurrD);
if (bMultiPlayer)
{
if (psObj->psSource && myResponsibility(psObj->psSource->player))
{
updateMultiStatsDamage(psObj->psSource->player, psCurrD->player, damage);
}
turnOffMultiMsg(TRUE);
}
//Watermelon:uses a slightly different check for angle,
// since fragment of a project is from the explosion spot not from the projectile start position
impactSide = getHitSide(psObj, (BASE_OBJECT *)psCurrD);
percentDamage = droidDamage(psCurrD, damage, psStats->weaponClass,psStats->weaponSubClass, impactSide);
turnOffMultiMsg(FALSE); // multiplay msgs back on.
proj_UpdateKills(psObj, percentDamage);
}
}
}
}
for (psCurrS = apsStructLists[i]; psCurrS; psCurrS = psNextS)
{
/* have to store the next pointer as psCurrD could be destroyed */

View File

@ -5628,157 +5628,17 @@ static BOOL structDoubleCheck(BASE_STATS *psStat,UDWORD xx,UDWORD yy, SDWORD max
}
// pick a structure location(only used in skirmish game at 27Aug) ajl.
BOOL scrPickStructLocation(void)
static BOOL pickStructLocation(int index, int *pX, int *pY, int player, int maxBlockingTiles)
{
SDWORD *pX,*pY;
SDWORD index;
STRUCTURE_STATS *psStat;
UDWORD numIterations = 30;
BOOL found = FALSE;
UDWORD startX, startY, incX, incY;
SDWORD x=0, y=0;
UDWORD player;
if (!stackPopParams(4, ST_STRUCTURESTAT, &index, VAL_REF|VAL_INT, &pX ,
VAL_REF|VAL_INT, &pY, VAL_INT, &player))
{
return FALSE;
}
if (player >= MAX_PLAYERS)
{
ASSERT( FALSE, "scrPickStructLocation:player number is too high" );
return FALSE;
}
// check for wacky coords.
if( *pX < 0
|| *pX > world_coord(mapWidth)
|| *pY < 0
|| *pY > world_coord(mapHeight)
)
{
goto failedstructloc;
}
psStat = &asStructureStats[index]; // get stat.
startX = map_coord(*pX); // change to tile coords.
startY = map_coord(*pY);
x = startX;
y = startY;
// first try the original location
if ( validLocation((BASE_STATS*)psStat, startX, startY, player, FALSE) )
{
if(structDoubleCheck((BASE_STATS*)psStat,startX,startY,MAX_BLOCKING_TILES))
{
found = TRUE;
}
}
// try some locations nearby
if(!found)
{
for (incX = 1, incY = 1; incX < numIterations; incX++, incY++)
{
if (!found){ //top
y = startY - incY;
for(x = startX - incX; x < (SDWORD)(startX + incX); x++){
if ( validLocation((BASE_STATS*)psStat, x, y, player, FALSE)
&& structDoubleCheck((BASE_STATS*)psStat,x,y,MAX_BLOCKING_TILES)
){
found = TRUE;
break;
}}}
if (!found) { //right
x = startX + incX;
for(y = startY - incY; y < (SDWORD)(startY + incY); y++){
if(validLocation((BASE_STATS*)psStat, x, y, player, FALSE)
&& structDoubleCheck((BASE_STATS*)psStat,x,y,MAX_BLOCKING_TILES)
){
found = TRUE;
break;
}}}
if (!found){ //bot
y = startY + incY;
for(x = startX + incX; x > (SDWORD)(startX - incX); x--){
if(validLocation((BASE_STATS*)psStat, x, y, player, FALSE)
&& structDoubleCheck((BASE_STATS*)psStat,x,y,MAX_BLOCKING_TILES)
){
found = TRUE;
break;
}}}
if (!found){ //left
x = startX - incX;
for(y = startY + incY; y > (SDWORD)(startY - incY); y--){
if(validLocation((BASE_STATS*)psStat, x, y, player, FALSE)
&& structDoubleCheck((BASE_STATS*)psStat,x,y,MAX_BLOCKING_TILES)
){
found = TRUE;
break;
}}}
if (found)
{
break;
}
}
}
if(found) // did It!
{
// back to world coords.
*pX = world_coord(x) + (psStat->baseWidth * (TILE_UNITS / 2));
*pY = world_coord(y) + (psStat->baseBreadth * (TILE_UNITS / 2));
scrFunctionResult.v.bval = TRUE;
if (!stackPushResult(VAL_BOOL, &scrFunctionResult)) // success!
{
return FALSE;
}
return TRUE;
}
else
{
failedstructloc:
scrFunctionResult.v.bval = FALSE;
if (!stackPushResult(VAL_BOOL, &scrFunctionResult)) // failed!
{
return FALSE;
}
}
return TRUE;
}
// pick a structure location(only used in skirmish game at 27Aug) ajl.
// Max number of blocking tiles is passed as parameter for this one
BOOL scrPickStructLocationB(void)
{
SDWORD *pX,*pY;
SDWORD index;
STRUCTURE_STATS *psStat;
UDWORD numIterations = 30;
BOOL found = FALSE;
UDWORD startX, startY, incX, incY;
SDWORD x=0, y=0;
UDWORD player;
SDWORD maxBlockingTiles;
if (!stackPopParams(5, ST_STRUCTURESTAT, &index, VAL_REF|VAL_INT, &pX ,
VAL_REF|VAL_INT, &pY, VAL_INT, &player, VAL_INT, &maxBlockingTiles))
{
return FALSE;
}
if (player >= MAX_PLAYERS)
{
ASSERT( FALSE, "scrPickStructLocationB:player number is too high" );
ASSERT( FALSE, "pickStructLocation:player number is too high" );
return FALSE;
}
@ -5886,6 +5746,38 @@ failedstructloc:
return TRUE;
}
// pick a structure location(only used in skirmish game at 27Aug) ajl.
BOOL scrPickStructLocation(void)
{
SDWORD *pX,*pY;
SDWORD index;
UDWORD player;
if (!stackPopParams(4, ST_STRUCTURESTAT, &index, VAL_REF|VAL_INT, &pX ,
VAL_REF|VAL_INT, &pY, VAL_INT, &player))
{
return FALSE;
}
return pickStructLocation(index, pX, pY, player, MAX_BLOCKING_TILES);
}
// pick a structure location(only used in skirmish game at 27Aug) ajl.
// Max number of blocking tiles is passed as parameter for this one
BOOL scrPickStructLocationB(void)
{
SDWORD *pX,*pY;
SDWORD index;
UDWORD player;
SDWORD maxBlockingTiles;
if (!stackPopParams(5, ST_STRUCTURESTAT, &index, VAL_REF|VAL_INT, &pX ,
VAL_REF|VAL_INT, &pY, VAL_INT, &player, VAL_INT, &maxBlockingTiles))
{
return FALSE;
}
return pickStructLocation(index, pX, pY, player, maxBlockingTiles);
}
// -----------------------------------------------------------------------------------------
// Sets the transporter entry and exit points for the map
BOOL scrSetTransporterExit(void)
@ -7955,44 +7847,12 @@ BOOL scrFriendlyWeapObjCostInRange(void)
return TRUE;
}
UDWORD numPlayerWeapDroidsInRange(SDWORD player, SDWORD lookingPlayer, SDWORD range, SDWORD rangeX, SDWORD rangeY, BOOL bVTOLs)
{
UDWORD numEnemies;
DROID *psDroid;
numEnemies = 0;
//check droids
for(psDroid = apsDroidLists[player]; psDroid; psDroid = psDroid->psNext)
{
if(psDroid->visible[lookingPlayer]) //can see this droid?
{
if (psDroid->droidType != DROID_WEAPON &&
psDroid->droidType != DROID_PERSON &&
psDroid->droidType != DROID_CYBORG &&
psDroid->droidType != DROID_CYBORG_SUPER)
{
continue;
}
//if VTOLs are excluded, skip them
if(!bVTOLs && ((asPropulsionStats[psDroid->asBits[COMP_PROPULSION].nStat].propulsionType == LIFT) || (psDroid->droidType == DROID_TRANSPORTER)))
{
continue;
}
if((range < 0) || (dirtySqrt(rangeX, rangeY , psDroid->pos.x, psDroid->pos.y) < range)) //enemy in range
{
numEnemies++;
}
}
}
return numEnemies;
}
UDWORD playerWeapDroidsCostInRange(SDWORD player, SDWORD lookingPlayer, SDWORD range,
SDWORD rangeX, SDWORD rangeY, BOOL bVTOLs)
/**
* Helper function for numPlayerWeapDroidsInRange and playerWeapDroidsCostInRange.
* Will either count the number of droids or calculate the total costs.
*/
static UDWORD costOrAmountInRange(SDWORD player, SDWORD lookingPlayer, SDWORD range,
SDWORD rangeX, SDWORD rangeY, BOOL bVTOLs, BOOL justCount)
{
UDWORD droidCost;
DROID *psDroid;
@ -8020,7 +7880,14 @@ UDWORD playerWeapDroidsCostInRange(SDWORD player, SDWORD lookingPlayer, SDWORD r
if((range < 0) || (dirtySqrt(rangeX, rangeY , psDroid->pos.x, psDroid->pos.y) < range)) //enemy in range
{
droidCost += calcDroidPower(psDroid);
if (justCount)
{
droidCost++;
}
else
{
droidCost += calcDroidPower(psDroid);
}
}
}
}
@ -8028,6 +7895,17 @@ UDWORD playerWeapDroidsCostInRange(SDWORD player, SDWORD lookingPlayer, SDWORD r
return droidCost;
}
UDWORD numPlayerWeapDroidsInRange(SDWORD player, SDWORD lookingPlayer, SDWORD range, SDWORD rangeX, SDWORD rangeY, BOOL bVTOLs)
{
return costOrAmountInRange(player, lookingPlayer, range, rangeX, rangeY, bVTOLs, TRUE /*only count*/);
}
UDWORD playerWeapDroidsCostInRange(SDWORD player, SDWORD lookingPlayer, SDWORD range,
SDWORD rangeX, SDWORD rangeY, BOOL bVTOLs)
{
return costOrAmountInRange(player, lookingPlayer, range, rangeX, rangeY, bVTOLs, FALSE /*total cost*/);
}
UDWORD numPlayerWeapStructsInRange(SDWORD player, SDWORD lookingPlayer, SDWORD range,

View File

@ -1087,7 +1087,7 @@ BOOL scrValDefLoad(SDWORD version, INTERP_VAL *psVal, char *pBuffer, UDWORD size
members = size / sizeof(UDWORD);
pPos = pBuffer;
}
else if (version == 2)
if (version >= 2)
{
members = (size - sizeof(SDWORD)*4) / sizeof(UDWORD);
pPos = pBuffer;
@ -1107,28 +1107,11 @@ BOOL scrValDefLoad(SDWORD version, INTERP_VAL *psVal, char *pBuffer, UDWORD size
psGroup->sRunData.leadership = (UBYTE)(*((SDWORD *)pPos));
pPos += sizeof(SDWORD);
}
else
if (version >= 3)
{
members = (size - sizeof(SDWORD)*5) / sizeof(UDWORD);
pPos = pBuffer;
// load the retreat data
psGroup = (DROID_GROUP*)(psVal->v.oval);
endian_sdword((SDWORD*)pPos);
psGroup->sRunData.sPos.x = *((SDWORD *)pPos);
psGroup->sRunData.healthLevel = (UBYTE)(*((SDWORD *)pPos));
pPos += sizeof(SDWORD);
endian_sdword((SDWORD*)pPos);
psGroup->sRunData.sPos.y = *((SDWORD *)pPos);
pPos += sizeof(SDWORD);
endian_sdword((SDWORD*)pPos);
psGroup->sRunData.forceLevel = (UBYTE)(*((SDWORD *)pPos));
pPos += sizeof(SDWORD);
endian_sdword((SDWORD*)pPos);
psGroup->sRunData.leadership = (UBYTE)(*((SDWORD *)pPos));
pPos += sizeof(SDWORD);
endian_sdword((SDWORD*)pPos);
psGroup->sRunData.healthLevel = (UBYTE)(*((SDWORD *)pPos));
pPos += sizeof(SDWORD);
}
// load the droids

View File

@ -444,86 +444,6 @@ BOOL bLaterInList, bMatch;
}
}
}
#if 0
// ---------------------------------------------------------------------
void selNextRepairUnit( void )
{
DROID *psCurr;
DROID *psResult;
DROID *psFirst;
BOOL bLaterInList;
for(psCurr = apsDroidLists[selectedPlayer],psFirst = NULL,psResult = NULL,bLaterInList = FALSE;
psCurr && !psResult; psCurr = psCurr->psNext)
{
if( psCurr->droidType == DROID_REPAIR ||
psCurr->droidType == DROID_CYBORG_REPAIR )
{
/* Always store away the first one we find */
if(!psFirst)
{
psFirst = psCurr;
}
if(psCurr == psOldRD)
{
bLaterInList = TRUE;
}
/* Nothing previously found... */
if(!psOldRD)
{
psResult = psCurr;
}
/* Only select is this isn't the old one and it's further on in list */
else if(psCurr!=psOldRD && bLaterInList)
{
psResult = psCurr;
}
}
}
/* Did we get one? */
if(!psResult)
{
/* was there at least one - the first one? Resetting */
if(psFirst)
{
psResult = psFirst;
}
}
if(psResult && !psResult->died)
{
selDroidDeselect(selectedPlayer);
// psResult->selected = TRUE;
SelectDroid(psResult);
if(getWarCamStatus())
{
camToggleStatus(); // messy - fix this
// setViewPos(map_coord(psCentreDroid->pos.x), map_coord(psCentreDroid->pos.y));
processWarCam(); //odd, but necessary
camToggleStatus(); // messy - FIXME
}
else
if(!getWarCamStatus())
{
// camToggleStatus();
/* Centre display on him if warcam isn't active */
setViewPos(map_coord(psResult->pos.x), map_coord(psResult->pos.y), TRUE);
}
psOldRD = psResult;
}
else
{
addConsoleMessage(_("Unable to locate any repair units!"),LEFT_JUSTIFY);
}
}
// ---------------------------------------------------------------------
#endif
// ---------------------------------------------------------------------
void selNextUnassignedUnit( void )
{

View File

@ -5583,113 +5583,57 @@ BOOL calcStructureMuzzleLocation(STRUCTURE *psStructure, Vector3i *muzzle, int w
CHECK_STRUCTURE(psStructure);
if (weapon_slot >= 0)
if (psStructure->asWeaps[weapon_slot].nStat > 0)
{
//if (psStructure->numWeaps > 0)
if (psStructure->asWeaps[weapon_slot].nStat > 0)
{
psWeaponImd = asWeaponStats[psStructure->asWeaps[weapon_slot].nStat].pIMD;
}
else
{
psWeaponImd = NULL;
}
if(psShape && psShape->nconnectors)
{
pie_MatBegin();
pie_TRANSLATE(psStructure->pos.x,-(SDWORD)psStructure->pos.z,psStructure->pos.y);
//matrix = the center of droid
pie_MatRotY( DEG( (SDWORD)psStructure->direction ) );
pie_MatRotX( DEG( psStructure->pitch ) );
pie_MatRotZ( DEG( -(SDWORD)psStructure->roll ) );
pie_TRANSLATE( psShape->connectors[weapon_slot].x, -psShape->connectors[weapon_slot].z,
-psShape->connectors[weapon_slot].y);//note y and z flipped
//matrix = the gun and turret mount on the body
pie_MatRotY(DEG((SDWORD)psStructure->turretRotation[weapon_slot]));//+ve anticlockwise
pie_MatRotX(DEG(psStructure->turretPitch[weapon_slot]));//+ve up
pie_MatRotZ(DEG(0));
//matrix = the muzzle mount on turret
if( psWeaponImd && psWeaponImd->nconnectors )
{
barrel.x = psWeaponImd->connectors->x;
barrel.y = -psWeaponImd->connectors->y;
barrel.z = -psWeaponImd->connectors->z;
}
else
{
barrel.x = 0;
barrel.y = 0;
barrel.z = 0;
}
pie_RotateTranslate3iv(&barrel, muzzle);
muzzle->z = -muzzle->z;
pie_MatEnd();
}
else
{
muzzle->x = psStructure->pos.x;
muzzle->y = psStructure->pos.y;
muzzle->z = psStructure->pos.z + psStructure->sDisplay.imd->ymax;;
}
psWeaponImd = asWeaponStats[psStructure->asWeaps[weapon_slot].nStat].pIMD;
}
else
{
if (psStructure->asWeaps[weapon_slot].nStat > 0)
{
psWeaponImd = asWeaponStats[psStructure->asWeaps[weapon_slot].nStat].pIMD;
}
else
{
psWeaponImd = NULL;
}
if(psShape && psShape->nconnectors)
{
pie_MatBegin();
pie_TRANSLATE(psStructure->pos.x,-(SDWORD)psStructure->pos.z,psStructure->pos.y);
//matrix = the center of droid
pie_MatRotY( DEG( (SDWORD)psStructure->direction ) );
pie_MatRotX( DEG( psStructure->pitch ) );
pie_MatRotZ( DEG( -(SDWORD)psStructure->roll ) );
pie_TRANSLATE( psShape->connectors->x, -psShape->connectors->z,
-psShape->connectors->y);//note y and z flipped
//matrix = the gun and turret mount on the body
pie_MatRotY(DEG((SDWORD)psStructure->turretRotation[0]));//+ve anticlockwise
pie_MatRotX(DEG(psStructure->turretPitch[0]));//+ve up
pie_MatRotZ(DEG(0));
//matrix = the muzzle mount on turret
if( psWeaponImd && psWeaponImd->nconnectors )
{
barrel.x = psWeaponImd->connectors->x;
barrel.y = -psWeaponImd->connectors->y;
barrel.z = -psWeaponImd->connectors->z;
}
else
{
barrel.x = 0;
barrel.y = 0;
barrel.z = 0;
}
pie_RotateTranslate3iv(&barrel, muzzle);
muzzle->z = -muzzle->z;
pie_MatEnd();
}
else
{
muzzle->x = psStructure->pos.x;
muzzle->y = psStructure->pos.y;
muzzle->z = psStructure->pos.z + psStructure->sDisplay.imd->ymax;;
}
psWeaponImd = NULL;
}
if(psShape && psShape->nconnectors)
{
pie_MatBegin();
pie_TRANSLATE(psStructure->pos.x,-(SDWORD)psStructure->pos.z,psStructure->pos.y);
//matrix = the center of droid
pie_MatRotY( DEG( (SDWORD)psStructure->direction ) );
pie_MatRotX( DEG( psStructure->pitch ) );
pie_MatRotZ( DEG( -(SDWORD)psStructure->roll ) );
pie_TRANSLATE( psShape->connectors[weapon_slot].x, -psShape->connectors[weapon_slot].z,
-psShape->connectors[weapon_slot].y);//note y and z flipped
//matrix = the gun and turret mount on the body
pie_MatRotY(DEG((SDWORD)psStructure->turretRotation[weapon_slot]));//+ve anticlockwise
pie_MatRotX(DEG(psStructure->turretPitch[weapon_slot]));//+ve up
pie_MatRotZ(DEG(0));
//matrix = the muzzle mount on turret
if( psWeaponImd && psWeaponImd->nconnectors )
{
barrel.x = psWeaponImd->connectors->x;
barrel.y = -psWeaponImd->connectors->y;
barrel.z = -psWeaponImd->connectors->z;
}
else
{
barrel.x = 0;
barrel.y = 0;
barrel.z = 0;
}
pie_RotateTranslate3iv(&barrel, muzzle);
muzzle->z = -muzzle->z;
pie_MatEnd();
}
else
{
muzzle->x = psStructure->pos.x;
muzzle->y = psStructure->pos.y;
muzzle->z = psStructure->pos.z + psStructure->sDisplay.imd->ymax;;
}
return TRUE;
}