MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), canvasWidget(new CanvasWidget(this)), gameIsPaused(true), thereIsAnotherDialog(false) { Item::setCanvas(canvasWidget); new Background; // the background put's itself into the canvasWidget gameEngine = new GameEngine(this); // must be called after Item::setCanvas() #if defined ANDROID setAttribute(Qt::WA_AcceptTouchEvents); #endif connect(canvasWidget, SIGNAL(mouseMoved(int)), gameEngine, SLOT(moveBar(int))); connect(canvasWidget, SIGNAL(barMovedLeft()), gameEngine, SLOT(moveBarLeft())); connect(canvasWidget, SIGNAL(barMovedRight()), gameEngine, SLOT(moveBarRight())); connect(canvasWidget, SIGNAL(focusLost()), this, SLOT(pauseGame())); connect(gameEngine, SIGNAL(gamePaused()), canvasWidget, SLOT(handleGamePaused())); connect(gameEngine, SIGNAL(gameResumed()), canvasWidget, SLOT(handleGameResumed())); connect(gameEngine, SIGNAL(gameResumed()), this, SLOT(handleGameResumed())); connect(gameEngine, SIGNAL(resetMousePosition()), canvasWidget, SLOT(handleResetMousePosition())); connect(gameEngine, SIGNAL(gameEnded(int,int,int)), SLOT(handleEndedGame(int,int,int))); // cheating keys, debugging and testing only TODO: REMOVE connect(canvasWidget, SIGNAL(cheatSkipLevel()), gameEngine, SLOT(cheatSkipLevel())); connect(canvasWidget, SIGNAL(cheatAddLife()), gameEngine, SLOT(cheatAddLife())); connect(gameEngine, SIGNAL(levelChanged()), this, SLOT(handleLevelChanged())); connect(Settings::self(), SIGNAL(themeChanged()), canvasWidget, SLOT(reloadSprites())); setCentralWidget(canvasWidget); setupActions(); setFocusProxy(canvasWidget); QSize defaultSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // show here (instead of in main) else the mouse can't be grabbed show(); gameEngine->start(Settings::self()->getLevelset()); }
void GameWidget::pause() { if(!m_paused) { this->setCursor(Qt::ArrowCursor); m_paused=true; emit gamePaused(m_scene->time()); } }
void GameEngine::pause() { if (gameIsPaused()) { return; } m_elapsedTimeTimer.stop(); m_gameTimer.stop(); emit gamePaused(); //showMessage("Game Paused!"); PORT - FOR NOW }
/* Move the particles */ void atmosUpdateSystem( void ) { UDWORD i; UDWORD numberToAdd; Vector3i pos; // we don't want to do any of this while paused. if(!gamePaused() && weather!=WT_NONE) { for(i = 0; i < MAX_ATMOS_PARTICLES; i++) { /* See if it's active */ if(asAtmosParts[i].status == APS_ACTIVE) { processParticle(&asAtmosParts[i]); } } /* This bit below needs to go into a "precipitation function" */ numberToAdd = ((weather==WT_SNOWING) ? 2 : 4); /* Temporary stuff - just adds a few particles! */ for(i=0; i<numberToAdd; i++) { pos.x = player.p.x + ((visibleTiles.x/2)*TILE_UNITS); pos.z = player.p.z + ((visibleTiles.y/2)*TILE_UNITS); pos.x += (((visibleTiles.x/2) - rand()%visibleTiles.x) * TILE_UNITS); pos.z += (((visibleTiles.x/2) - rand()%visibleTiles.x) * TILE_UNITS); pos.y = 1000; /* If we've got one on the grid */ if(pos.x>0 && pos.z>0 && pos.x<(SDWORD)((mapWidth-1)*TILE_UNITS) && pos.z<(SDWORD)((mapHeight-1)*TILE_UNITS) ) { /* On grid, so which particle shall we add? */ switch(weather) { case WT_SNOWING: atmosAddParticle(&pos,AP_SNOW); break; case WT_RAINING: atmosAddParticle(&pos,AP_RAIN); break; case WT_NONE: break; default: break; } } } } }
void GameEngine::pause() { if (gameIsPaused()) { return; } if (m_gameWon || m_gameOver) { return; } m_elapsedTimeTimer.stop(); m_gameTimer.stop(); emit gamePaused(); showMessage(i18n("Game Paused!")); }
static void ProcessOptionFinished(void) { intMode = INT_NORMAL; //unpause. if(gamePaused()) { kf_TogglePauseMode(); } }
static GAMECODE renderLoop() { if (bMultiPlayer && !NetPlay.isHostAlive && NetPlay.bComms && !NetPlay.isHost) { intAddInGamePopup(); } int clearMode = 0; if(getDrawShadows()) { clearMode |= CLEAR_SHADOW; } if (loopMissionState == LMS_SAVECONTINUE) { pie_SetFogStatus(false); clearMode = CLEAR_BLACK; } pie_ScreenFlip(clearMode);//gameloopflip HandleClosingWindows(); // Needs to be done outside the pause case. audio_Update(); wzShowMouse(true); INT_RETVAL intRetVal = INT_NONE; if (!paused) { /* Run the in game interface and see if it grabbed any mouse clicks */ if (!rotActive && getWidgetsStatus() && dragBox3D.status != DRAG_DRAGGING && wallDrag.status != DRAG_DRAGGING) { intRetVal = intRunWidgets(); } //don't process the object lists if paused or about to quit to the front end if (!gameUpdatePaused() && intRetVal != INT_QUIT) { if( dragBox3D.status != DRAG_DRAGGING && wallDrag.status != DRAG_DRAGGING && ( intRetVal == INT_INTERCEPT || ( radarOnScreen && CoordInRadar(mouseX(), mouseY()) && getHQExists(selectedPlayer) ) ) ) { // Using software cursors (when on) for these menus due to a bug in SDL's SDL_ShowCursor() wzSetCursor(CURSOR_DEFAULT); intRetVal = INT_INTERCEPT; } #ifdef DEBUG // check all flag positions for duplicate delivery points checkFactoryFlags(); #endif //handles callbacks for positioning of DP's process3DBuilding(); //ajl. get the incoming netgame messages and process them. // FIXME Previous comment is deprecated. multiPlayerLoop does some other weird stuff, but not that anymore. if (bMultiPlayer) { multiPlayerLoop(); } for (unsigned i = 0; i < MAX_PLAYERS; i++) { for (DROID *psCurr = apsDroidLists[i]; psCurr; psCurr = psCurr->psNext) { // Don't copy the next pointer - if droids somehow get destroyed in the graphics rendering loop, who cares if we crash. calcDroidIllumination(psCurr); } } /* update animations */ animObj_Update(); } if (!consolePaused()) { /* Process all the console messages */ updateConsoleMessages(); } if (!scrollPaused() && !getWarCamStatus() && dragBox3D.status != DRAG_DRAGGING && intMode != INT_INGAMEOP ) { scroll(); } } else // paused { // Using software cursors (when on) for these menus due to a bug in SDL's SDL_ShowCursor() wzSetCursor(CURSOR_DEFAULT); if(dragBox3D.status != DRAG_DRAGGING) { scroll(); } if(InGameOpUp || isInGamePopupUp) // ingame options menu up, run it! { unsigned widgval = widgRunScreen(psWScreen); intProcessInGameOptions(widgval); if(widgval == INTINGAMEOP_QUIT_CONFIRM || widgval == INTINGAMEOP_POPUP_QUIT) { if(gamePaused()) { kf_TogglePauseMode(); } intRetVal = INT_QUIT; } } if(bLoadSaveUp && runLoadSave(true) && strlen(sRequestResult)) { debug( LOG_NEVER, "Returned %s", sRequestResult ); if(bRequestLoad) { loopMissionState = LMS_LOADGAME; NET_InitPlayers(); // otherwise alliances were not cleared sstrcpy(saveGameName, sRequestResult); } else { char msgbuffer[256]= {'\0'}; if (saveInMissionRes()) { if (saveGame(sRequestResult, GTYPE_SAVE_START)) { sstrcpy(msgbuffer, _("GAME SAVED: ")); sstrcat(msgbuffer, sRequestResult); addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE); } else { ASSERT( false,"Mission Results: saveGame Failed" ); sstrcpy(msgbuffer, _("Could not save game!")); addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE); deleteSaveGame(sRequestResult); } } else if (bMultiPlayer || saveMidMission()) { if (saveGame(sRequestResult, GTYPE_SAVE_MIDMISSION))//mid mission from [esc] menu { sstrcpy(msgbuffer, _("GAME SAVED: ")); sstrcat(msgbuffer, sRequestResult); addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE); } else { ASSERT(!"saveGame(sRequestResult, GTYPE_SAVE_MIDMISSION) failed", "Mid Mission: saveGame Failed" ); sstrcpy(msgbuffer, _("Could not save game!")); addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE); deleteSaveGame(sRequestResult); } } else { ASSERT( false, "Attempt to save game with incorrect load/save mode" ); } } } } /* Check for quit */ bool quitting = false; if (intRetVal == INT_QUIT) { if (!loop_GetVideoStatus()) { //quitting from the game to the front end //so get a new backdrop quitting = true; pie_LoadBackDrop(SCREEN_RANDOMBDROP); } } if (!loop_GetVideoStatus() && !quitting) { if (!gameUpdatePaused()) { if (dragBox3D.status != DRAG_DRAGGING && wallDrag.status != DRAG_DRAGGING) { ProcessRadarInput(); } processInput(); //no key clicks or in Intelligence Screen if (intRetVal == INT_NONE && !InGameOpUp && !isInGamePopupUp) { processMouseClickInput(); } displayWorld(); } /* Display the in game interface */ pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON); pie_SetFogStatus(false); if(bMultiPlayer && bDisplayMultiJoiningStatus) { intDisplayMultiJoiningStatus(bDisplayMultiJoiningStatus); setWidgetsStatus(false); } if(getWidgetsStatus()) { intDisplayWidgets(); } pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON); pie_SetFogStatus(true); } pie_GetResetCounts(&loopPieCount, &loopPolyCount, &loopStateChanges); if ((fogStatus & FOG_BACKGROUND) && (loopMissionState == LMS_SAVECONTINUE)) { pie_SetFogStatus(false); } if (!quitting) { /* Check for toggling display mode */ if ((keyDown(KEY_LALT) || keyDown(KEY_RALT)) && keyPressed(KEY_RETURN)) { screenToggleMode(); } } // deal with the mission state switch (loopMissionState) { case LMS_CLEAROBJECTS: missionDestroyObjects(); setScriptPause(true); loopMissionState = LMS_SETUPMISSION; break; case LMS_NORMAL: // default break; case LMS_SETUPMISSION: setScriptPause(false); if (!setUpMission(nextMissionType)) { return GAMECODE_QUITGAME; } break; case LMS_SAVECONTINUE: // just wait for this to be changed when the new mission starts break; case LMS_NEWLEVEL: //nextMissionType = MISSION_NONE; nextMissionType = LDS_NONE; return GAMECODE_NEWLEVEL; break; case LMS_LOADGAME: return GAMECODE_LOADGAME; break; default: ASSERT( false, "unknown loopMissionState" ); break; } if (quitting) { pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK);//gameloopflip /* Check for toggling display mode */ if ((keyDown(KEY_LALT) || keyDown(KEY_RALT)) && keyPressed(KEY_RETURN)) { screenToggleMode(); } return GAMECODE_QUITGAME; } else if (loop_GetVideoStatus()) { audio_StopAll(); return GAMECODE_PLAYVIDEO; } return GAMECODE_CONTINUE; }
// // Quick hack to throw up a ingame 'popup' for when the host drops connection. // void intAddInGamePopup(void) { //clear out any mission widgets - timers etc that may be on the screen clearMissionWidgets(); setWidgetsStatus(true); intResetScreen(false); if (isInGamePopupUp) return; audio_StopAll(); if(!gamePaused()) { kf_TogglePauseMode(); // Pause the game. } W_FORMINIT sFormInit; sFormInit.formID = 0; sFormInit.id = INTINGAMEPOPUP; sFormInit.style = WFORM_PLAIN; sFormInit.width = 600; sFormInit.height = 160; sFormInit.x = (SWORD)(20+D_W); sFormInit.y = (SWORD)((240-(160/2))+D_H); sFormInit.pDisplay = intOpenPlainForm; sFormInit.disableChildren= true; widgAddForm(psWScreen, &sFormInit); // add the text "buttons" now W_BUTINIT sButInit; sButInit.formID = INTINGAMEPOPUP; sButInit.style = OPALIGN; sButInit.width = 600; sButInit.FontID = font_large; sButInit.x = 0; sButInit.height = 10; sButInit.pDisplay = displayTextOption; sButInit.id = INTINGAMEOP_POPUP_MSG2; sButInit.y = 20; sButInit.pText = _("Host has quit the game!"); widgAddButton(psWScreen, &sButInit); sButInit.id = INTINGAMEOP_POPUP_MSG1; sButInit.y = 60; sButInit.pText = _("The game can't continue without the host."); widgAddButton(psWScreen, &sButInit); sButInit.id = INTINGAMEOP_POPUP_QUIT; sButInit.y = 124; sButInit.pText = _("--> QUIT <--"); widgAddButton(psWScreen, &sButInit); intMode = INT_POPUPMSG; // change interface mode. isInGamePopupUp = true; }
static bool _intAddInGameOptions(void) { audio_StopAll(); //clear out any mission widgets - timers etc that may be on the screen clearMissionWidgets(); setWidgetsStatus(true); //if already open, then close! if (widgGetFromID(psWScreen,INTINGAMEOP)) { intCloseInGameOptions(false, true); return true; } intResetScreen(false); // Pause the game. if(!gamePaused()) { kf_TogglePauseMode(); } W_FORMINIT sFormInit; sFormInit.width = INTINGAMEOP_W; // add form sFormInit.formID = 0; sFormInit.id = INTINGAMEOP; sFormInit.style = WFORM_PLAIN; sFormInit.x = (SWORD)INTINGAMEOP_X; sFormInit.y = (SWORD)INTINGAMEOP_Y; sFormInit.height = INTINGAMEOP_H; if ((!bMultiPlayer || (NetPlay.bComms == 0)) && !bInTutorial) { } else { sFormInit.height = INTINGAMEOP_HS; } sFormInit.pDisplay = intOpenPlainForm; sFormInit.disableChildren= true; widgAddForm(psWScreen, &sFormInit); // add 'quit' text if ((!bMultiPlayer || (NetPlay.bComms == 0)) && !bInTutorial) { addIGTextButton(INTINGAMEOP_QUIT, INTINGAMEOP_5_Y, INTINGAMEOP_OP_W, _("Quit"), OPALIGN); } else { addIGTextButton(INTINGAMEOP_QUIT, INTINGAMEOP_3_Y, INTINGAMEOP_OP_W, _("Quit"), OPALIGN); } // add 'resume' addIGTextButton(INTINGAMEOP_RESUME, INTINGAMEOP_1_Y, INTINGAMEOP_OP_W, _("Resume Game"), OPALIGN); // add 'options' addIGTextButton(INTINGAMEOP_OPTIONS, INTINGAMEOP_2_Y, INTINGAMEOP_OP_W, _("Audio Options"), OPALIGN); if ((!bMultiPlayer || (NetPlay.bComms == 0)) && !bInTutorial) { // add 'load' addIGTextButton(INTINGAMEOP_LOAD, INTINGAMEOP_3_Y, INTINGAMEOP_OP_W, _("Load Game"), OPALIGN); // add 'save' addIGTextButton(INTINGAMEOP_SAVE, INTINGAMEOP_4_Y, INTINGAMEOP_OP_W, _("Save Game"), OPALIGN); } intMode = INT_INGAMEOP; // change interface mode. InGameOpUp = true; // inform interface. wzSetCursor(CURSOR_DEFAULT); return true; }
// this is able to handle multiple weapon graphics now // removed mountRotation,they get such stuff from psObj directly now static bool displayCompObj(DROID *psDroid, bool bButton, const glm::mat4 &viewMatrix) { iIMDShape *psMoveAnim, *psStillAnim; SDWORD iConnector; PROPULSION_STATS *psPropStats; SDWORD pieFlag, iPieData; PIELIGHT brightness; UDWORD colour; UBYTE i; bool didDrawSomething = false; glm::mat4 modelMatrix(1.f); if (graphicsTime - psDroid->timeLastHit < GAME_TICKS_PER_SEC / 4 && psDroid->lastHitWeapon == WSC_ELECTRONIC && !gamePaused()) { colour = getPlayerColour(rand() % MAX_PLAYERS); } else { colour = getPlayerColour(psDroid->player); } /* get propulsion stats */ psPropStats = asPropulsionStats + psDroid->asBits[COMP_PROPULSION]; ASSERT_OR_RETURN(didDrawSomething, psPropStats != nullptr, "invalid propulsion stats pointer"); //set pieflag for button object or ingame object if (bButton) { pieFlag = pie_BUTTON; brightness = WZCOL_WHITE; } else { pieFlag = pie_SHADOW; brightness = pal_SetBrightness(psDroid->illumination); // NOTE: Beware of transporters that are offscreen, on a mission! We should *not* be checking tiles at this point in time! if (!isTransporter(psDroid) && !missionIsOffworld()) { MAPTILE *psTile = worldTile(psDroid->pos.x, psDroid->pos.y); if (psTile->jammerBits & alliancebits[psDroid->player]) { pieFlag |= pie_ECM; } } } /* set default components transparent */ if (psDroid->asBits[COMP_PROPULSION] == 0) { pieFlag |= pie_TRANSLUCENT; iPieData = DEFAULT_COMPONENT_TRANSLUCENCY; } else { iPieData = 0; } if (!bButton && psPropStats->propulsionType == PROPULSION_TYPE_PROPELLOR) { // FIXME: change when adding submarines to the game modelMatrix *= glm::translate(glm::vec3(0.f, -world_coord(1) / 2.3f, 0.f)); } iIMDShape *psShapeProp = (leftFirst ? getLeftPropulsionIMD(psDroid) : getRightPropulsionIMD(psDroid)); if (psShapeProp) { if (pie_Draw3DShape(psShapeProp, 0, colour, brightness, pieFlag, iPieData, viewMatrix * modelMatrix)) { didDrawSomething = true; } } /* set default components transparent */ if (psDroid->asBits[COMP_BODY] == 0) { pieFlag |= pie_TRANSLUCENT; iPieData = DEFAULT_COMPONENT_TRANSLUCENCY; } else { pieFlag &= ~pie_TRANSLUCENT; iPieData = 0; } /* Get the body graphic now*/ iIMDShape *psShapeBody = BODY_IMD(psDroid, psDroid->player); if (psShapeBody) { iIMDShape *strImd = psShapeBody; if (psDroid->droidType == DROID_PERSON) { modelMatrix *= glm::scale(glm::vec3(.75f)); // FIXME - hideous....!!!! } if (strImd->objanimpie[psDroid->animationEvent]) { strImd = psShapeBody->objanimpie[psDroid->animationEvent]; } glm::mat4 viewModelMatrix = viewMatrix * modelMatrix; while (strImd) { if (drawShape(psDroid, strImd, colour, brightness, pieFlag, iPieData, viewModelMatrix)) { didDrawSomething = true; } strImd = strImd->next; } } /* Render animation effects based on movement or lack thereof, if any */ psMoveAnim = asBodyStats[psDroid->asBits[COMP_BODY]].ppMoveIMDList[psDroid->asBits[COMP_PROPULSION]]; psStillAnim = asBodyStats[psDroid->asBits[COMP_BODY]].ppStillIMDList[psDroid->asBits[COMP_PROPULSION]]; glm::mat4 viewModelMatrix = viewMatrix * modelMatrix; if (!bButton && psMoveAnim && psDroid->sMove.Status != MOVEINACTIVE) { if (pie_Draw3DShape(psMoveAnim, getModularScaledGraphicsTime(psMoveAnim->animInterval, psMoveAnim->numFrames), colour, brightness, pie_ADDITIVE, 200, viewModelMatrix)) { didDrawSomething = true; } } else if (!bButton && psStillAnim) // standing still { if (pie_Draw3DShape(psStillAnim, getModularScaledGraphicsTime(psStillAnim->animInterval, psStillAnim->numFrames), colour, brightness, 0, 0, viewModelMatrix)) { didDrawSomething = true; } } //don't change the screen coords of an object if drawing it in a button if (!bButton) { /* set up all the screen coords stuff - need to REMOVE FROM THIS LOOP */ calcScreenCoords(psDroid, viewModelMatrix); } /* set default components transparent */ if (psDroid->asWeaps[0].nStat == 0 && psDroid->asBits[COMP_SENSOR] == 0 && psDroid->asBits[COMP_ECM] == 0 && psDroid->asBits[COMP_BRAIN] == 0 && psDroid->asBits[COMP_REPAIRUNIT] == 0 && psDroid->asBits[COMP_CONSTRUCT] == 0) { pieFlag |= pie_TRANSLUCENT; iPieData = DEFAULT_COMPONENT_TRANSLUCENCY; } else { pieFlag &= ~pie_TRANSLUCENT; iPieData = 0; } if (psShapeBody && psShapeBody->nconnectors) { /* vtol weapons attach to connector 2 (underneath); * all others to connector 1 */ /* VTOL's now skip the first 5 connectors(0 to 4), VTOL's use 5,6,7,8 etc now */ if (psPropStats->propulsionType == PROPULSION_TYPE_LIFT && psDroid->droidType == DROID_WEAPON) { iConnector = VTOL_CONNECTOR_START; } else { iConnector = 0; } switch (psDroid->droidType) { case DROID_DEFAULT: case DROID_TRANSPORTER: case DROID_SUPERTRANSPORTER: case DROID_CYBORG: case DROID_CYBORG_SUPER: case DROID_WEAPON: case DROID_COMMAND: // command droids have a weapon to store all the graphics /* Get the mounting graphic - we've already moved to the right position Allegedly - all droids will have a mount graphic so this shouldn't fall on it's arse......*/ /* Double check that the weapon droid actually has any */ for (i = 0; i < psDroid->numWeaps; i++) { if ((psDroid->asWeaps[i].nStat > 0 || psDroid->droidType == DROID_DEFAULT) && psShapeBody->connectors) { Rotation rot = getInterpolatedWeaponRotation(psDroid, i, graphicsTime); glm::mat4 localModelMatrix = modelMatrix; //to skip number of VTOL_CONNECTOR_START ground unit connectors if (iConnector < VTOL_CONNECTOR_START) { localModelMatrix *= glm::translate(glm::vec3(psShapeBody->connectors[i].xzy())); } else { localModelMatrix *= glm::translate(glm::vec3(psShapeBody->connectors[iConnector + i].xzy())); } localModelMatrix *= glm::rotate(UNDEG(-rot.direction), glm::vec3(0.f, 1.f, 0.f)); /* vtol weapons inverted */ if (iConnector >= VTOL_CONNECTOR_START) { //this might affect gun rotation localModelMatrix *= glm::rotate(UNDEG(65536 / 2), glm::vec3(0.f, 0.f, 1.f)); } /* Get the mount graphic */ iIMDShape *psShape = WEAPON_MOUNT_IMD(psDroid, i); int recoilValue = getRecoil(psDroid->asWeaps[i]); localModelMatrix *= glm::translate(glm::vec3(0.f, 0.f, recoilValue / 3.f)); /* Draw it */ if (psShape) { if (pie_Draw3DShape(psShape, 0, colour, brightness, pieFlag, iPieData, viewMatrix * localModelMatrix)) { didDrawSomething = true; } } localModelMatrix *= glm::translate(glm::vec3(0, 0, recoilValue)); /* translate for weapon mount point */ if (psShape && psShape->nconnectors) { localModelMatrix *= glm::translate(glm::vec3(psShape->connectors->xzy())); } /* vtol weapons inverted */ if (iConnector >= VTOL_CONNECTOR_START) { //pitch the barrel down localModelMatrix *= glm::rotate(UNDEG(-rot.pitch), glm::vec3(1.f, 0.f, 0.f)); } else { //pitch the barrel up localModelMatrix *= glm::rotate(UNDEG(rot.pitch), glm::vec3(1.f, 0.f, 0.f)); } /* Get the weapon (gun?) graphic */ psShape = WEAPON_IMD(psDroid, i); // We have a weapon so we draw it and a muzzle flash from weapon connector if (psShape) { glm::mat4 localViewModelMatrix = viewMatrix * localModelMatrix; if (pie_Draw3DShape(psShape, 0, colour, brightness, pieFlag, iPieData, localViewModelMatrix)) { didDrawSomething = true; } drawMuzzleFlash(psDroid->asWeaps[i], psShape, MUZZLE_FLASH_PIE(psDroid, i), brightness, pieFlag, iPieData, localViewModelMatrix); } } } break; case DROID_SENSOR: case DROID_CONSTRUCT: case DROID_CYBORG_CONSTRUCT: case DROID_ECM: case DROID_REPAIR: case DROID_CYBORG_REPAIR: { Rotation rot = getInterpolatedWeaponRotation(psDroid, 0, graphicsTime); iIMDShape *psShape = nullptr; iIMDShape *psMountShape = nullptr; switch (psDroid->droidType) { default: ASSERT(false, "Bad component type"); break; case DROID_SENSOR: psMountShape = SENSOR_MOUNT_IMD(psDroid, psDroid->player); /* Get the sensor graphic, assuming it's there */ psShape = SENSOR_IMD(psDroid, psDroid->player); break; case DROID_CONSTRUCT: case DROID_CYBORG_CONSTRUCT: psMountShape = CONSTRUCT_MOUNT_IMD(psDroid, psDroid->player); /* Get the construct graphic assuming it's there */ psShape = CONSTRUCT_IMD(psDroid, psDroid->player); break; case DROID_ECM: psMountShape = ECM_MOUNT_IMD(psDroid, psDroid->player); /* Get the ECM graphic assuming it's there.... */ psShape = ECM_IMD(psDroid, psDroid->player); break; case DROID_REPAIR: case DROID_CYBORG_REPAIR: psMountShape = REPAIR_MOUNT_IMD(psDroid, psDroid->player); /* Get the Repair graphic assuming it's there.... */ psShape = REPAIR_IMD(psDroid, psDroid->player); break; } /* Get the mounting graphic - we've already moved to the right position Allegedly - all droids will have a mount graphic so this shouldn't fall on it's arse......*/ //sensor and cyborg and ecm uses connectors[0] glm::mat4 localModelMatrix = modelMatrix; /* vtol weapons inverted */ if (iConnector >= VTOL_CONNECTOR_START) { //this might affect gun rotation localModelMatrix *= glm::rotate(UNDEG(65536 / 2), glm::vec3(0.f, 0.f, 1.f)); } localModelMatrix *= glm::translate(glm::vec3(psShapeBody->connectors[0].xzy())); localModelMatrix *= glm::rotate(UNDEG(-rot.direction), glm::vec3(0.f, 1.f, 0.f)); /* Draw it */ if (psMountShape) { if (pie_Draw3DShape(psMountShape, 0, colour, brightness, pieFlag, iPieData, viewMatrix * localModelMatrix)) { didDrawSomething = true; } } /* translate for construct mount point if cyborg */ if (cyborgDroid(psDroid) && psMountShape && psMountShape->nconnectors) { localModelMatrix *= glm::translate(glm::vec3(psMountShape->connectors[0].xzy())); } /* Draw it */ if (psShape) { if (pie_Draw3DShape(psShape, 0, colour, brightness, pieFlag, iPieData, viewMatrix * localModelMatrix)) { didDrawSomething = true; } // In repair droid case only: if ((psDroid->droidType == DROID_REPAIR || psDroid->droidType == DROID_CYBORG_REPAIR) && psShape->nconnectors && psDroid->action == DACTION_DROIDREPAIR) { Spacetime st = interpolateObjectSpacetime(psDroid, graphicsTime); localModelMatrix *= glm::translate(glm::vec3(psShape->connectors[0].xzy())); localModelMatrix *= glm::translate(glm::vec3(0.f, -20.f, 0.f)); psShape = getImdFromIndex(MI_FLAME); /* Rotate for droid */ localModelMatrix *= glm::rotate(UNDEG(st.rot.direction), glm::vec3(0.f, 1.f, 0.f)); localModelMatrix *= glm::rotate(UNDEG(-st.rot.pitch), glm::vec3(1.f, 0.f, 0.f)); localModelMatrix *= glm::rotate(UNDEG(-st.rot.roll), glm::vec3(0.f, 0.f, 1.f)); //rotate Y localModelMatrix *= glm::rotate(UNDEG(rot.direction), glm::vec3(0.f, 1.f, 0.f)); localModelMatrix *= glm::rotate(UNDEG(-player.r.y), glm::vec3(0.f, 1.f, 0.f)); localModelMatrix *= glm::rotate(UNDEG(-player.r.x), glm::vec3(1.f, 0.f, 0.f)); if (pie_Draw3DShape(psShape, getModularScaledGraphicsTime(psShape->animInterval, psShape->numFrames), 0, brightness, pie_ADDITIVE, 140, viewMatrix * localModelMatrix)) { didDrawSomething = true; } // localModelMatrix *= glm::rotate(UNDEG(player.r.x), glm::vec3(1.f, 0.f, 0.f)); // Not used? // localModelMatrix *= glm::rotate(UNDEG(player.r.y), glm::vec3(0.f, 1.f, 0.f)); // Not used? } } break; } case DROID_PERSON: // no extra mounts for people break; default: ASSERT(!"invalid droid type", "Whoa! Weirdy type of droid found in drawComponentObject!!!"); break; } } /* set default components transparent */ if (psDroid->asBits[COMP_PROPULSION] == 0) { pieFlag |= pie_TRANSLUCENT; iPieData = DEFAULT_COMPONENT_TRANSLUCENCY; } else { pieFlag &= ~pie_TRANSLUCENT; iPieData = 0; } // now render the other propulsion side psShapeProp = (leftFirst ? getRightPropulsionIMD(psDroid) : getLeftPropulsionIMD(psDroid)); if (psShapeProp) { if (pie_Draw3DShape(psShapeProp, 0, colour, brightness, pieFlag, iPieData, viewModelMatrix)) // Safe to use viewModelMatrix because modelView has not been changed since it was calculated { didDrawSomething = true; } } return didDrawSomething; }
/** * Draw the water. */ void drawWater(const glm::mat4 &viewMatrix) { int x, y; const glm::vec4 paramsX(0, 0, -1.0f / world_coord(4), 0); const glm::vec4 paramsY(1.0f / world_coord(4), 0, 0, 0); const glm::vec4 paramsX2(0, 0, -1.0f / world_coord(5), 0); const glm::vec4 paramsY2(1.0f / world_coord(5), 0, 0, 0); const auto &renderState = getCurrentRenderState(); const auto &program = pie_ActivateShader(SHADER_WATER, viewMatrix, paramsX, paramsY, paramsX2, paramsY2, 0, 1, glm::translate(glm::vec3(waterOffset, 0.f, 0.f)), glm::mat4(1.f), renderState.fogEnabled, renderState.fogBegin, renderState.fogEnd); glDepthMask(GL_FALSE); // first texture unit pie_SetTexturePage(iV_GetTexture("page-80-water-1.png")); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // multiplicative blending pie_SetRendMode(REND_MULTIPLICATIVE); // second texture unit glActiveTexture(GL_TEXTURE1); pie_Texture(iV_GetTexture("page-81-water-2.png")).bind(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // bind the vertex buffer waterIndexVBO->bind(); waterVBO->bind(); glVertexAttribPointer(program.locVertex, 3, GL_FLOAT, GL_FALSE, sizeof(RenderVertex), BUFFER_OFFSET(0)); glEnableVertexAttribArray(program.locVertex); for (x = 0; x < xSectors; x++) { for (y = 0; y < ySectors; y++) { if (sectors[x * ySectors + y].draw) { addDrawRangeElements(GL_TRIANGLES, sectors[x * ySectors + y].geometryOffset, sectors[x * ySectors + y].geometryOffset + sectors[x * ySectors + y].geometrySize, sectors[x * ySectors + y].waterIndexSize, GL_UNSIGNED_INT, sectors[x * ySectors + y].waterIndexOffset); } } } finishDrawRangeElements(); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glDisableVertexAttribArray(program.locVertex); // move the water if (!gamePaused()) { waterOffset += graphicsTimeAdjustedIncrement(0.1f); } // disable second texture glActiveTexture(GL_TEXTURE0); // clean up glDepthMask(GL_TRUE); pie_DeactivateShader(); //glBindBuffer(GL_ARRAY_BUFFER, 0); // HACK Must unbind GL_ARRAY_BUFFER (don't know if it has to be unbound everywhere), otherwise text rendering may mysteriously crash. }
/* Moves one of the particles */ static void processParticle(ATPART *psPart) { SDWORD groundHeight; Vector3i pos; UDWORD x, y; MAPTILE *psTile; /* Only move if the game isn't paused */ if (!gamePaused()) { /* Move the particle - frame rate controlled */ psPart->position.x += graphicsTimeAdjustedIncrement(psPart->velocity.x); psPart->position.y += graphicsTimeAdjustedIncrement(psPart->velocity.y); psPart->position.z += graphicsTimeAdjustedIncrement(psPart->velocity.z); /* Wrap it around if it's gone off grid... */ testParticleWrap(psPart); /* If it's gone off the WORLD... */ if (psPart->position.x < 0 || psPart->position.z < 0 || psPart->position.x > ((mapWidth - 1)*TILE_UNITS) || psPart->position.z > ((mapHeight - 1)*TILE_UNITS)) { /* The kill it */ psPart->status = APS_INACTIVE; return; } /* What height is the ground under it? Only do if low enough...*/ if (psPart->position.y < 255 * ELEVATION_SCALE) { /* Get ground height */ groundHeight = map_Height(psPart->position.x, psPart->position.z); /* Are we below ground? */ if ((int)psPart->position.y < groundHeight || psPart->position.y < 0.f) { /* Kill it and return */ psPart->status = APS_INACTIVE; if (psPart->type == AP_RAIN) { x = map_coord(psPart->position.x); y = map_coord(psPart->position.z); psTile = mapTile(x, y); if (terrainType(psTile) == TER_WATER && TEST_TILE_VISIBLE(selectedPlayer, psTile)) { pos.x = psPart->position.x; pos.z = psPart->position.z; pos.y = groundHeight; effectSetSize(60); addEffect(&pos, EFFECT_EXPLOSION, EXPLOSION_TYPE_SPECIFIED, true, getImdFromIndex(MI_SPLASH), 0); } } return; } } if (psPart->type == AP_SNOW) { if (rand() % 30 == 1) { psPart->velocity.z = (float)SNOW_SPEED_DRIFT; } if (rand() % 30 == 1) { psPart->velocity.x = (float)SNOW_SPEED_DRIFT; } } } }
// this is able to handle multiple weapon graphics now // removed mountRotation,they get such stuff from psObj directly now static void displayCompObj(DROID *psDroid, bool bButton) { iIMDShape *psShape, *psMoveAnim, *psStillAnim, *psShapeTemp = NULL, *psMountShape; SDWORD iConnector; PROPULSION_STATS *psPropStats; SDWORD pieFlag, iPieData; PIELIGHT brightness; UDWORD colour; UBYTE i; if (graphicsTime - psDroid->timeLastHit < GAME_TICKS_PER_SEC / 4 && psDroid->lastHitWeapon == WSC_ELECTRONIC && !gamePaused()) { colour = getPlayerColour(rand() % MAX_PLAYERS); } else { colour = getPlayerColour(psDroid->player); } /* get propulsion stats */ psPropStats = asPropulsionStats + psDroid->asBits[COMP_PROPULSION]; ASSERT_OR_RETURN(, psPropStats != NULL, "invalid propulsion stats pointer"); //set pieflag for button object or ingame object if (bButton) { pieFlag = pie_BUTTON; brightness = WZCOL_WHITE; } else { pieFlag = pie_SHADOW; brightness = pal_SetBrightness(psDroid->illumination); // NOTE: Beware of transporters that are offscreen, on a mission! We should *not* be checking tiles at this point in time! if (!isTransporter(psDroid) && !missionIsOffworld()) { MAPTILE *psTile = worldTile(psDroid->pos.x, psDroid->pos.y); if (psTile->jammerBits & alliancebits[psDroid->player]) { pieFlag |= pie_ECM; } } } /* set default components transparent */ if (psDroid->asBits[COMP_PROPULSION] == 0) { pieFlag |= pie_TRANSLUCENT; iPieData = DEFAULT_COMPONENT_TRANSLUCENCY; } else { iPieData = 0; } if (!bButton && psPropStats->propulsionType == PROPULSION_TYPE_PROPELLOR) { // FIXME: change when adding submarines to the game pie_TRANSLATE(0, -world_coord(1) / 2.3f, 0); } //uses psShapeTemp too separate it from turret's psShape psShapeTemp = (leftFirst ? getLeftPropulsionIMD(psDroid) : getRightPropulsionIMD(psDroid)); if (psShapeTemp != NULL) { pie_Draw3DShape(psShapeTemp, 0, colour, brightness, pieFlag, iPieData); } /* set default components transparent */ if (psDroid->asBits[COMP_BODY] == 0) { pieFlag |= pie_TRANSLUCENT; iPieData = DEFAULT_COMPONENT_TRANSLUCENCY; } else { pieFlag &= ~pie_TRANSLUCENT; iPieData = 0; } /* Get the body graphic now*/ //uses psShapeTemp too separate it from turret's psShape psShapeTemp = BODY_IMD(psDroid, psDroid->player); if (psShapeTemp != NULL) { // FIXME if (psDroid->droidType == DROID_PERSON) { /* draw body if not animating */ if (psDroid->psCurAnim == NULL || psDroid->psCurAnim->bVisible == false) { // FIXME - hideous....!!!! pie_MatScale(.75f); pie_Draw3DShape(psShapeTemp, 0, psDroid->player - 6, brightness, pieFlag, iPieData); } } else if (cyborgDroid(psDroid)) { /* draw body if cyborg not animating */ if (psDroid->psCurAnim == NULL || psDroid->psCurAnim->bVisible == false) { pie_Draw3DShape(psShapeTemp, 0, colour, brightness, pieFlag, iPieData); } } else { pie_Draw3DShape(psShapeTemp, 0, colour, brightness, pieFlag, iPieData); } } /* Render animation effects based on movement or lack thereof, if any */ psMoveAnim = asBodyStats[psDroid->asBits[COMP_BODY]].ppMoveIMDList[psDroid->asBits[COMP_PROPULSION]]; psStillAnim = asBodyStats[psDroid->asBits[COMP_BODY]].ppStillIMDList[psDroid->asBits[COMP_PROPULSION]]; if (!bButton && psMoveAnim && psDroid->sMove.Status != MOVEINACTIVE) { pie_Draw3DShape(psMoveAnim, getModularScaledGraphicsTime(psMoveAnim->animInterval, psMoveAnim->numFrames), colour, brightness, pie_ADDITIVE, 200); } else if (!bButton && psStillAnim) // standing still { pie_Draw3DShape(psStillAnim, getModularScaledGraphicsTime(psStillAnim->animInterval, psStillAnim->numFrames), colour, brightness, 0, 0); } //don't change the screen coords of an object if drawing it in a button if (!bButton) { /* set up all the screen coords stuff - need to REMOVE FROM THIS LOOP */ calcScreenCoords(psDroid); } /* set default components transparent */ if (psDroid->asWeaps[0].nStat == 0 && psDroid->asBits[COMP_SENSOR] == 0 && psDroid->asBits[COMP_ECM] == 0 && psDroid->asBits[COMP_BRAIN] == 0 && psDroid->asBits[COMP_REPAIRUNIT] == 0 && psDroid->asBits[COMP_CONSTRUCT] == 0) { pieFlag |= pie_TRANSLUCENT; iPieData = DEFAULT_COMPONENT_TRANSLUCENCY; } else { pieFlag &= ~pie_TRANSLUCENT; iPieData = 0; } psShapeTemp = BODY_IMD(psDroid, psDroid->player); if (psShapeTemp->nconnectors) { /* vtol weapons attach to connector 2 (underneath); * all others to connector 1 */ /* VTOL's now skip the first 5 connectors(0 to 4), VTOL's use 5,6,7,8 etc now */ if (psPropStats->propulsionType == PROPULSION_TYPE_LIFT && psDroid->droidType == DROID_WEAPON) { iConnector = VTOL_CONNECTOR_START; } else { iConnector = 0; } switch (psDroid->droidType) { case DROID_DEFAULT: case DROID_TRANSPORTER: case DROID_SUPERTRANSPORTER: case DROID_CYBORG: case DROID_CYBORG_SUPER: case DROID_WEAPON: case DROID_COMMAND: // command droids have a weapon to store all the graphics /* Get the mounting graphic - we've already moved to the right position Allegedly - all droids will have a mount graphic so this shouldn't fall on it's arse......*/ /* Double check that the weapon droid actually has any */ for (i = 0; i < psDroid->numWeaps; i++) { if ((psDroid->asWeaps[i].nStat > 0 || psDroid->droidType == DROID_DEFAULT) && psShapeTemp->connectors) { Rotation rot = getInterpolatedWeaponRotation(psDroid, i, graphicsTime); pie_MatBegin(!bButton); //to skip number of VTOL_CONNECTOR_START ground unit connectors if (iConnector < VTOL_CONNECTOR_START) { pie_TRANSLATE(psShapeTemp->connectors[i].x, psShapeTemp->connectors[i].z, psShapeTemp->connectors[i].y); } else { pie_TRANSLATE(psShapeTemp->connectors[iConnector + i].x, psShapeTemp->connectors[iConnector + i].z, psShapeTemp->connectors[iConnector + i].y); } pie_MatRotY(-rot.direction); /* vtol weapons inverted */ if (iConnector >= VTOL_CONNECTOR_START) { pie_MatRotZ(65536 / 2); //this might affect gun rotation } /* Get the mount graphic */ psShape = WEAPON_MOUNT_IMD(psDroid, i); int recoilValue = getRecoil(psDroid->asWeaps[i]); pie_TRANSLATE(0, 0, recoilValue / 3); /* Draw it */ if (psShape) { pie_Draw3DShape(psShape, 0, colour, brightness, pieFlag, iPieData); } pie_TRANSLATE(0, 0, recoilValue); /* translate for weapon mount point */ if (psShape && psShape->nconnectors) { pie_TRANSLATE(psShape->connectors->x, psShape->connectors->z, psShape->connectors->y); } /* vtol weapons inverted */ if (iConnector >= VTOL_CONNECTOR_START) { //pitch the barrel down pie_MatRotX(-rot.pitch); } else { //pitch the barrel up pie_MatRotX(rot.pitch); } /* Get the weapon (gun?) graphic */ psShape = WEAPON_IMD(psDroid, i); // We have a weapon so we draw it and a muzzle flash from weapon connector if (psShape) { pie_Draw3DShape(psShape, 0, colour, brightness, pieFlag, iPieData); drawMuzzleFlash(psDroid->asWeaps[i], psShape, MUZZLE_FLASH_PIE(psDroid, i), brightness, pieFlag, iPieData); } /* Pop Matrix */ pie_MatEnd(); } } break; case DROID_SENSOR: case DROID_CONSTRUCT: case DROID_CYBORG_CONSTRUCT: case DROID_ECM: case DROID_REPAIR: case DROID_CYBORG_REPAIR: { Rotation rot = getInterpolatedWeaponRotation(psDroid, 0, graphicsTime); switch (psDroid->droidType) { default: ASSERT(false, "..."); case DROID_SENSOR: psMountShape = SENSOR_MOUNT_IMD(psDroid, psDroid->player); /* Get the sensor graphic, assuming it's there */ psShape = SENSOR_IMD(psDroid, psDroid->player); break; case DROID_CONSTRUCT: case DROID_CYBORG_CONSTRUCT: psMountShape = CONSTRUCT_MOUNT_IMD(psDroid, psDroid->player); /* Get the construct graphic assuming it's there */ psShape = CONSTRUCT_IMD(psDroid, psDroid->player); break; case DROID_ECM: psMountShape = ECM_MOUNT_IMD(psDroid, psDroid->player); /* Get the ECM graphic assuming it's there.... */ psShape = ECM_IMD(psDroid, psDroid->player); break; case DROID_REPAIR: case DROID_CYBORG_REPAIR: psMountShape = REPAIR_MOUNT_IMD(psDroid, psDroid->player); /* Get the Repair graphic assuming it's there.... */ psShape = REPAIR_IMD(psDroid, psDroid->player); break; } /* Get the mounting graphic - we've already moved to the right position Allegedly - all droids will have a mount graphic so this shouldn't fall on it's arse......*/ //sensor and cyborg and ecm uses connectors[0] pie_MatBegin(!bButton); /* vtol weapons inverted */ if (iConnector >= VTOL_CONNECTOR_START) { pie_MatRotZ(65536 / 2); //this might affect gun rotation } pie_TRANSLATE(psShapeTemp->connectors[0].x, psShapeTemp->connectors[0].z, psShapeTemp->connectors[0].y); pie_MatRotY(-rot.direction); /* Draw it */ if (psMountShape) { pie_Draw3DShape(psMountShape, 0, colour, brightness, pieFlag, iPieData); } /* translate for construct mount point if cyborg */ if (cyborgDroid(psDroid) && psMountShape && psMountShape->nconnectors) { pie_TRANSLATE(psMountShape->connectors[0].x, psMountShape->connectors[0].z, psMountShape->connectors[0].y); } /* Draw it */ if (psShape) { pie_Draw3DShape(psShape, 0, colour, brightness, pieFlag, iPieData); // In repair droid case only: if ((psDroid->droidType == DROID_REPAIR || psDroid->droidType == DROID_CYBORG_REPAIR) && psShape->nconnectors && psDroid->action == DACTION_DROIDREPAIR) { Spacetime st = interpolateObjectSpacetime(psDroid, graphicsTime); pie_TRANSLATE(psShape->connectors[0].x, psShape->connectors[0].z, psShape->connectors[0].y); pie_TRANSLATE(0, -20, 0); psShape = getImdFromIndex(MI_FLAME); /* Rotate for droid */ pie_MatRotY(st.rot.direction); pie_MatRotX(-st.rot.pitch); pie_MatRotZ(-st.rot.roll); //rotate Y pie_MatRotY(rot.direction); pie_MatRotY(-player.r.y); pie_MatRotX(-player.r.x); pie_Draw3DShape(psShape, getModularScaledGraphicsTime(psShape->animInterval, psShape->numFrames), 0, brightness, pie_ADDITIVE, 140); pie_MatRotX(player.r.x); pie_MatRotY(player.r.y); } } /* Pop Matrix */ pie_MatEnd(); break; } case DROID_PERSON: // no extra mounts for people break; default: ASSERT(!"invalid droid type", "Whoa! Weirdy type of droid found in drawComponentObject!!!"); break; } } /* We've also got a handle on the psShape here for the weapon which has a connector to point to muzzle flash attachment points - just grab it from psShape->connectors->[x|y|z] */ /* set default components transparent */ if (psDroid->asBits[COMP_PROPULSION] == 0) { pieFlag |= pie_TRANSLUCENT; iPieData = DEFAULT_COMPONENT_TRANSLUCENCY; } else { pieFlag &= ~pie_TRANSLUCENT; iPieData = 0; } psShape = (leftFirst ? getRightPropulsionIMD(psDroid) : getLeftPropulsionIMD(psDroid)); if (psShape != NULL) { pie_Draw3DShape(psShape, 0, colour, brightness, pieFlag, iPieData); } }
// this is able to handle multiple weapon graphics now // removed mountRotation,they get such stuff from psObj directly now static void displayCompObj(DROID *psDroid, BOOL bButton) { iIMDShape *psShape, *psJet, *psShapeTemp = NULL, *psMountShape; Vector3i zero = {0, 0, 0}; Vector2i screenCoords; SDWORD dummyZ, iConnector; PROPULSION_STATS *psPropStats; SDWORD frame; SDWORD pieFlag, iPieData; PIELIGHT brightness; const PIELIGHT specular = WZCOL_BLACK; UDWORD colour; UBYTE i; if( (gameTime-psDroid->timeLastHit < GAME_TICKS_PER_SEC/4 ) && psDroid->lastHitWeapon == WSC_ELECTRONIC && !gamePaused()) { colour = getPlayerColour(rand()%MAX_PLAYERS); } else { colour = getPlayerColour(psDroid->player); } /* get propulsion stats */ psPropStats = asPropulsionStats + psDroid->asBits[COMP_PROPULSION].nStat; ASSERT_OR_RETURN( , psPropStats != NULL, "invalid propulsion stats pointer"); //set pieflag for button object or ingame object if ( bButton ) { pieFlag = pie_BUTTON; } else { pieFlag = 0; } if(!bButton) { brightness = pal_SetBrightness(psDroid->illumination); pieFlag = pie_SHADOW; } else { brightness = WZCOL_WHITE; } /* We've got a z value here _and_ screen coords of origin */ dummyZ = pie_RotateProject(&zero, &screenCoords); /* set default components transparent */ if ( psDroid->asBits[COMP_PROPULSION].nStat == 0 ) { pieFlag |= pie_TRANSLUCENT; iPieData = DEFAULT_COMPONENT_TRANSLUCENCY; } else { iPieData = 0; } if (!bButton && psPropStats->propulsionType == PROPULSION_TYPE_PROPELLOR) { // FIXME: change when adding submarines to the game pie_TRANSLATE(0, -world_coord(1)/2.3f, 0); } //uses psShapeTemp too separate it from turret's psShape psShapeTemp = (leftFirst ? getLeftPropulsionIMD(psDroid) : getRightPropulsionIMD(psDroid)); if(psShapeTemp!=NULL) { pie_Draw3DShape(psShapeTemp, 0, colour, brightness, specular, pieFlag, iPieData); } /* set default components transparent */ if ( psDroid->asBits[COMP_BODY].nStat == 0 ) { pieFlag |= pie_TRANSLUCENT; iPieData = DEFAULT_COMPONENT_TRANSLUCENCY; } else { pieFlag &= ~pie_TRANSLUCENT; iPieData = 0; } /* Get the body graphic now*/ //uses psShapeTemp too separate it from turret's psShape psShapeTemp = BODY_IMD(psDroid,psDroid->player); if(psShapeTemp!=NULL) { // FIXME if ( psDroid->droidType == DROID_PERSON) { /* draw body if not animating */ if ( psDroid->psCurAnim == NULL || psDroid->psCurAnim->bVisible == false ) { // FIXME - hideous....!!!! pie_MatScale(.75f); pie_Draw3DShape(psShapeTemp, 0, psDroid->player-6, brightness, specular, pieFlag, iPieData); } } else if (cyborgDroid(psDroid)) { /* draw body if cyborg not animating */ if ( psDroid->psCurAnim == NULL || psDroid->psCurAnim->bVisible == false ) { pie_Draw3DShape(psShapeTemp, 0, colour, brightness, specular, pieFlag, iPieData); } } else { pie_Draw3DShape(psShapeTemp, 0, colour, brightness, specular, pieFlag, iPieData); } } /* render vtol jet if flying - horrible hack - GJ */ if (((psPropStats->propulsionType == PROPULSION_TYPE_LIFT) && //(psDroid->droidType != DROID_CYBORG)) && (!bButton)) (!cyborgDroid(psDroid))) && (!bButton)) { /* show flame if above ground */ if ( psDroid->sMove.Status != MOVEINACTIVE ) { /* draw flame if found */ /* GJ TODO: add flame-finding code here */ psJet = asBodyStats[psDroid->asBits[COMP_BODY].nStat].pFlameIMD; if ( psJet != NULL ) { pie_Draw3DShape(psJet, getModularScaledGraphicsTime(100, psJet->numFrames), colour, brightness, specular, pie_ADDITIVE, 200); } } } //don't change the screen coords of an object if drawing it in a button if (!bButton) { /* set up all the screen coords stuff - need to REMOVE FROM THIS LOOP */ calcScreenCoords(psDroid); } /* set default components transparent */ if (psDroid->asWeaps[0].nStat == 0 && psDroid->asBits[COMP_SENSOR].nStat == 0 && psDroid->asBits[COMP_ECM].nStat == 0 && psDroid->asBits[COMP_BRAIN].nStat == 0 && psDroid->asBits[COMP_REPAIRUNIT].nStat == 0 && psDroid->asBits[COMP_CONSTRUCT].nStat == 0) { pieFlag |= pie_TRANSLUCENT; iPieData = DEFAULT_COMPONENT_TRANSLUCENCY; } else { pieFlag &= ~pie_TRANSLUCENT; iPieData = 0; } /* Indenting here is only to show new matrix context */ { psShapeTemp = BODY_IMD(psDroid,psDroid->player); if( psShapeTemp->nconnectors ) { /* vtol weapons attach to connector 2 (underneath); * all others to connector 1 */ /* VTOL's now skip the first 5 connectors(0 to 4), VTOL's use 5,6,7,8 etc now */ if ( (psPropStats->propulsionType == PROPULSION_TYPE_LIFT) && psDroid->droidType == DROID_WEAPON ) { iConnector = VTOL_CONNECTOR_START; } else { iConnector = 0; } switch(psDroid->droidType) { case DROID_DEFAULT: case DROID_TRANSPORTER: case DROID_CYBORG: case DROID_CYBORG_SUPER: case DROID_WEAPON: case DROID_COMMAND: // command droids have a weapon to store all the graphics /* Get the mounting graphic - we've already moved to the right position Allegedly - all droids will have a mount graphic so this shouldn't fall on it's arse......*/ /* Double check that the weapon droid actually has any */ for (i = 0;i < psDroid->numWeaps;i++) { if (psDroid->asWeaps[i].nStat > 0 || psDroid->droidType == DROID_DEFAULT) { if ( psShapeTemp->connectors ) { Rotation rot = getInterpolatedWeaponRotation(psDroid, i, graphicsTime); pie_MatBegin(); //reset Z? dummyZ = pie_RotateProject(&zero, &screenCoords); //to skip number of VTOL_CONNECTOR_START ground unit connectors if ( iConnector < VTOL_CONNECTOR_START ) { pie_TRANSLATE(psShapeTemp->connectors[i].x, psShapeTemp->connectors[i].z, psShapeTemp->connectors[i].y); } else { pie_TRANSLATE( psShapeTemp->connectors[iConnector + i].x, psShapeTemp->connectors[iConnector + i].z, psShapeTemp->connectors[iConnector + i].y ); } pie_MatRotY(-rot.direction); /* vtol weapons inverted */ if ( iConnector >= VTOL_CONNECTOR_START ) { pie_MatRotZ(65536/2); //this might affect gun rotation } /* Get the mount graphic */ psShape = WEAPON_MOUNT_IMD(psDroid, i); pie_TRANSLATE(0,0,psDroid->asWeaps[i].recoilValue/3); /* Draw it */ if(psShape) { pie_Draw3DShape(psShape, 0, colour, brightness, specular, pieFlag, iPieData); } pie_TRANSLATE(0,0,psDroid->asWeaps[i].recoilValue); /* translate for weapon mount point */ if (psShape && psShape->nconnectors) { pie_TRANSLATE(psShape->connectors->x, psShape->connectors->z, psShape->connectors->y); } /* vtol weapons inverted */ if ( iConnector >= VTOL_CONNECTOR_START ) { //pitch the barrel down pie_MatRotX(-rot.pitch); } else { //pitch the barrel up pie_MatRotX(rot.pitch); } /* Get the weapon (gun?) graphic */ psShape = WEAPON_IMD(psDroid, i); // We have a weapon so we draw it and a muzzle flash from weapon connector if (psShape) { pie_Draw3DShape(psShape, 0, colour, brightness, specular, pieFlag, iPieData); if (psShape->nconnectors) { unsigned int connector_num = 0; // which barrel is firing if model have multiple muzzle connectors? if (psDroid->asWeaps[i].shotsFired && (psShape->nconnectors > 1)) { // shoot first, draw later - substract one shot to get correct results connector_num = (psDroid->asWeaps[i].shotsFired - 1) % (psShape->nconnectors); } /* Now we need to move to the end of the firing barrel (there maybe multiple barrels) */ pie_TRANSLATE( psShape->connectors[connector_num].x, psShape->connectors[connector_num].z, psShape->connectors[connector_num].y); //and draw the muzzle flash psShape = MUZZLE_FLASH_PIE(psDroid, i); if (psShape) { //assume no clan colours for muzzle effects if ((psShape->numFrames == 0) || (psShape->animInterval <= 0)) { //no anim so display one frame for a fixed time if (gameTime < (psDroid->asWeaps[i].lastFired + BASE_MUZZLE_FLASH_DURATION)) { pie_Draw3DShape(psShape, 0, 0, brightness, WZCOL_BLACK, pieFlag | pie_ADDITIVE, EFFECT_MUZZLE_ADDITIVE); } } else { // animated muzzle frame = (gameTime - psDroid->asWeaps[i].lastFired) / psShape->animInterval; if (frame < psShape->numFrames) { pie_Draw3DShape(psShape, frame, 0, brightness, WZCOL_BLACK, pieFlag | pie_ADDITIVE, EFFECT_MUZZLE_ADDITIVE); } } } } } } /* Pop Matrix */ pie_MatEnd(); } } break; case DROID_SENSOR: case DROID_CONSTRUCT: case DROID_CYBORG_CONSTRUCT: case DROID_ECM: case DROID_REPAIR: case DROID_CYBORG_REPAIR: { Rotation rot = getInterpolatedWeaponRotation(psDroid, 0, graphicsTime); switch (psDroid->droidType) { default: ASSERT(false, "..."); case DROID_SENSOR: psMountShape = SENSOR_MOUNT_IMD(psDroid, psDroid->player); /* Get the sensor graphic, assuming it's there */ psShape = SENSOR_IMD(psDroid, psDroid->player); break; case DROID_CONSTRUCT: case DROID_CYBORG_CONSTRUCT: psMountShape = CONSTRUCT_MOUNT_IMD(psDroid, psDroid->player); /* Get the construct graphic assuming it's there */ psShape = CONSTRUCT_IMD(psDroid, psDroid->player); break; case DROID_ECM: psMountShape = ECM_MOUNT_IMD(psDroid, psDroid->player); /* Get the ECM graphic assuming it's there.... */ psShape = ECM_IMD(psDroid, psDroid->player); break; case DROID_REPAIR: case DROID_CYBORG_REPAIR: psMountShape = REPAIR_MOUNT_IMD(psDroid, psDroid->player); /* Get the Repair graphic assuming it's there.... */ psShape = REPAIR_IMD(psDroid, psDroid->player); break; } /* Get the mounting graphic - we've already moved to the right position Allegedly - all droids will have a mount graphic so this shouldn't fall on it's arse......*/ //sensor and cyborg and ecm uses connectors[0] pie_MatBegin(); //reset Z? dummyZ = pie_RotateProject(&zero, &screenCoords); /* vtol weapons inverted */ if ( iConnector >= VTOL_CONNECTOR_START ) { pie_MatRotZ(65536/2); //this might affect gun rotation } pie_TRANSLATE( psShapeTemp->connectors[0].x, psShapeTemp->connectors[0].z, psShapeTemp->connectors[0].y ); pie_MatRotY(-rot.direction); /* Draw it */ if (psMountShape) { pie_Draw3DShape(psMountShape, 0, colour, brightness, specular, pieFlag, iPieData); } /* translate for construct mount point if cyborg */ if (cyborgDroid(psDroid) && psMountShape && psMountShape->nconnectors) { pie_TRANSLATE(psMountShape->connectors[0].x, psMountShape->connectors[0].z, psMountShape->connectors[0].y); } /* Draw it */ if(psShape) { pie_Draw3DShape(psShape, 0, colour, brightness, specular, pieFlag, iPieData); // In repair droid case only: if ((psDroid->droidType == DROID_REPAIR || psDroid->droidType == DROID_CYBORG_REPAIR) && psShape->nconnectors && psDroid->action == DACTION_DROIDREPAIR) { SPACETIME st = interpolateObjectSpacetime((SIMPLE_OBJECT *)psDroid, graphicsTime); Rotation rot = getInterpolatedWeaponRotation(psDroid, 0, graphicsTime); pie_TRANSLATE( psShape->connectors[0].x, psShape->connectors[0].z, psShape->connectors[0].y ); pie_TRANSLATE(0,-20,0); psShape = getImdFromIndex(MI_FLAME); /* Rotate for droid */ pie_MatRotY(st.rot.direction); pie_MatRotX(-st.rot.pitch); pie_MatRotZ(-st.rot.roll); //rotate Y pie_MatRotY(rot.direction); pie_MatRotY(-player.r.y); pie_MatRotX(-player.r.x); /* Dither on software */ pie_Draw3DShape(psShape, getModularScaledGraphicsTime(100, psShape->numFrames), 0, brightness, WZCOL_BLACK, pie_ADDITIVE, 140); /* Dither off software */ pie_MatRotX(player.r.x); pie_MatRotY(player.r.y); } } /* Pop Matrix */ pie_MatEnd(); break; } case DROID_PERSON: // no extra mounts for people break; default: ASSERT(!"invalid droid type", "Whoa! Weirdy type of droid found in drawComponentObject!!!"); break; } } /* We've also got a handle on the psShape here for the weapon which has a connector to point to muzzle flash attachment points - just grab it from psShape->connectors->[x|y|z] */ } // end of illustrative indentation - see above /* set default components transparent */ if ( psDroid->asBits[COMP_PROPULSION].nStat == 0 ) { pieFlag |= pie_TRANSLUCENT; iPieData = DEFAULT_COMPONENT_TRANSLUCENCY; } else { pieFlag &= ~pie_TRANSLUCENT; iPieData = 0; } psShape = (leftFirst ? getRightPropulsionIMD(psDroid) : getLeftPropulsionIMD(psDroid)); if(psShape!=NULL) { pie_Draw3DShape(psShape, 0, colour, brightness, specular, pieFlag, iPieData); } }