コード例 #1
0
ファイル: ShipView.c プロジェクト: rcarmo/homeworld
/*-----------------------------------------------------------------------------
    Name        : svFirepowerRender
    Description : Callback which draws the firepower stat in ship view.
    Inputs      : standard FE callback
    Outputs     : ..
    Return      : void
----------------------------------------------------------------------------*/
void svFirepowerRender(featom *atom, regionhandle region)
{
    rectangle *rect = &region->rect;
    fonthandle currentFont;
    uword firepower;
    char buftemp[50];
    ShipStaticInfo *info = GetShipStaticInfoSafe(svShipType, universe.curPlayerPtr->race);

    svFirepowerRegion = region;

    if (FELASTCALL(atom))
    {
        svFirepowerRegion = NULL;
        return;
    }

    if(svShipType == DefaultShip)
    {
        return;
    }
    if (info == NULL)
    {
        info = GetShipStaticInfoSafe(svShipType, GetValidRaceForShipType(svShipType));
    }
    if (info == NULL)
    {
        return;
    }

    currentFont = fontMakeCurrent(svShipStatFont);

    if (RGLtype == SWtype) primRectSolid2(&region->rect, FEC_Background);

    if(info->svFirePower !=0)
    {
        firepower = (uword) info->svFirePower;
    }
    else
    {
        firepower = (uword) gunShipFirePower(info, Neutral);
    }
    if(firepower != 0)
    {
        sprintf(buftemp,"%d",firepower);
    }
    else
    {
        sprintf(buftemp,"%s","-");
    }
    sprintf(buf,ShipStatToNiceStr(Firepower),buftemp);

    fontPrintf(
        rect->x0,
        rect->y0,
        FEC_ListItemStandard,
        "%s",
        buf);

    fontMakeCurrent(currentFont);
}
コード例 #2
0
ファイル: ShipView.c プロジェクト: rcarmo/homeworld
/*-----------------------------------------------------------------------------
    Name        : svCoverageRender
    Description : Callback which draws the coverage stat in ship view.
    Inputs      : standard FE callback
    Outputs     : ..
    Return      : void
----------------------------------------------------------------------------*/
void svCoverageRender(featom *atom, regionhandle region)
{
    rectangle *rect = &region->rect;
    sdword width;
    fonthandle currentFont;
    char buftemp[50];
    uword coverage;
    ShipStaticInfo *info = GetShipStaticInfoSafe(svShipType, universe.curPlayerPtr->race);

    svCoverageRegion = region;

    if (FELASTCALL(atom))
    {
        svCoverageRegion = NULL;
        return;
    }

    if(svShipType == DefaultShip)
    {
        return;
    }

    if (info == NULL)
    {
        info = GetShipStaticInfoSafe(svShipType, GetValidRaceForShipType(svShipType));
    }

    if (info == NULL)
    {
        return; //maybe print UNKNOWN!
    }

    currentFont = fontMakeCurrent(svShipStatFont);

    coverage = svShipCoverage(info);
    if(coverage != 0)
    {
        sprintf(buftemp,"%d %s",coverage,ShipStatToNiceStr(CoverageUnits));
    }
    else
    {
        sprintf(buftemp,"%s","-");
    }
    sprintf(buf,ShipStatToNiceStr(Coverage),buftemp);

    width = fontWidthf("%s",buf);

    if (RGLtype == SWtype) primRectSolid2(&region->rect, FEC_Background);

    fontPrintf(
        rect->x0,//rect->x1 - width,
        rect->y0,
        FEC_ListItemStandard,
        "%s",buf);

    fontMakeCurrent(currentFont);
}
コード例 #3
0
ファイル: ShipView.c プロジェクト: rcarmo/homeworld
/*-----------------------------------------------------------------------------
    Name        : svTopSpeedRender
    Description : Callback which draws the top speed stat in ship view.
    Inputs      : standard FE callback
    Outputs     : ..
    Return      : void
----------------------------------------------------------------------------*/
void svTopSpeedRender(featom *atom, regionhandle region)
{
    rectangle *rect = &region->rect;
    fonthandle currentFont;
    char buftemp[50];

    ShipStaticInfo *info = GetShipStaticInfoSafe(svShipType, universe.curPlayerPtr->race);

    svTopSpeedRegion = region;

    if (FELASTCALL(atom))
    {
        svTopSpeedRegion = NULL;
        return;
    }

    if(svShipType == DefaultShip)
    {
            return;
    }
    if (info == NULL)
    {
        info = GetShipStaticInfoSafe(svShipType, GetValidRaceForShipType(svShipType));
    }
    if (info == NULL)
    {
        return;
    }

    currentFont = fontMakeCurrent(svShipStatFont);

    if (RGLtype == SWtype) primRectSolid2(&region->rect, FEC_Background);

    //sprintf(buf,"%d", (uword)info->staticheader.maxvelocity);
    //topspeed contains a %d for the numerical location of the maxvelocity
    if(info->shiptype == Probe)
    {
        sprintf(buftemp,"%d",(udword) ((ProbeStatics *) info->custstatinfo)->ProbeDispatchMaxVelocity);
        sprintf(buf,ShipStatToNiceStr(TopSpeed),buftemp);
    }
    else
    {
        sprintf(buftemp,"%d",(udword) info->staticheader.maxvelocity);
        sprintf(buf,ShipStatToNiceStr(TopSpeed),buftemp);
    }
    fontPrintf(
        rect->x0,
        rect->y0,
        FEC_ListItemStandard,
        "%s",
        buf);



    fontMakeCurrent(currentFont);
}
コード例 #4
0
ファイル: ShipView.c プロジェクト: rcarmo/homeworld
/*-----------------------------------------------------------------------------
    Name        : svMassRender
    Description : Callback which draws the mass stat in ship view.
    Inputs      : standard FE callback
    Outputs     : ..
    Return      : void
----------------------------------------------------------------------------*/
void svMassRender(featom *atom, regionhandle region)
{
    rectangle *rect = &region->rect;
    fonthandle currentFont;
    sdword width;
    char buftemp[50];

    ShipStaticInfo *info = GetShipStaticInfoSafe(svShipType, universe.curPlayerPtr->race);

    svMassRegion = region;

    if (FELASTCALL(atom))
    {
        svMassRegion = NULL;
        return;
    }

    if(svShipType == DefaultShip)
    {
            return;
    }
    if (info == NULL)
    {
        info = GetShipStaticInfoSafe(svShipType, GetValidRaceForShipType(svShipType));
    }
    if (info == NULL)
    {
        return;
    }

    currentFont = fontMakeCurrent(svShipStatFont);

    //sprintf(buf, "%d", (uword)info->staticheader.mass);
    //Mass str contains a %d for the mass to expand into
    sprintf(buftemp,"%d",(udword)info->staticheader.mass);
    sprintf(buf,ShipStatToNiceStr(Mass),buftemp);

    width = fontWidthf("%s",
        buf);                       //width of number
        //ShipTypeStatToNiceStr(svShipType, Mass));//width of number


    if (RGLtype == SWtype) primRectSolid2(&region->rect, FEC_Background);

    fontPrintf(
        rect->x0,//rect->x1 - width,
        rect->y0,
        FEC_ListItemStandard,
        "%s",
        buf);
        //ShipTypeStatToNiceStr(svShipType, Mass));

    fontMakeCurrent(currentFont);
}
コード例 #5
0
ファイル: ShipView.c プロジェクト: rcarmo/homeworld
/*-----------------------------------------------------------------------------
    Name        : svArmorRender
    Description : Callback which draws the armor stat in ship view.
    Inputs      : standard FE callback
    Outputs     : ..
    Return      : void
----------------------------------------------------------------------------*/
void svArmorRender(featom *atom, regionhandle region)
{
    rectangle *rect = &region->rect;
    sdword width;
    char buftemp[50];

    fonthandle currentFont;
    ShipStaticInfo *info = GetShipStaticInfoSafe(svShipType, universe.curPlayerPtr->race);

    svArmorRegion = region;

    if (FELASTCALL(atom))
    {
        svArmorRegion = NULL;
        return;
    }

    if(svShipType == DefaultShip)
    {
        return;
    }
    if (info == NULL)
    {
        info = GetShipStaticInfoSafe(svShipType, GetValidRaceForShipType(svShipType));
    }
    if (info == NULL)
    {
        return;
    }

    svArmorRegion = region;

    currentFont = fontMakeCurrent(svShipStatFont);

    sprintf(buftemp,"%d",(udword) info->maxhealth);
    sprintf(buf,ShipStatToNiceStr(Armor),buftemp);

    width = fontWidthf("%s",buf);

    if (RGLtype == SWtype) primRectSolid2(&region->rect, FEC_Background);

    fontPrintf(
        rect->x0,//rect->x1 - width,
        rect->y0,
        FEC_ListItemStandard,
        "%s",buf);

    fontMakeCurrent(currentFont);
}
コード例 #6
0
ファイル: ShipView.c プロジェクト: rcarmo/homeworld
/*-----------------------------------------------------------------------------
    Name        : svManeuverRender
    Description : Callback which draws the maneuver stat in ship view.
    Inputs      : standard FE callback
    Outputs     : ..
    Return      : void
----------------------------------------------------------------------------*/
void svManeuverRender(featom *atom, regionhandle region)
{
    rectangle *rect = &region->rect;
    fonthandle currentFont;
    char maneuverability[100] = "";
    ShipStaticInfo *info = GetShipStaticInfoSafe(svShipType, universe.curPlayerPtr->race);

    svManeuverRegion = region;

    if (FELASTCALL(atom))
    {
        svManeuverRegion = NULL;
        return;
    }

    if (svShipType == DefaultShip)
    {
        return;
    }
    if (info == NULL)
    {
        info = GetShipStaticInfoSafe(svShipType, GetValidRaceForShipType(svShipType));
    }
    if (info == NULL)
    {
        return;
    }

    currentFont = fontMakeCurrent(svShipStatFont);

    if (RGLtype == SWtype) primRectSolid2(&region->rect, FEC_Background);

    svShipManeuverability(info,maneuverability);
    sprintf(buf,ShipStatToNiceStr(Maneuver),maneuverability);

    fontPrintf(
        rect->x0,
        rect->y0,
        FEC_ListItemStandard,
        "%s",buf);

    fontMakeCurrent(currentFont);
}
コード例 #7
0
ファイル: Carrier.c プロジェクト: rcarmo/homeworld
void CarrierHouseKeep(Ship *ship)
{
    CarrierSpec *spec = (CarrierSpec *)ship->ShipSpecifics;
    sdword i;

    for(i=0;i<MAX_NUM_DROP;i++)
    {
        if(spec->droptarget[i] != NULL)
        {
            if(DropTargetInShip(ship,&spec->dropstate[i],spec->droptarget[i],&spec->dockindex[i]))
            {
                spec->dropstate[i] = 0;
                spec->droptarget[i] = NULL;
            }
        }
    }

    for(i=0;i<spec->CAP_NumInBuildCue;)
    {
        spec->CAPTimeToBuildShip[i]-= universe.phystimeelapsed;
        if(spec->CAPTimeToBuildShip[i] < 0.0f)
        {
            Ship *newship;

            if (GetShipStaticInfoSafe(spec->CAPshiptype[i],spec->CAPshiprace[i]))
            {
                //time for a captured ship to pop out
                if ((multiPlayerGame) && (ship->playerowner->playerIndex==sigsPlayerIndex))
                {
                    shiplagtotals[spec->CAPshiptype[i]]++;
                }

                newship = clCreateShip(&universe.mainCommandLayer,
                        spec->CAPshiptype[i],
                        spec->CAPshiprace[i],
                        ship->playerowner->playerIndex,
                        ship);
                newship->colorScheme = spec->CAPcolorScheme[i];
            }

            spec->CAP_NumInBuildCue--;
            spec->CAPTimeToBuildShip[i] = spec->CAPTimeToBuildShip[spec->CAP_NumInBuildCue];
            spec->CAPshiptype[i] = spec->CAPshiptype[spec->CAP_NumInBuildCue];
            spec->CAPshiprace[i] = spec->CAPshiprace[spec->CAP_NumInBuildCue];
            spec->CAPcolorScheme[i] = spec->CAPcolorScheme[spec->CAP_NumInBuildCue];
            continue;
        }
        i++;
    }

}
コード例 #8
0
/*-----------------------------------------------------------------------------
    Name        : svShipViewRender
    Description : Callback which draws the main ship view.
    Inputs      : standard FE callback
    Outputs     : ..
    Return      : void
----------------------------------------------------------------------------*/
void svShipViewRender(featom* atom, regionhandle region)
{
    rectangle drawRect;
    rectangle* rect;
    rectangle viewRect;
    fonthandle currentFont;
    GLint viewPort[4];
    GLint box[4];
    ShipStaticInfo* info;
    real32 scale;
    sdword width, height;
    sdword x, y;
    keyindex key;
    char* keystring;
    bool resetRender = FALSE;
    char    temp[100];

    // facilitates smooth transition between auto/manual rotation of ship
    static real32 angle_user_rotated_to       = 0.0f;
    static real32 declination_user_rotated_to = 0.0f;
    static real32 time_user_rotated_view      = 0.0f;
           real32 real_time_angle             = 0.0f;
    static real32 user_real_angle_offset      = 0.0f;
    
    rect = &region->rect;
    viewRect.x0 = 0;
    viewRect.y0 = 0;
    viewRect.x1 = MAIN_WindowWidth  - 1;
    viewRect.y1 = MAIN_WindowHeight - 1;
    info = NULL;

    if (svShipType != DefaultShip)
    {
        if (universe.curPlayerPtr)
        {
            info = GetShipStaticInfoSafe(svShipType, universe.curPlayerPtr->race);
        }
        if (info == NULL)
        {
            info = GetShipStaticInfoSafe(svShipType, GetValidRaceForShipType(svShipType));
        }
        if (info == NULL)
        {
            return;
        }
    }

    svShipViewRegion = region;

    if (!resetRender)
    {
        if (svMouseInside)
        {
            ferDrawFocusWindow(region, lw_focus);
        }
        else
        {
            ferDrawFocusWindow(region, lw_normal);
        }
    }

    soundEventUpdate();

    currentFont = fontMakeCurrent(svShipViewFont);

    if (region->flags == 0 || region->flags == RPE_DrawFunctionAdded)
    {                                         //if region not processed yet
        region->flags =
            RPE_Enter | RPE_Exit |
            RPE_WheelDown | RPE_WheelUp |
            RPE_PressLeft | RPE_ReleaseLeft |
            RPE_PressRight | RPE_ReleaseRight;

        regFunctionSet(region, (regionfunction) svReadMouseEvent);               //set new region handler function
    }

    //scale = *svScale[svShipType];
        //svCamera.closestZoom  = *svMinZoom[svShipType];
    //svCamera.farthestZoom = *svMaxZoom[svShipType];

    scale = 1.0f; //*svScale[svShipType];

    if(svShipType != DefaultShip)
    {
        svCamera.closestZoom = info->minimumZoomDistance*svZoomInScalar;
        svCamera.farthestZoom = (svCamera.closestZoom+info->staticheader.staticCollInfo.approxcollspheresize)*svZoomOutScalar;
        if(ReZoom)
        {
            ReZoom=FALSE;
            cameraZoom(&svCamera,1.0f,FALSE);
        }

        if (svMouseInside && (wheel_down || wheel_up))
        {
            cameraControl(&svCamera, FALSE);
        }
        else if (svMouseInside && svMousePressRight)
        {
            camMouseX = (svMouseCentreX - mouseCursorX()) * 4;      //was 2
            camMouseY = (svMouseCentreY - mouseCursorY()) * 4;
            savecamMouseX = savecamMouseX * SPIN_FEEDBACK +
                (real32)camMouseX * (1.0f - SPIN_FEEDBACK);
            cameraControl(&svCamera, FALSE);                         //update the camera

            mouseCursorHide();
            mousePositionSet(svMouseCentreX, svMouseCentreY); // Reset position so it doesn't walk off region

            // keep track of where the user left the camera so we can sync auto-rotation with it
            angle_user_rotated_to       = svCamera.angle;
            declination_user_rotated_to = svCamera.declination;
            time_user_rotated_view      = universe.totaltimeelapsed;
        }
        else // auto rotate ship model
        {
            // continual 360 degree yaw rotation
            real_time_angle = DEG_TO_RAD(remainder(universe.totaltimeelapsed, SV_360_ROTATION_SECS) / SV_360_ROTATION_SECS * 360);

            if (angle_user_rotated_to >= 0.0) {
                user_real_angle_offset = angle_user_rotated_to - real_time_angle;
                angle_user_rotated_to = -1.0;
            }

            svCamera.angle = real_time_angle + user_real_angle_offset;
            
            // collapse pitch to default declination
            if (time_user_rotated_view > 0.0) {
                if (universe.totaltimeelapsed > time_user_rotated_view + SV_PITCH_FLATTEN_SECS) {
                    svCamera.declination = DEG_TO_RAD(svDeclination);
                    time_user_rotated_view = 0.0;
                }
                else {
                    svCamera.declination = declination_user_rotated_to + (DEG_TO_RAD(svDeclination) - declination_user_rotated_to) * ((universe.totaltimeelapsed - time_user_rotated_view) / SV_PITCH_FLATTEN_SECS);
                }
            }
            
            if (svMouseInside) mouseCursorShow();
        }
    }
    //rotation

    drawRect.x0 = rect->x0 + SV_ViewMargin;
    drawRect.y0 = rect->y0 + SV_ViewMargin;
    drawRect.x1 = rect->x1 - SV_ViewMargin;
    drawRect.y1 = rect->y1 - SV_ViewMargin;

    width  = drawRect.x1 - drawRect.x0;
    height = drawRect.y1 - drawRect.y0;

    glGetIntegerv(GL_VIEWPORT, viewPort);
    glViewport(drawRect.x0, MAIN_WindowHeight - drawRect.y1, width, height);

    primModeSet2();
    if (!resetRender)
    {
        primRectSolid2(&viewRect, FEC_Background);
    }
    primModeClear2();

    glEnable(GL_SCISSOR_TEST);
    glGetIntegerv(GL_SCISSOR_BOX, box);
    glScissor(drawRect.x0, MAIN_WindowHeight - drawRect.y1, width, height);
    glClear(GL_DEPTH_BUFFER_BIT);
    glDisable(GL_SCISSOR_TEST);

    rndPerspectiveCorrection(TRUE);

    //svCamera.lookatpoint.x = -info->staticheader.staticCollInfo.collsphereoffset.z * scale;
    //svCamera.lookatpoint.y = -info->staticheader.staticCollInfo.collsphereoffset.x * scale;
    //svCamera.lookatpoint.z = -info->staticheader.staticCollInfo.collsphereoffset.y * scale;
    if (svShipType == DefaultShip)
    {
        svCamera.lookatpoint.x=0.0f;
        svCamera.lookatpoint.y=0.0f;
        svCamera.lookatpoint.z=0.0f;
    }
    else
    {
        svCamera.lookatpoint.x = -info->staticheader.staticCollInfo.collsphereoffset.z;
        svCamera.lookatpoint.y = -info->staticheader.staticCollInfo.collsphereoffset.x;
        svCamera.lookatpoint.z = -info->staticheader.staticCollInfo.collsphereoffset.y;
    }

    cameraSetEyePosition(&svCamera);

    rndLightingEnable(TRUE);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    rgluPerspective(
        svCamera.fieldofview,
        (float)(width) / (float)(height) /*rndAspectRatio*/,    //set projection matrix
        svCamera.clipPlaneNear,
        svCamera.clipPlaneFar);

    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();

    rgluLookAt(
        svCamera.eyeposition.x,
        svCamera.eyeposition.y,
        svCamera.eyeposition.z,
        svCamera.lookatpoint.x,
        svCamera.lookatpoint.y,
        svCamera.lookatpoint.z,
        svCamera.upvector.x,
        svCamera.upvector.y,
        svCamera.upvector.z);

    glPushMatrix();

    glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);

    glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *)(&rndCameraMatrix));
    glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat *)(&rndProjectionMatrix));

    glEnable(GL_NORMALIZE);

    glLightfv(GL_LIGHT0, GL_POSITION, lightPosition0);      //position light(s) within world

    glScalef(scale, scale, scale);

    if (svShipType != DefaultShip)
    {
        sdword index;
        //try player index colours first
        index = universe.curPlayerIndex;
        if (info->teamColor[index] == 0)
        {
            //colour scheme doesn't exist, search for something valid
            for (index = 0; index < MAX_MULTIPLAYER_PLAYERS; index++)
            {
                if (info->teamColor[index] != 0)
                {
                    break;
                }
            }
            if (index == MAX_MULTIPLAYER_PLAYERS)
            {
                //this ship doesn't have any colour info,
                //at least avoid a GPF
                index = universe.curPlayerIndex;
            }
        }
        meshRender((meshdata *)info->staticheader.LOD->level[0].pData, index);
    }

    glDisable(GL_NORMALIZE);

    glPopMatrix();

    primModeSet2();

    glScissor(box[0], box[1], box[2], box[3]);
    glViewport(viewPort[0], viewPort[1], viewPort[2], viewPort[3]);

    rndLightingEnable(FALSE);
    rndPerspectiveCorrection(FALSE);

    x = rect->x0 + 2 + SV_ViewMargin;
    y = rect->y0 + 2 + SV_ViewMargin;

    if (svShipType != DefaultShip && !resetRender)
    {
        fontPrintf(
            x,
            y,
            FEC_ListItemStandard,
            "%s",
            ShipTypeToNiceStr(svShipType));

        y += fontHeight(" ");

        sprintf(temp, "%s %d %s",strGetString(strSVCost),info->buildCost, strGetString(strSVRUs));

        fontPrintf(
            x,
            y,
            FEC_ListItemStandard,
            temp);

        if (cmPrintHotKey)
        {
            x = rect->x1 - 2 - SV_ViewMargin;
            y = rect->y0 + 2 + SV_ViewMargin;

            key = cmShipTypeToKey(svShipType);
            keystring = opKeyToNiceString((keyindex)(key & 0x00ff));

            if (key & CM_SHIFT)
            {
                width = fontWidthf("[SHIFT-%s]",keystring);
                fontPrintf(
                    x-width,
                    y,
                    FEC_ListItemStandard,
                    "[SHIFT-%s]",
                    keystring);
            }
            else if (key)
            {
                width = fontWidthf("[%s]",keystring);
                fontPrintf(
                    x-width,
                    y,
                    FEC_ListItemStandard,
                    "[%s]",
                    keystring);
            }
        }
    }
    fontMakeCurrent(currentFont);

    svDirtyShipView();
}