// ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- void ChPitmanArm::Initialize(std::shared_ptr<ChBodyAuxRef> chassis, const ChVector<>& location, const ChQuaternion<>& rotation) { m_position = ChCoordsys<>(location, rotation); // Chassis orientation (expressed in absolute frame) // Recall that the suspension reference frame is aligned with the chassis. ChQuaternion<> chassisRot = chassis->GetFrame_REF_to_abs().GetRot(); // Express the steering reference frame in the absolute coordinate system. ChFrame<> steering_to_abs(location, rotation); steering_to_abs.ConcatenatePreTransformation(chassis->GetFrame_REF_to_abs()); // Transform all points and directions to absolute frame. std::vector<ChVector<>> points(NUM_POINTS); std::vector<ChVector<>> dirs(NUM_DIRS); for (int i = 0; i < NUM_POINTS; i++) { ChVector<> rel_pos = getLocation(static_cast<PointId>(i)); points[i] = steering_to_abs.TransformPointLocalToParent(rel_pos); } for (int i = 0; i < NUM_DIRS; i++) { ChVector<> rel_dir = getDirection(static_cast<DirectionId>(i)); dirs[i] = steering_to_abs.TransformDirectionLocalToParent(rel_dir); } // Unit vectors for orientation matrices. ChVector<> u; ChVector<> v; ChVector<> w; ChMatrix33<> rot; // Create and initialize the steering link body m_link = std::shared_ptr<ChBody>(chassis->GetSystem()->NewBody()); m_link->SetNameString(m_name + "_link"); m_link->SetPos(points[STEERINGLINK]); m_link->SetRot(steering_to_abs.GetRot()); m_link->SetMass(getSteeringLinkMass()); if (m_vehicle_frame_inertia) { ChMatrix33<> inertia = TransformInertiaMatrix(getSteeringLinkInertiaMoments(), getSteeringLinkInertiaProducts(), chassisRot, steering_to_abs.GetRot()); m_link->SetInertia(inertia); } else { m_link->SetInertiaXX(getSteeringLinkInertiaMoments()); m_link->SetInertiaXY(getSteeringLinkInertiaProducts()); } chassis->GetSystem()->AddBody(m_link); m_pP = m_link->TransformPointParentToLocal(points[UNIV]); m_pI = m_link->TransformPointParentToLocal(points[REVSPH_S]); m_pTP = m_link->TransformPointParentToLocal(points[TIEROD_PA]); m_pTI = m_link->TransformPointParentToLocal(points[TIEROD_IA]); // Create and initialize the Pitman arm body m_arm = std::shared_ptr<ChBody>(chassis->GetSystem()->NewBody()); m_arm->SetNameString(m_name + "_arm"); m_arm->SetPos(points[PITMANARM]); m_arm->SetRot(steering_to_abs.GetRot()); m_arm->SetMass(getPitmanArmMass()); if (m_vehicle_frame_inertia) { ChMatrix33<> inertia = TransformInertiaMatrix(getPitmanArmInertiaMoments(), getPitmanArmInertiaProducts(), chassisRot, steering_to_abs.GetRot()); m_arm->SetInertia(inertia); } else { m_arm->SetInertiaXX(getPitmanArmInertiaMoments()); m_arm->SetInertiaXY(getPitmanArmInertiaProducts()); } chassis->GetSystem()->AddBody(m_arm); // Cache points for arm visualization (expressed in the arm frame) m_pC = m_arm->TransformPointParentToLocal(points[REV]); m_pL = m_arm->TransformPointParentToLocal(points[UNIV]); // Create and initialize the revolute joint between chassis and Pitman arm. // Note that this is modeled as a ChLinkEngine to allow driving it with // imposed rotation (steering input). // The z direction of the joint orientation matrix is dirs[REV_AXIS], assumed // to be a unit vector. u = points[PITMANARM] - points[REV]; v = Vcross(dirs[REV_AXIS], u); v.Normalize(); u = Vcross(v, dirs[REV_AXIS]); rot.Set_A_axis(u, v, dirs[REV_AXIS]); m_revolute = std::make_shared<ChLinkMotorRotationAngle>(); m_revolute->SetNameString(m_name + "_revolute"); m_revolute->Initialize(chassis, m_arm, ChFrame<>(points[REV], rot.Get_A_quaternion())); auto motor_fun = std::make_shared<ChFunction_Setpoint>(); m_revolute->SetAngleFunction(motor_fun); chassis->GetSystem()->AddLink(m_revolute); // Create and initialize the universal joint between the Pitman arm and steering link. // The x and y directions of the joint orientation matrix are given by // dirs[UNIV_AXIS_ARM] and dirs[UNIV_AXIS_LINK], assumed to be unit vectors // and orthogonal. w = Vcross(dirs[UNIV_AXIS_ARM], dirs[UNIV_AXIS_LINK]); rot.Set_A_axis(dirs[UNIV_AXIS_ARM], dirs[UNIV_AXIS_LINK], w); m_universal = std::make_shared<ChLinkUniversal>(); m_universal->SetNameString(m_name + "_universal"); m_universal->Initialize(m_arm, m_link, ChFrame<>(points[UNIV], rot.Get_A_quaternion())); chassis->GetSystem()->AddLink(m_universal); // Create and initialize the revolute-spherical joint (massless idler arm). // The length of the idler arm is the distance between the two hardpoints. // The z direction of the revolute joint orientation matrix is // dirs[REVSPH_AXIS], assumed to be a unit vector. double distance = (points[REVSPH_S] - points[REVSPH_R]).Length(); u = points[REVSPH_S] - points[REVSPH_R]; v = Vcross(dirs[REVSPH_AXIS], u); v.Normalize(); u = Vcross(v, dirs[REVSPH_AXIS]); rot.Set_A_axis(u, v, dirs[REVSPH_AXIS]); m_revsph = std::make_shared<ChLinkRevoluteSpherical>(); m_revsph->SetNameString(m_name + "_revsph"); m_revsph->Initialize(chassis, m_link, ChCoordsys<>(points[REVSPH_R], rot.Get_A_quaternion()), distance); chassis->GetSystem()->AddLink(m_revsph); }
// Real-C #include "ENGINE.hpp" #include "globals.h" TRIGGER( enterrange , 0x01 )(obj target) { if(!hasObjVar(this, "disarmed")) { doLocAnimation(getLocation(this), 0x10FE, 0x02, 0x10, 0x00, 0x00); loseHP(target, dice(0x0A, 0x03)); } return(0x01); } TRIGGER( message , "covThreeFireTrapDisarm" )(obj sender, list args) { if(!hasObjVar(this, "disarmed")) { setObjVar(this, "disarmed", 0x01); callback(this, 0x78, 0x24); } return(0x00); } TRIGGER( callback , 0x24 )() { if(hasObjVar(this, "disarmed")) { removeObjVar(this, "disarmed"); }
CG::ExprValue CreateArrayGenerator::buildExprValue( CG::BasicBlockBuilder &basicBlockBuilder, CG::Usage usage, std::string const &lValueErrorDesc ) const { if ( usage == CG::USAGE_LVALUE ) throw Exception( "cannot be used as l-values" ); RC::Handle<CG::Context> context = basicBlockBuilder.getContext(); llvm::LLVMContext &llvmContext = context->getLLVMContext(); RC::ConstHandle<CG::SizeAdapter> sizeAdapter = basicBlockBuilder.getManager()->getSizeAdapter(); RC::ConstHandle<CG::Symbol> operatorSymbol = basicBlockBuilder.getScope().get( m_operatorName ); if ( !operatorSymbol ) throw CG::Error( getLocation(), _(m_operatorName) + ": operator not found" ); if ( !operatorSymbol->isPencil() ) throw CG::Error( getLocation(), _(m_operatorName) + ": not an operator" ); RC::ConstHandle<CG::PencilSymbol> pencil = RC::ConstHandle<CG::PencilSymbol>::StaticCast( operatorSymbol ); CG::Function const *function = pencil->getUniqueFunction( getLocation(), "operator " + _(m_operatorName) ); std::vector<CG::FunctionParam> const &operatorParams = function->getParams(); if ( operatorParams.size() < 1 ) throw MR::ArrayGeneratorOperator::GetPrototypeException(); CG::ExprType countExprType = m_count->getExprType( basicBlockBuilder ); if ( !RT::isValueProducer( countExprType.getAdapter()->getType() ) ) throw CG::Error( getLocation(), "count must be a value producer" ); RC::ConstHandle<CG::ValueProducerAdapter> countValueProducerAdapter = RC::ConstHandle<CG::ValueProducerAdapter>::StaticCast( countExprType.getAdapter() ); RC::ConstHandle<CG::Adapter> countAdapter = countValueProducerAdapter->getValueAdapter(); if ( countAdapter != sizeAdapter ) throw CG::Error( getLocation(), "count value type must be 'Size'" ); CG::ExprValue countValueProducerExprValue = m_count->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc ); if ( operatorParams[0].getUsage() != CG::USAGE_LVALUE ) throw CG::Error( getLocation(), "operator value parameter must be an 'io' parameter" ); RC::ConstHandle<CG::Adapter> outputAdapter = operatorParams[0].getAdapter(); RC::ConstHandle<CG::ArrayProducerAdapter> outputArrayProducerAdapter = basicBlockBuilder.getManager()->getArrayProducerOf( outputAdapter ); llvm::Value *resultLValue = outputArrayProducerAdapter->llvmAlloca( basicBlockBuilder, "result" ); outputArrayProducerAdapter->llvmInit( basicBlockBuilder, resultLValue ); basicBlockBuilder.getScope().put( CG::VariableSymbol::Create( CG::ExprValue( outputArrayProducerAdapter, CG::USAGE_LVALUE, context, resultLValue ) ) ); bool needCall = true; if ( operatorParams.size() >= 2 ) { if ( operatorParams[1].getAdapter() != sizeAdapter ) throw CG::Error( getLocation(), "operator index parameter type (" + operatorParams[1].getAdapter()->getUserName() + ") must be 'Size'" ); if ( operatorParams[1].getUsage() != CG::USAGE_RVALUE ) throw CG::Error( getLocation(), "operator index parameter must be an 'in' parameter" ); if ( operatorParams.size() >= 3 ) { if ( operatorParams[2].getAdapter() != sizeAdapter ) throw CG::Error( getLocation(), "operator index parameter type (" + operatorParams[2].getAdapter()->getUserName() + ") must be 'Size'" ); if ( operatorParams[2].getUsage() != CG::USAGE_RVALUE ) throw CG::Error( getLocation(), "operator index parameter must be an 'in' parameter" ); if ( operatorParams.size() >= 4 ) { if ( operatorParams.size() > 4 ) throw MR::ArrayGeneratorOperator::GetPrototypeException(); if ( !m_shared ) throw CG::Error( getLocation(), "operator takes a shared value but no shared value is provided" ); CG::ExprType sharedExprType = m_shared->getExprType( basicBlockBuilder ); if ( !RT::isValueProducer( sharedExprType.getAdapter()->getType() ) ) throw CG::Error( getLocation(), "shared value must be a value producer" ); RC::ConstHandle<CG::ValueProducerAdapter> sharedValueProducerAdapter = RC::ConstHandle<CG::ValueProducerAdapter>::StaticCast( sharedExprType.getAdapter() ); RC::ConstHandle<CG::Adapter> sharedAdapter = sharedValueProducerAdapter->getValueAdapter(); if ( operatorParams[3].getAdapter() != sharedAdapter ) throw CG::Error( getLocation(), "operator shared value parameter type (" + operatorParams[3].getAdapter()->getUserName() + ") does not match shared value type (" + sharedAdapter->getUserName() + ")" ); if ( operatorParams[3].getUsage() != CG::USAGE_RVALUE ) throw CG::Error( getLocation(), "operator shared value parameter must be an 'in' parameter" ); CG::ExprValue sharedExprRValue = m_shared->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc ); std::vector<llvm::Type const *> argTypes; argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // function argTypes.push_back( sizeAdapter->llvmRType( context ) ); // numParams argTypes.push_back( countValueProducerAdapter->llvmLType( context ) ); // count value producer argTypes.push_back( sharedValueProducerAdapter->llvmLType( context ) ); // shared value producer argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // output array producer adapter argTypes.push_back( outputArrayProducerAdapter->llvmLType( context ) ); // output array producer llvm::FunctionType const *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( llvmContext ), argTypes, false ); llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__MR_CreateArrayGenerator_4", funcType ); std::vector<llvm::Value *> args; args.push_back( basicBlockBuilder->CreateBitCast( function->getLLVMFunction(), llvm::Type::getInt8PtrTy( llvmContext ) ) ); args.push_back( sizeAdapter->llvmConst( context, operatorParams.size() ) ); args.push_back( countValueProducerExprValue.getValue() ); args.push_back( sharedExprRValue.getValue() ); args.push_back( outputArrayProducerAdapter->llvmAdapterPtr( basicBlockBuilder ) ); args.push_back( resultLValue ); basicBlockBuilder->CreateCall( func, args.begin(), args.end() ); needCall = false; } } } if ( needCall ) { std::vector<llvm::Type const *> argTypes; argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // function argTypes.push_back( sizeAdapter->llvmRType( context ) ); // numParams argTypes.push_back( countValueProducerAdapter->llvmLType( context ) ); // count value producer argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // output array producer adapter argTypes.push_back( outputArrayProducerAdapter->llvmLType( context ) ); // output array producer llvm::FunctionType const *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( llvmContext ), argTypes, false ); llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__MR_CreateArrayGenerator_3", funcType ); std::vector<llvm::Value *> args; args.push_back( basicBlockBuilder->CreateBitCast( function->getLLVMFunction(), llvm::Type::getInt8PtrTy( llvmContext ) ) ); args.push_back( sizeAdapter->llvmConst( context, operatorParams.size() ) ); args.push_back( countValueProducerExprValue.getValue() ); args.push_back( outputArrayProducerAdapter->llvmAdapterPtr( basicBlockBuilder ) ); args.push_back( resultLValue ); basicBlockBuilder->CreateCall( func, args.begin(), args.end() ); } return CG::ExprValue( outputArrayProducerAdapter, CG::USAGE_RVALUE, context, outputArrayProducerAdapter->llvmLValueToRValue( basicBlockBuilder, resultLValue ) ); }
void Shorty::keyPressEventHandler(QEvent *event){ qDebug(shorty_Main()) << "A key was pressed. we are now at location" << getLocation() << "and looking for" << data->getCommandAt(getLocation()); if (data->getCommandAt(getLocation()) == "Ctrl" && ((QKeyEvent*)event)->modifiers() && Qt::ControlModifier) { //if key is Ctrl qDebug(shorty_Main()) << "Ctrl was pressed. our location is" << getLocation() << "and now it'll be" << getLocation()+1; paint(getLocation()); setLocation(getLocation()+1); } else if (data->getCommandAt(getLocation()) == "Alt" && ((QKeyEvent*)event)->modifiers() && Qt::AltModifier) { //if key is Alt qDebug(shorty_Main()) << "Alt was pressed. our location is" << getLocation() << "and now it'll be" << getLocation()+1; paint(getLocation()); setLocation(getLocation()+1); }//shift else if (data->getCommandAt(getLocation()) == "Enter" && (((QKeyEvent*)event)->key() == Qt::Key_Enter || ((QKeyEvent*)event)->key() == Qt::Key_Return)) { //if key is Enter qDebug(shorty_Main()) << "Enter was pressed. our location is" << getLocation() << "and now it'll be" << getLocation()+1; paint(getLocation()); setLocation(getLocation()+1); } else if (data->getCommandAt(getLocation()) == "ESC" && (((QKeyEvent*)event)->key() == Qt::Key_Escape)) { //if key is esc qDebug(shorty_Main()) << "Enter was pressed. our location is" << getLocation() << "and now it'll be" << getLocation()+1; paint(getLocation()); setLocation(getLocation()+1); } else { // key is not pressedKeys += ((QKeyEvent*)event)->key(); qDebug(shorty_Main()) << ((QKeyEvent*)event)->key() << "was pressed. our location is" << getLocation() << "and and the key that we are looking for is" << data->getCommandAt(getLocation()); if ( pressedKeys.contains(toKey(data->getCommandAt(getLocation())))) { qDebug(shorty_Main()) << "We got a match. our location is" << getLocation() << "and now it'll be" << getLocation()+1; paint(getLocation()); setLocation(getLocation()+1); } else { qDebug(shorty_Main()) << "No match for this key. turning on errorFlag"; setLocation(getLocation()-1); errorPaint(getLocation()); errorFlag = !errorFlag; } } if (getLocation() == keyList.count()) { //full match qDebug(shorty_Main()) << "Location is" << getLocation() << "Total count is" << keyList.count() << "all keys for this shortcut are matched"; load(); } }
DPoint CATouch::getDeltaFromAToZ() const { return ccpSub(getLocation(), getStartLocation()); }
void Sound::DrawOverlay(X3DDrawContext* pDC) { // TODO: not here if (m_selected) { pDC->m_renderContext->PushModelView(pDC->m_renderContext->modelViewMatrix() * MatrixTranslation(getLocation())); DrawAxis(pDC); pDC->m_renderContext->PopMatrix(); // pDC->m_renderContext->GetRT()->m_d3d10->m_device->OMSetDepthStencilState(depthStencilState, stencilRef); } }
void Require::collectRequires( RequireNameToLocationMap &uses ) const { uses.insert( RequireNameToLocationMap::value_type( m_name, getLocation() ) ); }
void Vec4ShaderUniform::apply() { glUniform4fv(getLocation(), 1, glm::value_ptr(value)); }
void Mat4ShaderUniform::apply() { glUniformMatrix4fv(getLocation(), 1, 0, glm::value_ptr(value)); }
void BoolShaderUniform::apply() { glUniform1i(getLocation(), value); }
void Sampler2DShaderUniform::apply() { glUniform1i(getLocation(), value); }
void FloatShaderUniform::apply() { glUniform1f(getLocation(), value); }
CG::ExprValue IndexOp::buildExprValue( CG::BasicBlockBuilder &basicBlockBuilder, CG::Usage usage, std::string const &lValueErrorDesc ) const { CG::ExprValue result( basicBlockBuilder.getContext() ); try { CG::ExprValue arrayExprValue = m_expr->buildExprValue( basicBlockBuilder, usage, lValueErrorDesc ); RC::ConstHandle<CG::Adapter> adapter = arrayExprValue.getAdapter(); if ( RT::isArray( arrayExprValue.getAdapter()->getType() ) ) { RC::ConstHandle<CG::ArrayAdapter> arrayAdapter = RC::ConstHandle<CG::ArrayAdapter>::StaticCast( adapter ); CG::ExprValue indexExprValue = m_indexExpr->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc ); RC::ConstHandle< CG::SizeAdapter > sizeAdapter = basicBlockBuilder.getManager()->getSizeAdapter(); llvm::Value *indexExprRValue = sizeAdapter->llvmCast( basicBlockBuilder, indexExprValue ); if ( indexExprRValue ) { switch ( usage ) { case CG::USAGE_LVALUE: result = CG::ExprValue( arrayAdapter->getMemberAdapter(), CG::USAGE_LVALUE, basicBlockBuilder.getContext(), arrayAdapter->llvmNonConstIndexOp( basicBlockBuilder, arrayExprValue.getValue(), indexExprRValue, &getLocation() ) ); break; default: result = CG::ExprValue( arrayAdapter->getMemberAdapter(), CG::USAGE_RVALUE, basicBlockBuilder.getContext(), arrayAdapter->llvmConstIndexOp( basicBlockBuilder, arrayExprValue.getValue(), indexExprRValue, &getLocation() ) ); break; } } } else if ( RT::isDict( arrayExprValue.getAdapter()->getType() ) ) { RC::ConstHandle<CG::DictAdapter> dictAdapter = RC::ConstHandle<CG::DictAdapter>::StaticCast( adapter ); CG::ExprValue indexExprValue = m_indexExpr->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc ); RC::ConstHandle<CG::ComparableAdapter> keyAdapter = dictAdapter->getKeyAdapter(); llvm::Value *indexExprRValue = keyAdapter->llvmCast( basicBlockBuilder, indexExprValue ); if ( indexExprRValue ) { switch ( usage ) { case CG::USAGE_LVALUE: result = CG::ExprValue( dictAdapter->getValueAdapter(), CG::USAGE_LVALUE, basicBlockBuilder.getContext(), dictAdapter->llvmGetLValue( basicBlockBuilder, arrayExprValue.getValue(), indexExprRValue ) ); break; default: result = CG::ExprValue( dictAdapter->getValueAdapter(), CG::USAGE_RVALUE, basicBlockBuilder.getContext(), dictAdapter->llvmGetRValue( basicBlockBuilder, arrayExprValue.getValue(), indexExprRValue ) ); break; } } } else throw CG::Error( getLocation(), "only arrays and dictionaries can be indexed" ); } catch ( CG::Error e ) { throw e; } catch ( Exception e ) { throw CG::Error( getLocation(), e ); } return result; }
// ----------------------------------------------------------------------------- // Get the wheel track using the spindle local position. // ----------------------------------------------------------------------------- double ChDoubleWishboneReduced::GetTrack() { return 2 * getLocation(SPINDLE).y(); }
FUNCTION int Q659(obj user) { int Q62A = getObjType(this); if(hasObjVar(this, "fuel")) { int fuel = getObjVar(this, "fuel"); } switch(Q62A) { case 0x0A26: setObjVar(this, "burning", 0x01); setType(this, 0x0B1A); break; case 0x0A27: setObjVar(this, "burning", 0x01); setType(this, 0x0B1D); break; case 0x0A29: setObjVar(this, "burning", 0x01); setType(this, 0x0B26); break; case 0x1853: setObjVar(this, "burning", 0x01); setType(this, 0x1854); break; case 0x1857: setObjVar(this, "burning", 0x01); setType(this, 0x1858); break; case 0x1849: setObjVar(this, "burning", 0x01); setType(this, 0x184A); break; case 0x184D: setObjVar(this, "burning", 0x01); setType(this, 0x184E); break; case 0x0A28: int Q527; obj Q47F = getBackpack(user); obj Q5BO = requestCreateObjectAt(0x0A0F, getLocation(user)); setObjVar(this, "fuel", 0x64); setObjVar(Q5BO, "burning", 0x01); attachscript(Q5BO, "torch"); callback(Q5BO, 0x1E, 0x39); if(!isInContainer(this)) { Q527 = teleport(Q5BO, getLocation(this)); if(getQuantity(this) > 0x01) { destroyOne(this); if(canHold(Q47F, this)) { systemMessage(user, "You put the remaining unlit candles into your backpack."); Q527 = putObjContainer(this, Q47F); } else { systemMessage(user, "You put the remaining unlit candles at your feet."); Q527 = teleport(this, getLocation(user)); } } } else { destroyOne(this); if(getItemAtSlot(user, 0x02) != NULL()) { systemMessage(user, "You cannot hold the candle, so it has been placed at your feet."); } else { Q527 = equipObj(Q5BO, user, 0x02); systemMessage(user, "You put the candle in your left hand."); } } if(getQuantity(this) == 0x01) { destroyOne(this); } break; case 0x0F64: case 0x0F6B: Q47F = getBackpack(user); obj Q5CB = requestCreateObjectAt(0x0A12, getLocation(user)); setObjVar(this, "fuel", 0x64); setObjVar(Q5CB, "burning", 0x01); attachscript(Q5CB, "torch"); callback(Q5CB, 0x1E, 0x39); if(!isInContainer(this)) { Q527 = teleport(Q5CB, getLocation(this)); if(getQuantity(this) > 0x01) { destroyOne(this); if(canHold(Q47F, this)) { systemMessage(user, "You put the remaining unlit torches into your backpack."); Q527 = putObjContainer(this, Q47F); } else { systemMessage(user, "You put the remaining unlit torches at your feet."); Q527 = teleport(this, getLocation(user)); } } } else { destroyOne(this); if(getItemAtSlot(user, 0x02) != NULL()) { systemMessage(user, "You cannot hold the torch, so it has been placed at your feet."); } else { Q527 = equipObj(Q5CB, user, 0x02); systemMessage(user, "You put the torch in your left hand."); } } if(getQuantity(this) == 0x01) { destroyOne(this); } break; case 0x0A18: case 0x0A1D: case 0x0A25: if(fuel > 0x00) { setObjVar(this, "burning", 0x01); callback(this, 0x1E, 0x39); setType(this, Q62A - 0x03); } else { systemMessage(user, "The lantern is out of fuel."); } break; default: return(0x00); break; } sfx(getLocation(this), 0x47, 0x00); return(0x01); }
void Vec4ArrayShaderUniform::apply() { glUniform4fv(getLocation(), length, glm::value_ptr(value[0])); }
void Sound::Draw(X3DDrawContext* pDC) { if (!m_bPlaying) { m_bPlaying = true; Play(); } XAUDIO2_DEVICE_DETAILS& deviceDetails = Gui::deviceDetails; int destChannels = 1; destChannels = deviceDetails.OutputFormat.Format.nChannels; AudioClip* source = dynamic_cast<AudioClip*>(m_currentSource); X3DAUDIO_EMITTER emitter = {0}; emitter.ChannelCount = 1;//source->m_wfx.nChannels; emitter.CurveDistanceScaler = 10;//FLT_MIN; emitter.DopplerScaler = 1; X3DAUDIO_DSP_SETTINGS dspSettings = {0}; FLOAT32* matrix = new FLOAT32[destChannels * 1]; dspSettings.SrcChannelCount = source->m_wave->get_Format().nChannels; dspSettings.DstChannelCount = destChannels; dspSettings.pMatrixCoefficients = matrix; D3DXVECTOR3 emitterPosition = transform(pDC->m_renderContext->modelViewMatrix(), getLocation()); D3DXVECTOR3 emitterVelocity(0, 0, 0); D3DXVECTOR3 emitterOrientTop(0, 1, 0); D3DXVECTOR3 emitterOrientFront(1, 0, 0); emitter.OrientFront = emitterOrientFront; emitter.OrientTop = emitterOrientTop; emitter.Position = emitterPosition; emitter.Velocity = emitterVelocity; // emitter.InnerRadius = 2.0f; // emitter.InnerRadiusAngle = X3DAUDIO_PI/4.0f; emitter.ChannelRadius = 1.0; X3DAudioCalculate(Gui::X3DInstance, &pDC->m_listener, &emitter, X3DAUDIO_CALCULATE_MATRIX | X3DAUDIO_CALCULATE_DOPPLER | X3DAUDIO_CALCULATE_LPF_DIRECT | X3DAUDIO_CALCULATE_REVERB, &dspSettings); m_sourceVoice->SetOutputMatrix(Gui::pMasteringVoice, source->m_wave->get_Format().nChannels, destChannels, dspSettings.pMatrixCoefficients); m_sourceVoice->SetFrequencyRatio(dspSettings.DopplerFactor); m_sourceVoice->SetOutputMatrix(m_submixVoice, 1, 1, &dspSettings.ReverbLevel); XAUDIO2_FILTER_PARAMETERS FilterParametersDirect = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI/6.0f * dspSettings.LPFDirectCoefficient), 1.0f }; // see XAudio2CutoffFrequencyToRadians() in XAudio2.h for more information on the formula used here m_sourceVoice->SetOutputFilterParameters(Gui::pMasteringVoice, &FilterParametersDirect); XAUDIO2_FILTER_PARAMETERS FilterParametersReverb = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI/6.0f * dspSettings.LPFReverbCoefficient), 1.0f }; // see XAudio2CutoffFrequencyToRadians() in XAudio2.h for more information on the formula used here m_sourceVoice->SetOutputFilterParameters(m_submixVoice, &FilterParametersReverb); // XAUDIO2_FILTER_PARAMETERS FilterParameters = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI/6.0f * DSPSettings.LPFDirectCoefficient), 1.0f }; // m_sourceVoice->SetFilterParameters(&FilterParameters); #if 0 if (m_source->m_value) { // Add us the audioclips list of sounds for (int i = 0; i < static_cast<CLAudioClip*>(m_source->m_value)->m_sounds.GetSize(); i++) { if (static_cast<CLAudioClip*>(m_source->m_value)->m_sounds[i] == this) break; } if (i == static_cast<CLAudioClip*>(m_source->m_value)->m_sounds.GetSize()) { static_cast<CLAudioClip*>(m_source->m_value)->m_sounds.Add(this); } } #endif }
const omxFreeVarLocation *omxFreeVar::getLocation(omxMatrix *mat) const { return getLocation(~mat->matrixNumber); }
//=================================================================================== float laneHalfAngle (Pair passerLoc, // Position of the passing robot. Pair passDestination, // location of the pass destination const VisionData &field, // where everyone else is now const SystemParameters &rp, // contains necessary game parameters const Pair * extraObstacle, // Check this (optional) location as an obstacle too bool checkOurRobots) //to see if we check for our robots or not... { float minLaneAngle = PI/2.0f; // Initialize the lane half angle to PI/2 (a clear lane) // Lane parameters float laneLength = passerLoc.distanceTo (passDestination); laneLength = laneLength + rp.general.PLAYER_RADIUS + rp.general.BALL_RADIUS; float laneDirection = angleWithXAxis (passerLoc, passDestination); // Obstacle parameters Pair obstacleLoc; // Obstacle centre location float obstacleDist; // Distance of the obstacle centre from the passerLoc float obstacleDirection; // Angle made by the segment from passerLoc to obstacle with the x-axis float obstacleHalfAngle; // Half the angle subtended by the obstacle on the passer loc float angleWithLane1; // Angle between the tangents drawn from passerLoc to obstacle with float angleWithLane2; // the lane direction // Check opponent robots first RobotIndex i; for (i = ROBOT0; i < NUM_ROBOTS; i++) { if (theirRobotFound (i, field, rp)) { // Get obstacle direction and distance from the passerLoc obstacleLoc = getTheirRobotLocation (i, field, rp); obstacleDist = passerLoc.distanceTo (obstacleLoc); // Get the direction of the segment from passerLoc to obstacle with the x-axis obstacleDirection = angleWithXAxis (passerLoc, obstacleLoc); obstacleHalfAngle = ATAN2 (rp.general.OPPONENT_RADIUS, obstacleDist); // Evaluate angles only if the passer loc is closer to the obtacle than the lane length if (obstacleDist <= laneLength) { // If the difference between the obstacle direction and lane direction is within the half // angle subtended by the obstacle on the passer loc, the lane is being blocked if (ABS (laneDirection - obstacleDirection) <= obstacleHalfAngle) return 0.0f; // Get the directions of the tangent to the obstacle from the passer loc and their angular // difference from the lane direction angleWithLane1 = ABS (angleDifference (obstacleDirection + obstacleHalfAngle, laneDirection)); angleWithLane2 = ABS (angleDifference (obstacleDirection - obstacleHalfAngle, laneDirection)); // Compare the angle of the tangent closer to the lane diretion float smallerAngle = MIN (angleWithLane1, angleWithLane2); if (smallerAngle < minLaneAngle) minLaneAngle = smallerAngle; } } } //IF WE WANT TO TAKE INTO ACCOUNT OUR OWN ROBOTS... if (checkOurRobots) { for (i = ROBOT0; i < NUM_ROBOTS; i++) { //If our robot is found, and he is not the passer or receiver => check to see if it is in the way if(robotFound(i, field, rp)&&(dist(i,passerLoc,field,rp)>rp.general.PLAYER_RADIUS)&&(dist(i,passDestination,field,rp)>rp.general.PLAYER_RADIUS)) { // Get obstacle direction and distance from the passerLoc obstacleLoc = getLocation (i, field, rp); obstacleDist = passerLoc.distanceTo (obstacleLoc); // Get the direction of the segment from passerLoc to obstacle with the x-axis obstacleDirection = angleWithXAxis (passerLoc, obstacleLoc); obstacleHalfAngle = ATAN2 (rp.general.PLAYER_RADIUS, obstacleDist); // Evaluate angles only if the passer loc is closer to the obtacle than the lane length if (obstacleDist <= laneLength) { // If the difference between the obstacle direction and lane direction is within the half // angle subtended by the obstacle on the passer loc, the lane is being blocked if (ABS (laneDirection - obstacleDirection) <= obstacleHalfAngle) return 0.0f; // Get the directions of the tangent to the obstacle from the passer loc and their angular // difference from the lane direction angleWithLane1 = ABS (angleDifference (obstacleDirection + obstacleHalfAngle, laneDirection)); angleWithLane2 = ABS (angleDifference (obstacleDirection - obstacleHalfAngle, laneDirection)); // Compare the angle of the tangent closer to the lane diretion float smallerAngle = MIN (angleWithLane1, angleWithLane2); if (smallerAngle < minLaneAngle) minLaneAngle = smallerAngle; } } } } // Check the passed extra location as an obstacle having the radius the same as our robots if (extraObstacle) { // Get obstacle direction and distance from the passerLoc obstacleLoc = * extraObstacle; obstacleDist = passerLoc.distanceTo (obstacleLoc); // Get the direction of the segment from passerLoc to obstacle with the x-axis obstacleDirection = angleWithXAxis (passerLoc, obstacleLoc); obstacleHalfAngle = ATAN2 (rp.general.PLAYER_RADIUS, obstacleDist); // Evaluate angles only if the passer loc is closer to the obtacle than the lane length if (obstacleDist <= laneLength) { // If the difference between the obstacle direction and lane direction is within the half // angle subtended by the obstacle on the passer loc, the lane is being blocked if (ABS (laneDirection - obstacleDirection) <= obstacleHalfAngle) return 0.0f; // Get the directions of the tangent to the obstacle from the passer loc and their angular // difference from the lane direction angleWithLane1 = ABS (angleDifference (obstacleDirection + obstacleHalfAngle, laneDirection)); angleWithLane2 = ABS (angleDifference (obstacleDirection - obstacleHalfAngle, laneDirection)); // Compare the angle of the tangent closer to the lane diretion float smallerAngle = MIN (angleWithLane1, angleWithLane2); if (smallerAngle < minLaneAngle) minLaneAngle = smallerAngle; } } return minLaneAngle; }
TRIGGER( targetobj )(obj user, obj usedon) { if(usedon == NULL()) { return(0x00); } if(isEquipped(usedon)) { systemMessage(user, "Can't Dye clothing that is being worn."); return(0x00); } int Q66P = getObjType(usedon); int Q61R = getHue(this); loc Q66R = loc( getLocation(usedon) ); switch(Q66P) { case 0x0DEF: case 0x0DF8: case 0x0DF9: case 0x0E1D: case 0x0E1E: case 0x0E1F: case 0x0E75: case 0x0E76: case 0x0F95: case 0x0F96: case 0x0F97: case 0x0F98: case 0x0F99: case 0x0F9A: case 0x0F9B: case 0x0F9C: case 0x0F9C: case 0x0FA0: case 0x0FA1: case 0x101F: case 0x13A4: case 0x0BD5: case 0x0BD6: case 0x0BD7: case 0x0BD8: case 0x0BD9: case 0x0BDA: case 0x0BDB: case 0x0BDC: case 0x0BDD: case 0x0BDE: case 0x1515: case 0x1516: case 0x1517: case 0x1518: case 0x152E: case 0x152F: case 0x1530: case 0x1531: case 0x1537: case 0x1538: case 0x1539: case 0x153A: case 0x153B: case 0x153C: case 0x153D: case 0x153E: case 0x153F: case 0x1540: case 0x1541: case 0x1542: case 0x1543: case 0x1544: case 0x170B: case 0x170C: case 0x170F: case 0x1710: case 0x1711: case 0x1712: case 0x1713: case 0x1714: case 0x1715: case 0x1716: case 0x1717: case 0x1718: case 0x1719: case 0x171A: case 0x171B: case 0x171C: case 0x175D: case 0x175E: case 0x175F: case 0x1760: case 0x1761: case 0x1762: case 0x1763: case 0x1764: case 0x1765: case 0x1766: case 0x1767: case 0x1768: case 0x1914: case 0x1915: case 0x1B74: case 0x1B75: case 0x1EFD: case 0x1EFE: case 0x1EFF: case 0x1F00: case 0x1F01: case 0x1F02: case 0x1F03: case 0x1F04: case 0x1F7B: case 0x1F7C: case 0x1F9F: case 0x1FA0: case 0x1FA1: case 0x1FA2: case 0x1F7B: case 0x1F7C: case 0x1FA1: case 0x1FA1: case 0x1FFD: case 0x1FFE: sfx(Q66R, 0x023E, 0x00); setHue(usedon, Q61R); break; } return(0x00); }
void Shorty::unPaint(int loc) { qDebug(shorty_Main()) << "No color for you!" << loc; keyList.replace(loc,data->getCommandAt(getLocation())); updateText(); }
void PolymerizationProcess::pushNewBend(Subunit* aSubunit, double aBendAngle) { Point& aRefPoint(aSubunit->subunitPoint); Point aPoint; Bend aBend; while(aBendAngle > M_PI) { aBendAngle -= 2*M_PI; } while(aBendAngle < -M_PI) { aBendAngle += 2*M_PI; } aBend.angle = aBendAngle; if(aRefPoint.z < theOriZ) { aBendAngle = aBendAngle-M_PI; } double x(aRefPoint.x); if(x > theMaxX) { x = x-theMaxX; } else if(x < theMinX) { x = x-theMinX; } else { x = 0; } double currX[3]; currX[0] = aRefPoint.x-theMinX-((theMaxX-theMinX)/2); currX[1] = aRefPoint.y-theOriY; currX[2] = aRefPoint.z-theOriZ; double tmpDcm[9]; getOneDcm(tmpDcm); rotXrotY(tmpDcm, atan2(currX[1],sqrt(x*x+currX[2]*currX[2])), -atan2(x,-currX[2])); getCylinderDcm(-aBendAngle, -aBendAngle-CylinderYaw, aBend.cylinderDcm); getSphereDcm(0, -SphereYaw, aBend.sphereDcm); double aDcm[9]; if(getLocation(aRefPoint.x) == CYLINDER) { getCylinderDcm(0, M_PI-aBendAngle, aDcm); dcmXdcm(aDcm, tmpDcm, aDcm); pinStep(currX, aBend.cylinderDcm, aDcm, aBend.dcm); } else { getSphereDcm(0, M_PI-aBendAngle, aDcm); dcmXdcm(aDcm, theInitSphereDcm, aDcm); dcmXdcm(aDcm, tmpDcm, aDcm); pinStep(currX, aBend.sphereDcm, aDcm, aBend.dcm); } dcmXdcm(aBend.dcm, aDcm, aBend.dcm); aPoint.x = aRefPoint.x + theMonomerLength*aBend.dcm[0]; aPoint.y = aRefPoint.y + theMonomerLength*aBend.dcm[1]; aPoint.z = aRefPoint.z + theMonomerLength*aBend.dcm[2]; aSubunit->targetPoints.push_back(aPoint); aSubunit->targetBends.push_back(aBend); }
// returns the delta position between the current location and the previous location in OpenGL coordinates DPoint CATouch::getDelta() const { return ccpSub(getLocation(), getPreviousLocation()); }
void PassingChallengePlay::executePlay(VisionData* vision, RobocupStrategyData* rsd) { RobotIndex r0=ROBOT0; RobotIndex r1=ROBOT1; Pair ballLoc=getBallLocation(*vision); ///---- for(RobotIndex robotID = r0; robotID < ROBOT2; robotID++){ Pair robotLoc=getLocation(robotID,*vision,rsd->getSystemParams()); Pair otherPos; int side; if(robotID == r0){ otherPos=getLocation(r1,*vision,rsd->getSystemParams()); side=side0; }else{ otherPos=getLocation(r0,*vision,rsd->getSystemParams()); side=side1; } if((ballLoc.getX() > rsd->getSystemParams().field.HALF_LINE && robotID==r0) || (ballLoc.getX() < rsd->getSystemParams().field.HALF_LINE && robotID==r1)) { //ball on our side if(friendlyHasPossession(robotID,rsd->getSystemParams())){ //go kick if(-robotLoc.getY()*side > (rsd->getSystemParams().field.SPLIT_LINE + .5f)){ //we're there, kick rsd->getDestination(robotID)->setKick(KICK_PASS); }else{ //not there yet. rsd->getDestination(robotID)->setDribble(DRIBBLE_DEFAULT); rsd->getDestination(robotID)->setVerticalDribble(V_DRIBBLE_DEFAULT); //head across float backup=.3f; if(robotID == r1){ rsd->getDestination(robotID)->setPos(rsd->getSystemParams().field.HALF_LINE - backup,-side*1.0f); rsd->getDestination(robotID)->setRotation(0.0f); }else{ rsd->getDestination(robotID)->setPos(rsd->getSystemParams().field.HALF_LINE + backup,-side*1.0f); rsd->getDestination(robotID)->setRotation(PI); } } }else{ //go grab ball if(!rsd->getStrategyModule().getSkillSet(robotID)->getSkill(AcquirePossessionSkill::skillNum)->isInitialized()){ rsd->getStrategyModule().getSkillSet(robotID)->getSkill(AcquirePossessionSkill::skillNum)->initialize(); } rsd->getStrategyModule().getSkillSet(robotID)->getSkill(AcquirePossessionSkill::skillNum)->run(); rsd->getDestination(robotID)->setDribble(DRIBBLE_DEFAULT); rsd->getDestination(robotID)->setVerticalDribble(V_DRIBBLE_DEFAULT); rsd->getDestination(robotID)->setKick(NO_KICK); rsd->getDestination(robotID)->setSpeed(GOALIE_SPEED); } }else{ int side; if(ballLoc.getY() > rsd->getSystemParams().field.SPLIT_LINE){ side=1; }else{ side=-1; } if(robotID == r0){ side0=side; }else{ side1=side; } float backup=.5f; if(robotID == r1){ rsd->getDestination(robotID)->setPos(rsd->getSystemParams().field.HALF_LINE - backup,otherPos.getY()); rsd->getDestination(robotID)->setRotation(0.0f); }else{ rsd->getDestination(robotID)->setPos(rsd->getSystemParams().field.HALF_LINE + backup,otherPos.getY()); rsd->getDestination(robotID)->setRotation(PI); } } } /* Pair aggressorPos(getLocation(robot1ID,*vision,rsd->getSystemParams())); Pair creatorPos(getLocation(robot2ID,*vision,rsd->getSystemParams())); Pair ballLoc(getBallLocation(*vision)); if(ballLoc.getX() > rsd->getSystemParams().field.HALF_LINE) { turn = LEFT; } else { turn = RIGHT; } if(state == KICK_RECEIVE && readTimer() > MAX_ELAPSED_TIME) { state = MOVE; uninitializeSkills(); } if(state == MOVE && dist(getLocation(robot1ID,*vision,rsd->getSystemParams()),dest) < DISTANCE_THRESHOLD && dist(getLocation(robot2ID,*vision,rsd->getSystemParams()),dest1) < DISTANCE_THRESHOLD && (friendlyHasPossession(rsd->getRobotByPosition(AGGRESSOR),rsd->getSystemParams(),*vision, *rsd,true) || friendlyHasPossession(rsd->getRobotByPosition(CREATOR),rsd->getSystemParams(),*vision, *rsd,true))) { state = ROTATE; uninitializeSkills(); } if(state == ROTATE && ABS(getRotation(robot1ID,*vision,rsd->getSystemParams()) - PI < ROTATION_THRESHOLD && ABS(getRotation(robot2ID,*vision,rsd->getSystemParams()) - 0) < ROTATION_THRESHOLD) && (friendlyHasPossession(rsd->getRobotByPosition(AGGRESSOR),rsd->getSystemParams(),*vision, *rsd,true) || friendlyHasPossession(rsd->getRobotByPosition(CREATOR),rsd->getSystemParams(),*vision, *rsd,true))) { state = KICK_RECEIVE; uninitializeSkills(); } if(turn == LEFT) { if(state == KICK_RECEIVE) { kickSkill1->initialize(KICK_PASS); receiveSkill2->initialize(0.5f,dest1,false,true); kickSkill1->run(); receiveSkill2->run(); turn = RIGHT; dest.set(POINT_X,-POINT_Y); dest1.set(-POINT_X,-POINT_Y); startTimer(); rsd->setMessage(robot1ID,"Kicking"); rsd->setMessage(robot2ID,"Receiving"); } if(state == MOVE) { rsd->getDestination(robot1ID)->setDribble(DRIBBLE_DEFAULT); rsd->getDestination(robot1ID)->setVerticalDribble(V_DRIBBLE_DEFAULT); if(getBallLocation(*vision).getX() < rsd->getSystemParams().field.HALF_LINE) { rsd->getDestination(robot2ID)->setPos(dest1); rsd->setMessage(robot2ID,"Moving to Receive"); } rsd->setMessage(robot1ID,"Moving with Ball to pass."); if(!friendlyHasPossession(rsd->getRobotByPosition(AGGRESSOR),rsd->getSystemParams(),*vision, *rsd,true)) { acquireSkill1->initialize(); acquireSkill1->run(); } else { rsd->getDestination(robot1ID)->setPos(dest); } } if(state == ROTATE) { rsd->getDestination(robot2ID)->setRotation(angleBetween(creatorPos,aggressorPos)); rsd->setMessage(robot2ID,"Rotating to receive"); rsd->setMessage(robot1ID,"Rotating to kick"); if(!friendlyHasPossession(rsd->getRobotByPosition(AGGRESSOR),rsd->getSystemParams(),*vision, *rsd,true)) { acquireSkill1->initialize(); acquireSkill1->run(); rsd->getDestination(robot2ID)->setDribble(DRIBBLE_DEFAULT); rsd->getDestination(robot2ID)->setVerticalDribble(V_DRIBBLE_DEFAULT); rsd->getDestination(robot1ID)->setKick(NO_KICK); } else { rotateSkill1->initialize(dest1); rotateSkill1->run(); } } } else { if(state == KICK_RECEIVE) { kickSkill2->initialize(KICK_PASS); receiveSkill1->initialize(0.5f,dest,false,true); kickSkill2->run(); receiveSkill1->run(); turn = LEFT; dest.set(POINT_X,POINT_Y); dest1.set(-POINT_X,POINT_Y); startTimer(); rsd->setMessage(robot2ID,"Kicking"); rsd->setMessage(robot1ID,"Receiving"); } if(state == MOVE) { if(getBallLocation(*vision).getX() > rsd->getSystemParams().field.HALF_LINE) { rsd->getDestination(robot1ID)->setDribble(DRIBBLE_DEFAULT); rsd->getDestination(robot1ID)->setVerticalDribble(V_DRIBBLE_DEFAULT); rsd->getDestination(robot1ID)->setPos(dest); rsd->setMessage(robot1ID,"Moving to Receive"); } rsd->setMessage(robot2ID,"Moving with Ball to pass."); if(!friendlyHasPossession(rsd->getRobotByPosition(CREATOR),rsd->getSystemParams(),*vision, *rsd,true)) { acquireSkill2->initialize(); acquireSkill2->run(); rsd->getDestination(robot2ID)->setDribble(DRIBBLE_DEFAULT); rsd->getDestination(robot2ID)->setVerticalDribble(V_DRIBBLE_DEFAULT); rsd->getDestination(robot2ID)->setKick(NO_KICK); } else { rsd->getDestination(robot2ID)->setPos(dest1); } } if(state == ROTATE) { rsd->getDestination(robot1ID)->setRotation(angleBetween(creatorPos,aggressorPos)); rsd->setMessage(robot1ID,"Rotating to receive"); rsd->setMessage(robot2ID,"Rotating to kick"); if(!friendlyHasPossession(rsd->getRobotByPosition(CREATOR),rsd->getSystemParams(),*vision, *rsd,true)) { acquireSkill2->initialize(); acquireSkill2->run(); } else { rotateSkill2->initialize(dest1); rotateSkill2->run(); } } } */ }
bool MetaballEnemy::intersect(Vector3f &pos){ return ((pos - getLocation()).norm() < this->radius); }
//=============================================================================== //Execute the skill. This is the main part of the skill, where you tell the //robot how to perform the skill. void SupplementThreeManSkill::execute() { ///If not initialized, dont do anything! if(!initialized) { return; } //if the ball is close enough to defenisve players, move next to //the defensive player that is closer to the ball //since he'll become the aggresor and move upfield. //this way we can slide in and form the defensive wall immediately. Pair ballLoc = getBallLocation(*currentVisionData); Pair robotLoc = getLocation(robotID, *currentVisionData, *sp); RobotIndex closeDefensiveID = NO_ROBOT; float closestDistance; RobotIndex tempID; float tempDistance; tempID = strategy->getCurrentRoboCupFrame()->getRobotByPosition(BLOCKER); if(tempID != NO_ROBOT) { closestDistance = getLocation(tempID, *currentVisionData, *sp).distanceTo(ballLoc); closeDefensiveID = tempID; } tempID = strategy->getCurrentRoboCupFrame()->getRobotByPosition(DEFENDER); if(tempID != NO_ROBOT) { tempDistance = getLocation(tempID, *currentVisionData, *sp).distanceTo(ballLoc); if(tempDistance < closestDistance) { closestDistance = tempDistance; closeDefensiveID = tempID; } if(closeDefensiveID == strategy->getCurrentRoboCupFrame()->getRobotByPosition(BLOCKER)) closeDefensiveID = strategy->getCurrentRoboCupFrame()->getRobotByPosition(DEFENDER); } tempID = strategy->getCurrentRoboCupFrame()->getRobotByPosition(SPECIAL_OP_DEFENDER); if(tempID != NO_ROBOT) { tempDistance = getLocation(tempID, *currentVisionData, *sp).distanceTo(ballLoc); if(tempDistance < closestDistance) { closestDistance = tempDistance; closeDefensiveID = tempID; } if(closeDefensiveID == strategy->getCurrentRoboCupFrame()->getRobotByPosition(BLOCKER)) closeDefensiveID = strategy->getCurrentRoboCupFrame()->getRobotByPosition(SPECIAL_OP_DEFENDER); } //if closest defensive player //a.) exists //b.) within tolerance, then go to side of him if(closestDistance < 3.0f*sp->general.PLAYER_RADIUS) { Pair defensivePlayer = getLocation(closeDefensiveID, *currentVisionData, *sp); if(defensivePlayer.getY() > sp->field.SPLIT_LINE) { command->setYPos(defensivePlayer.getY() + sp->general.PLAYER_RADIUS + 0.02f); } else { command->setYPos(defensivePlayer.getY() - sp->general.PLAYER_RADIUS - 0.02f); } command->setXPos(defensivePlayer.getX()); command->setRotation(angleBetween(robotLoc, ballLoc)); } //else acquire the ball else { Skill* skillHandle = skillSet->getSkill(AcquirePossessionSkill::skillNum); if(!skillHandle->isInitialized()) skillHandle->initialize(); skillHandle->run(); } }
// Real-C #include "ENGINE.hpp" TRIGGER( message , "fireInTheHole" )(obj sender, list args) { int Q62A = getObjType(this); loc Q61U = loc( getLocation(this) ); list Q67G; getMobsInRange(Q67G, Q61U, 0x01); if(numInList(Q67G) != 0x00) { obj target = Q67G[0x00]; } if(!hasObjVar(this, "disarmed")) { switch(Q62A) { case 0x10FC: doLocAnimation(Q61U, 0x10FE, 0x02, 0x10, 0x00, 0x00); break; case 0x1110: doLocAnimation(Q61U, 0x1111, 0x02, 0x10, 0x00, 0x00); break; default: break; } int Q4GH = dice(0x03, 0x0F); loseHP(target, Q4GH); } return(0x01); }
int Q5CG = Q4FU + 0x01; loc Q5C0 = loc( Q4FS, Q4FT, Q5CG ); loc trapLocation = loc( 0x14CB, 0x023C, 0x00 ); list Q5DQ; if(!hasObjVar(this, "working")) { bark(this, "SOUND EFFECT"); callback(this, 0x05, 0x01); int Q64U = teleport(this, Q5C0); messageToRange(trapLocation, 0x0A, "disarm", Q5DQ); setObjVar(this, "working", 0x01); } return(0x01); } TRIGGER( callback , 0x01 )() { int Q4FS = getX(getLocation(this)); int Q4FT = getY(getLocation(this)); int Q4FU = getZ(getLocation(this)); int Q5CG = Q4FU - 0x01; loc Q5C0 = loc( Q4FS, Q4FT, Q5CG ); bark(this, "SOUND EFFECT"); bark(this, "returning"); if(hasObjVar(this, "working")) { removeObjVar(this, "working"); } int Q64U = teleport(this, Q5C0); return(0x01); }
std::string Scanner::escape(const char *str, int len, char quote_type) const { std::string output; output.reserve(len); if (quote_type == '\'') { for (int i = 0; i < len; i++) { unsigned char ch = str[i]; if (ch == '\\') { if (++i < len) { switch (str[i]) { case '\\': output += "\\"; break; case '\'': output += '\''; break; default: { output += ch; output += str[i]; break; } } } else { assert(false); output += ch; } } else { output += ch; } } } else { for (int i = 0; i < len; i++) { unsigned char ch = str[i]; if (ch == '\\') { if (++i < len) { switch (str[i]) { case 'n': output += '\n'; break; case 't': output += '\t'; break; case 'r': output += '\r'; break; case 'v': output += '\v'; break; case 'f': output += '\f'; break; case 'e': output += '\033'; break; case '\\': output += '\\'; break; case '$': output += '$'; break; case '"': case '`': if (str[i] != quote_type) { output += '\\'; } output += str[i]; break; case 'x': case 'X': { if (isxdigit(str[i+1])) { std::string shex; shex += str[++i]; // 0th hex digit if (isxdigit(str[i+1])) { shex += str[++i]; // 1st hex digit } output += strtol(shex.c_str(), nullptr, 16); } else { output += ch; output += str[i]; } break; } case 'u': { // Unicode escape sequence // "\u{123456}" if (str[i+1] != '{') { // BC for "\u1234" passthrough output += ch; output += str[i]; break; } bool valid = true; auto start = str + i + 2; auto closebrace = strchr(start, '}'); if (closebrace > start) { for (auto p = start; p < closebrace; ++p) { if (!isxdigit(*p)) { valid = false; break; } } } else { valid = false; } auto fatal = [this](const char *msg) { auto loc = getLocation(); return ParseTimeFatalException( loc->file, loc->r.line0, "%s", msg); }; if (!valid) { throw fatal("Invalid UTF-8 codepoint escape sequence"); } std::string codepoint(start, closebrace - start); char *end = nullptr; int32_t uchar = strtol(codepoint.c_str(), &end, 16); if ((end && *end) || (uchar > 0x10FFFF)) { throw fatal( "Invalid UTF-8 codepoint escape sequence: " "Codepoint too large"); } if (uchar <= 0x0007F) { output += (char)uchar; } else if (uchar <= 0x007FF) { output += (char)(0xC0 | ( uchar >> 6 )); output += (char)(0x80 | ( uchar & 0x3F)); } else if (uchar <= 0x00FFFF) { output += (char)(0xE0 | ( uchar >> 12 )); output += (char)(0x80 | ((uchar >> 6) & 0x3F)); output += (char)(0x80 | ( uchar & 0x3F)); } else if (uchar <= 0x10FFFF) { output += (char)(0xF0 | ( uchar >> 18 )); output += (char)(0x80 | ((uchar >> 12) & 0x3F)); output += (char)(0x80 | ((uchar >> 6) & 0x3F)); output += (char)(0x80 | ( uchar & 0x3F)); } else { not_reached(); assert(false); } i += codepoint.size() + 2 /* strlen("{}") */; break; }
void decideMove (HunterView gameState) { printf("at start of code\n"); fflush(stdout); Graph g = newGraph(); char *locations[] = { "AL", "AM", "AT", "BA", "BI", "BE", "BR", "BO", "BU", "BC", "BD", "CA", "CG", "CD", "CF", "CO", "CN", "DU", "ED", "FL", "FR", "GA", "GW", "GE", "GO", "GR", "HA", "JM", "KL", "LE", "LI", "LS", "LV", "LO", "MA", "MN", "MR", "MI", "MU", "NA", "NP", "NU", "PA", "PL", "PR", "RO", "SA", "SN", "SR", "SJ", "SO", "ST", "SW", "SZ", "TO", "VA", "VR", "VE", "VI", "ZA", "ZU", "NS", "EC", "IS", "AO", "BB", "MS", "TS", "IO", "AS", "BS", "C?", "S?", "HI", "D1", "D2", "D3", "D4", "D5", "TP" }; int round = getRound(gameState); PlayerID id = getCurrentPlayer(gameState); LocationID move = getLocation(gameState, id); printf("the original loc is %d and health %d\n",move,getHealth(gameState,id)); char * msg = ""; printf("initialised all variables\n"); fflush(stdout); //set initial locations if (round - id == 0) { if (id == PLAYER_LORD_GODALMING) {move = CASTLE_DRACULA; msg = "camping";} else if (id == PLAYER_DR_SEWARD) move = BELGRADE; else if (id == PLAYER_VAN_HELSING) move = STRASBOURG; else if (id == PLAYER_MINA_HARKER) move = MADRID; registerBestPlay(locations[move], msg); destroyGraph(g); return; } printf("done initial moves\n"); fflush(stdout); //below code will throw errors if LG is killed //if (id == PLAYER_LORD_GODALMING) { registerBestPlay("CD","I'm camping MAN!!!"); return; } srand (time(NULL)); int path[NUM_MAP_LOCATIONS]; int amtLocs = 0; LocationID * adj = connectedLocations(&amtLocs, getLocation(gameState, id), id, round, ANY, g); LocationID target = UNKNOWN_LOCATION; int camper = 0, i, j; printf("setting up connected locs etc\n"); fflush(stdout); // check for campers // if the current player is camping, then the player // will stay camping and ai will return for (i = 0; i < NUM_HUNTERS; i++) { if (getLocation(gameState, i) == CASTLE_DRACULA) { camper = 1; if (id == i) { registerBestPlay("CD", "Staying camping"); destroyGraph(g); free(adj); return; } } } if (!camper) { //if no camper and hunter is shortest dist to castle dracula, move towards castle dracula int hunterDist[NUM_HUNTERS] = {UNKNOWN_LOCATION,UNKNOWN_LOCATION,UNKNOWN_LOCATION,UNKNOWN_LOCATION}; int closestHunter = PLAYER_LORD_GODALMING; for (i = PLAYER_LORD_GODALMING; i < NUM_HUNTERS; i++) { hunterDist[i] = findShortestPath(getLocation(gameState, i), CASTLE_DRACULA, path, ANY, round); if (hunterDist[i] == -1) hunterDist[i] = 1000; //-1 is when there is no path, so don't want him to be shortest if ((hunterDist[closestHunter] > hunterDist[i]) || (hunterDist[closestHunter] == UNKNOWN_LOCATION)) closestHunter = i; } if (closestHunter == id) move = path[1]; } else { LocationID draculaLoc[TRAIL_SIZE]; getHistory (gameState, PLAYER_DRACULA, draculaLoc); //updates Dracula trail for (i = TRAIL_SIZE - 1; i >= 0 ; i--) //locations newer in trail will override older ones target = dracTarget(draculaLoc, i); //we have any useful info on his location... if (target != UNKNOWN_LOCATION) { //Note: Dracula cannot visit any location currently in his trail - hunters should not visit target itself! int pathLen = findShortestPath(getLocation(gameState, id), target, path, ANY, round); //success is any number not -1 if (getLocation(gameState, id) != target && pathLen != -1) { //path found, and not at rest on target (Drac's trail) if (path[1] != target) move = path[1]; //don't move into Dracula's trail (see note above) else move = adj[rand() % amtLocs]; for (i = 0; i < TRAIL_SIZE ; i++) if (path[1] == dracTarget(draculaLoc, i)) move = adj[rand() % amtLocs]; } else move = adj[rand() % amtLocs]; } else { //prevents doubling up of hunters when making a random move, since Dracula 404 int occupied = 0, newLoc = UNKNOWN_LOCATION; move = adj[rand() % amtLocs]; for (j = 0; j < NUM_HUNTERS; j++) if (move == getLocation(gameState, j)) occupied = 1; if (occupied) { for (i = 0; i < amtLocs; i++) { occupied = 0; for (j = 0; j < NUM_HUNTERS; j++) if (adj[i] == getLocation(gameState, j)) occupied = 1; if (!occupied) {newLoc = i; break;} } } if (newLoc != UNKNOWN_LOCATION) move = adj[newLoc]; } } if (target != UNKNOWN_LOCATION) printf("*Moving from %s (%d) to target %s (%d) via %s (%d)*\n", locations[getLocation(gameState, id)], getLocation(gameState, id), locations[target], target, locations[move], move); else printf("*No target - moving from %s (%d) to %s (%d)*\n", locations[getLocation(gameState, id)], getLocation(gameState, id), locations[move], move); if (isLegalMove(gameState, id, move, round, g)) registerBestPlay(locations[move], ""); else { printf("ERROR: Location is invalid! Registering default rest move..."); registerBestPlay(locations[getLocation(gameState, id)], ""); } destroyGraph(g); free(adj); }