000
15.08.2001, 19:38
apfelkorn
|
Ich habe heute, als ich meine Festplatte aufgeräumt habe noch von vor dem letzten "format c:" ein paar Code-Schnipsel gefunden, die ich ursprünglich für den Mod "Operation: Red Falcon" programmiert habe. Da in dem Mod nun allerdings keine Autos eingesetzt werden, habe ich mich nun dazu entschlossen, die paar Schnipsel auch der Öffentlichkeit zugänglich zu machen.
Wenn ihr diese Code-Schnipsel benutzen wollt, gibt es aber ein paar kleine Regeln: 1. Ich übernehme keinerlei Support dafür und antworte nicht auf Fragen wie: "Wie kann ich denn diesen Code jetzt einsetzen???" Wenn ihr diesen Code benutzen wollt, braucht ihr schon ein wenig Verstand, mit dem ihr sowieso sofort rausfinden würded, was man damit macht. 2. Die Codestücke sind teilweise unvollständig (also Variablen sind nicht deklariert etc.). Ich habe selber auch nicht mehr. Bitte fragt mich nicht nach weiteren Teilen. 3. Wenn ihr was davon in eurem Mod einsetzt, würde es mich freuen, wenn ihr einen klitzekleinen Hinweis irgendwo versteckt, dass der Code teilweise von mir ist, muss aber nicht :) 4. Bitte seht über das schlechte Englisch und die spärlichen Kommentare hinweg. Ich habe gerade noch notdürftig ein wenig was reingeschrieben, wie man diesen Code weiter ausbauen kann und sollte.
Nun, hier kommen die Schnipsel:
// ----------------- Collisiondetection ------------------- float f_unitscalc = m_length / 8; // Units on tracelines to calculate Vector angles; angles = pev->angles; VehicleFixupAngles( angles ); UTIL_MakeVectors( angles );
// TODO: calculate the collisions if you turn around /* // Checking sides // Creating Edge-Vectors! // Options for Tracelines: ignore_monsters - We just want to see if there's a wall!
Vector vecSrcFrontRightSide, vecSrcFrontLeftSide, vecSrcBackRightSide, vecSrcBackLeftSide; // Source-Vectors Vector vecEndFrontRightSide, vecEndFrontLeftSide, vecEndBackRightSide, vecEndBackLeftSide; // End-Vectors TraceResult trs1, trs2, trs3, trs4; // Calculating Source-Vectors vecSrcFrontLeftSide = pev->origin + (-(gpGlobals->v_right) * (m_width/2)) + (gpGlobals->v_forward * (m_length/2)); vecSrcFrontRightSide = pev->origin + (gpGlobals->v_right * (m_width/2)) + (gpGlobals->v_forward * (m_length/2)); vecSrcBackLeftSide = pev->origin + (-(gpGlobals->v_right) * (m_width/2)) + (-(gpGlobals->v_forward) * (m_length/2)); vecSrcBackRightSide = pev->origin + (gpGlobals->v_right * (m_width/2)) + (-(gpGlobals->v_forward) * (m_length/2)); // Calculating End-Vectors vecEndFrontLeftSide = pev->origin + (-(gpGlobals->v_right) * (m_width/2 + f_unitscalc)) + (gpGlobals->v_forward * (m_length/2)); vecEndFrontRightSide = pev->origin + (gpGlobals->v_right * (m_width/2 + f_unitscalc)) + (gpGlobals->v_forward * (m_length/2)); vecEndBackLeftSide = pev->origin + (-(gpGlobals->v_right) * (m_width/2 + f_unitscalc)) + (-(gpGlobals->v_forward) * (m_length/2)); vecEndBackRightSide = pev->origin + (gpGlobals->v_right * (m_width/2 + f_unitscalc)) + (-(gpGlobals->v_forward) * (m_length/2));
// lets shoot some TraceLines UTIL_TraceLine( vecSrcFrontLeftSide, vecEndFrontLeftSide, ignore_monsters, ENT( pev ), &trs1 ); UTIL_TraceLine( vecSrcFrontRightSide, vecEndFrontRightSide, ignore_monsters, ENT( pev ), &trs2 ); UTIL_TraceLine( vecSrcBackLeftSide, vecEndBackLeftSide, ignore_monsters, ENT( pev ), &trs3 ); UTIL_TraceLine( vecSrcBackRightSide, vecEndBackRightSide, ignore_monsters, ENT( pev ), &trs4 ); if (trs1.flFraction < 1.0 || trs2.flFraction < 1.0 || trs3.flFraction < 1.0 || trs4.flFraction < 1.0) { CBaseEntity *pHitS1 = CBaseEntity::Instance( trs1.pHit ); CBaseEntity *pHitS2 = CBaseEntity::Instance( trs2.pHit ); CBaseEntity *pHitS3 = CBaseEntity::Instance( trs3.pHit ); CBaseEntity *pHitS4 = CBaseEntity::Instance( trs4.pHit );
if ( pHitS1->IsBSPModel() || pHitS2->IsBSPModel() || pHitS3->IsBSPModel() || pHitS4->IsBSPModel() ) { // Insert Code HERE! } } */ // Checking front and back // Creating Edge-Vectors! // Options for Tracelines: ignore_monsters - We just want to see if there's a wall!
Vector vecSrcFrontRight, vecSrcFrontLeft, vecSrcBackRight, vecSrcBackLeft; // Source-Vectors Vector vecEndFrontRight, vecEndFrontLeft, vecEndBackRight, vecEndBackLeft; // End-Vectors TraceResult tr1, tr2, tr3, tr4; // Calculating Source-Vectors vecSrcFrontLeft = pev->origin + (-(gpGlobals->v_right) * (m_width/2)) + (gpGlobals->v_forward * (m_length/2 + 1)); vecSrcFrontRight = pev->origin + (gpGlobals->v_right * (m_width/2)) + (gpGlobals->v_forward * (m_length/2 + 1)); vecSrcBackLeft = pev->origin + (-(gpGlobals->v_right) * (m_width/2)) + (-(gpGlobals->v_forward) * (m_length/2 + 1)); vecSrcBackRight = pev->origin + (gpGlobals->v_right * (m_width/2)) + (-(gpGlobals->v_forward) * (m_length/2 + 1));
// Calculating End-Vectors vecEndFrontLeft = pev->origin + (-(gpGlobals->v_right) * (m_width/2)) + (gpGlobals->v_forward * (m_length/2 + f_unitscalc + 1)); vecEndFrontRight = pev->origin + (gpGlobals->v_right * (m_width/2)) + (gpGlobals->v_forward * (m_length/2 + f_unitscalc + 1)); vecEndBackLeft = pev->origin + (-(gpGlobals->v_right) * (m_width/2)) + (-(gpGlobals->v_forward) * (m_length/2 + f_unitscalc + 1)); vecEndBackRight = pev->origin + (gpGlobals->v_right * (m_width/2)) + (-(gpGlobals->v_forward) * (m_length/2 + f_unitscalc + 1));
// lets shoot some TraceLines UTIL_TraceLine( vecSrcFrontLeft, vecEndFrontLeft, ignore_monsters, ENT( pev ), &tr1 ); UTIL_TraceLine( vecSrcFrontRight, vecEndFrontRight, ignore_monsters, ENT( pev ), &tr2 ); UTIL_TraceLine( vecSrcBackLeft, vecEndBackLeft, ignore_monsters, ENT( pev ), &tr3 ); UTIL_TraceLine( vecSrcBackRight, vecEndBackRight, ignore_monsters, ENT( pev ), &tr4 ); if (tr1.flFraction < 1.0 || tr2.flFraction < 1.0 || tr3.flFraction < 1.0 || tr4.flFraction < 1.0) { CBaseEntity *pHit1 = CBaseEntity::Instance( tr1.pHit ); CBaseEntity *pHit2 = CBaseEntity::Instance( tr2.pHit ); CBaseEntity *pHit3 = CBaseEntity::Instance( tr3.pHit ); CBaseEntity *pHit4 = CBaseEntity::Instance( tr4.pHit );
if ( pHit1->IsBSPModel() || pHit2->IsBSPModel() || pHit3->IsBSPModel() || pHit4->IsBSPModel() ) { ALERT ( at_console, "I think we hit a wall at: " ); pev->velocity.x = -(pev->velocity.x); pev->velocity.y = -(pev->velocity.y); pev->velocity.z = -(pev->velocity.z); pev->speed = -(pev->speed); ALERT (at_console, "%f - %f - %f\n", pev->velocity.x, pev->velocity.y, pev->velocity.z);
return; } }
// Check length of vehicle, add it at the front and calculate how fare the vehicle should get away from the wall // You can also just let the car move in the wall an check how far he is in the wall, then dubble it and u see how far the vehicle should be away from the car, but what happens, if the driver stands nearly at the front of the car? -CRUSH- Thats not good :(
// ----------------- Rampcode ------------------- Vector angles = pev->angles; Vector rampangles; UTIL_MakeVectors( pev->angles ); TraceResult trFrontLeft, trFrontRight, trBackLeft, trBackRight, trCalc, trCalcFloor;
Vector vecFrontLeftSrc = pev->origin + (gpGlobals->v_forward * (m_length/2)) - (gpGlobals->v_right * (m_width/2)) + (gpGlobals->v_up * (m_height/2)); Vector vecFrontRightSrc = pev->origin + (gpGlobals->v_forward * (m_length/2)) + (gpGlobals->v_right * (m_width/2)) + (gpGlobals->v_up * (m_height/2)); Vector vecBackLeftSrc = pev->origin - (gpGlobals->v_forward * (m_length/2)) - (gpGlobals->v_right * (m_width/2)) + (gpGlobals->v_up * (m_height/2)); Vector vecBackRightSrc = pev->origin - (gpGlobals->v_forward * (m_length/2)) + (gpGlobals->v_right * (m_width/2)) + (gpGlobals->v_up * (m_height/2));
Vector vecFrontLeftEnd = pev->origin + (gpGlobals->v_forward * (m_length/2)) - (gpGlobals->v_right * (m_width/2)) - (gpGlobals->v_up * (m_height/2)); Vector vecFrontRightEnd = pev->origin + (gpGlobals->v_forward * (m_length/2)) + (gpGlobals->v_right * (m_width/2)) - (gpGlobals->v_up * (m_height/2)); Vector vecBackLeftEnd = pev->origin - (gpGlobals->v_forward * (m_length/2)) - (gpGlobals->v_right * (m_width/2)) - (gpGlobals->v_up * (m_height/2)); Vector vecBackRightEnd = pev->origin - (gpGlobals->v_forward * (m_length/2)) + (gpGlobals->v_right * (m_width/2)) - (gpGlobals->v_up * (m_height/2));
UTIL_TraceLine(vecFrontLeftSrc, vecFrontLeftEnd, ignore_monsters, ENT( pev ), &trFrontLeft); UTIL_TraceLine(vecFrontRightSrc, vecFrontRightEnd, ignore_monsters, ENT( pev ), &trFrontRight); UTIL_TraceLine(vecBackLeftSrc, vecBackLeftEnd, ignore_monsters, ENT( pev ), &trBackLeft); UTIL_TraceLine(vecBackRightSrc, vecBackRightEnd, ignore_monsters, ENT( pev ), &trBackLeft);
if (trFrontLeft.flFraction < trFrontRight.flFraction) { ALERT (at_console, "trFrontLeft.flFraction is smaller than trFrontRight.flFraction"); }
// Use pev->avelocity to make the car drive up ramps // Important: the backwheels MUST stand on the ground while the frontwheels move up the ramp // Do something with sin/cos to do this
// ----------------- Acceleration ------------------- if( gpGlobals->time > (lastAccelerate + 0.1)) { if ( (pev->speed >= 0 && value > 0) || (pev->speed <= 0 && value < 0) ) { pev->speed += (m_speed / m_acceleration) * value; if ( pev->speed > m_speed ) pev->speed = m_speed; else if ( pev->speed < -(m_speed / 2) ) pev->speed = -(m_speed / 2); lastAccelerate = gpGlobals->time; } else { pev->speed += (m_speed / m_acceleration) * value * 1.5; if ( pev->speed < 0 && value < 0 ) { pev->speed = 0; lastAccelerate = gpGlobals->time + 2; } else if ( pev->speed > 0 && value > 0 ) { pev->speed = 0; lastAccelerate = gpGlobals->time + 2; }
EMIT_SOUND_DYN(ENT(pev), CHAN_ITEM, "other/heli_stop.wav", m_flVolume, ATTN_NORM, 0, 100);
} Next(); ALERT( at_aiconsole, "TRAIN(%s), speed to %.2f\n", STRING(pev->targetname), pev->speed ); }
--
Dieser Beitrag wurde am 15.08.2001 um 19:39 von apfelkorn bearbeitet.
|