Exemple #1
0
bool Vehicle::Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 vehicleId, uint32 team, const CreatureData *data)
{
    SetMap(map);
    SetPhaseMask(phaseMask,false);

    CreatureInfo const *cinfo = sObjectMgr.GetCreatureTemplate(Entry);
    if(!cinfo)
    {
        sLog.outErrorDb("Creature entry %u does not exist.", Entry);
        return false;
    }

    Object::_Create(guidlow, Entry, HIGHGUID_VEHICLE);

    if(!UpdateEntry(Entry, team, data))
        return false;

    if(!vehicleId)
    {
        CreatureDataAddon const *cainfo = GetCreatureAddon();
        if(!cainfo)
            return false;
        vehicleId = cainfo->vehicle_id;
    }
    if(!SetVehicleId(vehicleId))
        return false;

    LoadCreaturesAddon();

    m_regenHealth = false;
    m_creation_time = getMSTime();

    SetFloatValue(UNIT_FIELD_HOVERHEIGHT, 1.0f);
    //RemoveMonsterMoveFlag(MONSTER_MOVE_WALK);

    //Notify the map's instance data.
    //Only works if you create the object in it, not if it is moves to that map.
    //Normally non-players do not teleport to other maps.
    if(map->IsDungeon() && ((InstanceMap*)map)->GetInstanceData())
    {
        ((InstanceMap*)map)->GetInstanceData()->OnCreatureCreate(this);
    }
    
    if(m_vehicleInfo->m_powerType == POWER_TYPE_STEAM)
    {
        setPowerType(POWER_ENERGY);
        SetMaxPower(POWER_ENERGY, 100);
        SetPower(POWER_ENERGY, 100);
    }
    else if(m_vehicleInfo->m_powerType == POWER_TYPE_PYRITE)
    {
        setPowerType(POWER_ENERGY);
        SetMaxPower(POWER_ENERGY, 50);
        SetPower(POWER_ENERGY, 50);
    }
    else
    {
        for (uint32 i = 0; i < MAX_VEHICLE_SPELLS; ++i)
        {
            if(!GetVehicleData()->v_spells[i])
                continue;
            SpellEntry const *spellInfo = sSpellStore.LookupEntry(GetVehicleData()->v_spells[i]);
            if(!spellInfo)
                continue;

            if(spellInfo->powerType == POWER_MANA)
                break;

            if(spellInfo->powerType == POWER_ENERGY)
            {
                setPowerType(POWER_ENERGY);
                SetMaxPower(POWER_ENERGY, 100);
                SetPower(POWER_ENERGY, 100);
                break;
            }
        }
    }
    SetHealth(GetMaxHealth());
    InstallAllAccessories();
    return true;
}
Exemple #2
0
bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool current)
{
    m_loading = true;

    uint32 ownerid = owner->GetGUIDLow();

    QueryResult result;

    if (petnumber)
        // known petnumber entry                  0   1      2(?)   3        4      5    6           7     8     9        10         11       12            13      14        15              16
        result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, slot, name, renamed, curhealth, curmana, curhappiness, abdata, savetime, CreatedBySpell, PetType "
            "FROM character_pet WHERE owner = '%u' AND id = '%u'",
            ownerid, petnumber);
    else if (current)
        // current pet (slot 0)                   0   1      2(?)   3        4      5    6           7     8     9        10         11       12            13      14        15              16
        result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, slot, name, renamed, curhealth, curmana, curhappiness, abdata, savetime, CreatedBySpell, PetType "
            "FROM character_pet WHERE owner = '%u' AND slot = '%u'",
            ownerid, PET_SAVE_AS_CURRENT);
    else if (petentry)
        // known petentry entry (unique for summoned pet, but non unique for hunter pet (only from current or not stabled pets)
        //                                        0   1      2(?)   3        4      5    6           7     8     9        10         11       12           13       14        15              16
        result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, slot, name, renamed, curhealth, curmana, curhappiness, abdata, savetime, CreatedBySpell, PetType "
            "FROM character_pet WHERE owner = '%u' AND entry = '%u' AND (slot = '%u' OR slot > '%u') ",
            ownerid, petentry, PET_SAVE_AS_CURRENT, PET_SAVE_LAST_STABLE_SLOT);
    else
        // any current or other non-stabled pet (for hunter "call pet")
        //                                        0   1      2(?)   3        4      5    6           7     8     9        10         11       12            13      14        15              16
        result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, slot, name, renamed, curhealth, curmana, curhappiness, abdata, savetime, CreatedBySpell, PetType "
            "FROM character_pet WHERE owner = '%u' AND (slot = '%u' OR slot > '%u') ",
            ownerid, PET_SAVE_AS_CURRENT, PET_SAVE_LAST_STABLE_SLOT);

    if (!result)
    {
        m_loading = false;
        return false;
    }

    Field* fields = result->Fetch();

    // update for case of current pet "slot = 0"
    petentry = fields[1].GetUInt32();
    if (!petentry)
        return false;

    uint32 summon_spell_id = fields[15].GetUInt32();
    SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(summon_spell_id);

    bool is_temporary_summoned = spellInfo && spellInfo->GetDuration() > 0;

    // check temporary summoned pets like mage water elemental
    if (current && is_temporary_summoned)
        return false;

    PetType pet_type = PetType(fields[16].GetUInt8());
    if (pet_type == HUNTER_PET)
    {
        CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(petentry);
        if (!creatureInfo || !creatureInfo->isTameable(owner->CanTameExoticPets()))
            return false;
    }

    uint32 pet_number = fields[0].GetUInt32();

    if (current && owner->IsPetNeedBeTemporaryUnsummoned())
    {
        owner->SetTemporaryUnsummonedPetNumber(pet_number);
        return false;
    }

    Map* map = owner->GetMap();
    uint32 guid = sObjectMgr->GenerateLowGuid(HIGHGUID_PET);
    if (!Create(guid, map, owner->GetPhaseMask(), petentry, pet_number))
        return false;

    float px, py, pz;
    owner->GetClosePoint(px, py, pz, GetObjectSize(), PET_FOLLOW_DIST, GetFollowAngle());
    Relocate(px, py, pz, owner->GetOrientation());

    if (!IsPositionValid())
    {
        sLog->outError("Pet (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)",
            GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY());
        return false;
    }

    setPetType(pet_type);
    setFaction(owner->getFaction());
    SetUInt32Value(UNIT_CREATED_BY_SPELL, summon_spell_id);

    CreatureTemplate const* cinfo = GetCreatureInfo();
    if (cinfo->type == CREATURE_TYPE_CRITTER)
    {
        map->AddToMap(this->ToCreature());
        return true;
    }

    m_charmInfo->SetPetNumber(pet_number, IsPermanentPetFor(owner));

    SetDisplayId(fields[3].GetUInt32());
    SetNativeDisplayId(fields[3].GetUInt32());
    uint32 petlevel = fields[4].GetUInt16();
    SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
    SetName(fields[8].GetString());

    switch (getPetType())
    {
        case SUMMON_PET:
            petlevel = owner->getLevel();

            SetUInt32Value(UNIT_FIELD_BYTES_0, 0x800); // class = mage
            SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
                                                            // this enables popup window (pet dismiss, cancel)
            break;
        case HUNTER_PET:
            SetUInt32Value(UNIT_FIELD_BYTES_0, 0x02020100); // class = warrior, gender = none, power = focus
            SetSheath(SHEATH_STATE_MELEE);
            SetByteFlag(UNIT_FIELD_BYTES_2, 2, fields[9].GetBool() ? UNIT_CAN_BE_ABANDONED : UNIT_CAN_BE_RENAMED | UNIT_CAN_BE_ABANDONED);

            SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
                                                            // this enables popup window (pet abandon, cancel)
            SetMaxPower(POWER_HAPPINESS, GetCreatePowers(POWER_HAPPINESS));
            SetPower(POWER_HAPPINESS, fields[12].GetUInt32());
            setPowerType(POWER_FOCUS);
            break;
        default:
            if (!IsPetGhoul())
                sLog->outError("Pet have incorrect type (%u) for pet loading.", getPetType());
            break;
    }

    SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); // cast can't be helped here
    SetCreatorGUID(owner->GetGUID());

    InitStatsForLevel(petlevel);
    SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, fields[5].GetUInt32());

    SynchronizeLevelWithOwner();

    SetReactState(ReactStates(fields[6].GetUInt8()));
    SetCanModifyStats(true);

    if (getPetType() == SUMMON_PET && !current)              //all (?) summon pets come with full health when called, but not when they are current
        SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
    else
    {
        uint32 savedhealth = fields[10].GetUInt32();
        uint32 savedmana = fields[11].GetUInt32();
        if (!savedhealth && getPetType() == HUNTER_PET)
            setDeathState(JUST_DIED);
        else
        {
            SetHealth(savedhealth > GetMaxHealth() ? GetMaxHealth() : savedhealth);
            SetPower(POWER_MANA, savedmana > GetMaxPower(POWER_MANA) ? GetMaxPower(POWER_MANA) : savedmana);
        }
    }

    // set current pet as current
    // 0=current
    // 1..MAX_PET_STABLES in stable slot
    // PET_SAVE_NOT_IN_SLOT(100) = not stable slot (summoning))
    if (fields[7].GetUInt8())
    {
        SQLTransaction trans = CharacterDatabase.BeginTransaction();
        trans->PAppend("UPDATE character_pet SET slot = '%u' WHERE owner = '%u' AND slot = '%u' AND id <> '%u'",
            PET_SAVE_NOT_IN_SLOT, ownerid, PET_SAVE_AS_CURRENT, m_charmInfo->GetPetNumber());
        trans->PAppend("UPDATE character_pet SET slot = '%u' WHERE owner = '%u' AND id = '%u'",
            PET_SAVE_AS_CURRENT, ownerid, m_charmInfo->GetPetNumber());
        CharacterDatabase.CommitTransaction(trans);
    }

    // Send fake summon spell cast - this is needed for correct cooldown application for spells
    // Example: 46584 - without this cooldown (which should be set always when pet is loaded) isn't set clientside
    // TODO: pets should be summoned from real cast instead of just faking it?
    if (summon_spell_id)
    {
        WorldPacket data(SMSG_SPELL_GO, (8+8+4+4+2));
        data.append(owner->GetPackGUID());
        data.append(owner->GetPackGUID());
        data << uint8(0);
        data << uint32(summon_spell_id);
        data << uint32(256); // CAST_FLAG_UNKNOWN3
        data << uint32(0);
        owner->SendMessageToSet(&data, true);
    }

    owner->SetMinion(this, true);
    map->AddToMap(this->ToCreature());

    InitTalentForLevel();                                   // set original talents points before spell loading

    uint32 timediff = uint32(time(NULL) - fields[14].GetUInt32());
    _LoadAuras(timediff);

    // load action bar, if data broken will fill later by default spells.
    if (!is_temporary_summoned)
    {
        m_charmInfo->LoadPetActionBar(fields[13].GetString());

        _LoadSpells();
        InitTalentForLevel();                               // re-init to check talent count
        _LoadSpellCooldowns();
        LearnPetPassives();
        InitLevelupSpellsForLevel();
        CastPetAuras(current);
    }

    CleanupActionBar();                                     // remove unknown spells from action bar after load

    sLog->outDebug(LOG_FILTER_PETS, "New Pet has guid %u", GetGUIDLow());

    owner->PetSpellInitialize();

    if (owner->GetGroup())
        owner->SetGroupUpdateFlag(GROUP_UPDATE_PET);

    owner->SendTalentsInfoData(true);

    if (getPetType() == HUNTER_PET)
    {
        result = CharacterDatabase.PQuery("SELECT genitive, dative, accusative, instrumental, prepositional FROM character_pet_declinedname WHERE owner = '%u' AND id = '%u'", owner->GetGUIDLow(), GetCharmInfo()->GetPetNumber());

        if (result)
        {
            delete m_declinedname;
            m_declinedname = new DeclinedName;
            Field* fields2 = result->Fetch();
            for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
            {
                m_declinedname->name[i] = fields2[i].GetString();
            }
        }
    }

    //set last used pet number (for use in BG's)
    if (owner->GetTypeId() == TYPEID_PLAYER && isControlled() && !isTemporarySummoned() && (getPetType() == SUMMON_PET || getPetType() == HUNTER_PET))
        owner->ToPlayer()->SetLastPetNumber(pet_number);

    m_loading = false;

    return true;
}
int main()
{

  int i;

  printf("hello world\n");

  printf("start of out_test\n");
  Wait(SEC_1);

  // initialize
  if (!OutputInit())
    printf("output init returned false\n");

  ResetAllTachoCounts(OUT_ABCD);

//  OutputSetType(OUT_A, DEVICE_TYPE_TACHO);
//  OutputSetType(OUT_B, DEVICE_TYPE_TACHO);
//  OutputSetType(OUT_C, DEVICE_TYPE_MINITACHO);
//  OutputSetTypes(DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO);

  SetPower(OUT_A, 90);
  SetSpeed(OUT_B, 40);
  SetPower(OUT_C, 60);
  SetPower(OUT_D, -60);
  On(OUT_ALL);

  bool isBusy = false;
  for(i=0; i < 10; i++)
  {
    printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
    printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));
    printf("OUT_C: %d %d %d\n", MotorRotationCount(OUT_C), MotorTachoCount(OUT_C), MotorActualSpeed(OUT_C));
    printf("OUT_D: %d %d %d\n", MotorRotationCount(OUT_D), MotorTachoCount(OUT_D), MotorActualSpeed(OUT_D));
    Wait(SEC_1);

    isBusy = MotorBusy(OUT_ALL);
    printf("Any output isBusy = %d\n", (byte)isBusy);
  }
//  Wait(SEC_5);

  printf("Float(OUT_ALL)\n");
  Float(OUT_ALL);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("ResetAllTachoCounts(OUT_ALL)\n");
  ResetAllTachoCounts(OUT_ALL);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));
  printf("OUT_C: %d %d %d\n", MotorRotationCount(OUT_C), MotorTachoCount(OUT_C), MotorActualSpeed(OUT_C));
  printf("OUT_D: %d %d %d\n", MotorRotationCount(OUT_D), MotorTachoCount(OUT_D), MotorActualSpeed(OUT_D));

  printf("Wait(SEC_1)\n");
  Wait(SEC_1);

  printf("RotateMotorNoWait(OUT_AB, 75, 7200)\n");
  RotateMotorNoWait(OUT_AB, 75, 7200);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  isBusy = MotorBusy(OUT_AB);
  printf("A or B isBusy = %d\n", (byte)isBusy);

  printf("Wait(SEC_20)\n");
  Wait(SEC_20);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("resetting all tacho counters\n");
  ResetAllTachoCounts(OUT_ALL);

  printf("Wait(SEC_1)\n");
  Wait(SEC_1);

  printf("OnForSync(OUT_AB, SEC_10, 75)\n");
  OnForSync(OUT_AB, SEC_10, 75);

  for(i=0; i < 10; i++)
  {
    printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
    printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

    isBusy = MotorBusy(OUT_AB);
    printf("A or B isBusy = %d\n", (byte)isBusy);

    isBusy = MotorBusy(OUT_CD);
    printf("C or D isBusy = %d\n", (byte)isBusy);

    Wait(SEC_1);
  }

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  // synchronized motor movement without tacho or time limitation
  printf("OnFwdSync(OUT_AB, 75)\n");
  OnFwdSync(OUT_AB, 75);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("Off(OUT_AB)\n");
  Off(OUT_AB); // stop with braking

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("Wait(SEC_1)\n");
  Wait(SEC_1);

/*
 *  Turn ratio is how tight you turn and to what direction you turn
 *   - 0 value is moving straight forward
 *   - Negative values turns to the left
 *   - Positive values turns to the right
 *   - Value -100 stops the left motor
 *   - Value +100 stops the right motor
 *   - Values less than -100 makes the left motor run the opposite
 *     direction of the right motor (Spin)
 *   - Values greater than +100 makes the right motor run the opposite
 *     direction of the left motor (Spin)
 */

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("OnFwdSyncEx(OUT_AB, 75, -20, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 75, -20, RESET_NONE);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("OnFwdSync(OUT_AB, 50, -50, RESET_NONE)");
  OnFwdSyncEx(OUT_AB, 50, -50, RESET_NONE);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("OnFwdSync(OUT_AB, 20, -100, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 20, -100, RESET_NONE);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("OnFwdSync(OUT_AB, 80, -150, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 80, -150, RESET_NONE);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("OnFwdSync(OUT_AB, 30, -200, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 30, -200, RESET_NONE);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("Off(OUT_AB)\n");
  Off(OUT_AB);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("ResetAllTachoCounts(OUT_AB)\n");
  ResetAllTachoCounts(OUT_AB);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  // a blocking version of RotateMotor (function call does not return
  // until the motor rotation is complete)
  printf("RotateMotor(OUT_AB, 75, 1800)");
  RotateMotor(OUT_AB, 75, 1800); // 5 rotations

  // by the time the function above returns the motors are no longer busy
  isBusy = MotorBusy(OUT_AB);
  printf("A or B isBusy = %d\n", isBusy);

  // this call starts the motors running Forward without regulation or
  // synchronization and the function call does not return until the
  // specified amount of time has elapsed.
  // at the end of the elapsed time the motors are stopped with braking.
  printf("OnFor(OUT_AB, SEC_3)\n");
  OnFor(OUT_AB, SEC_3);

  printf("Off(OUT_AB)\n");
  Off(OUT_AB);

  printf("Wait(SEC_5)\n");
  Wait(SEC_5);

  OutputClose();
  OutputExit();
  printf("end of out_test\n");

  return 0;
}
Exemple #4
0
int CMQOMaterial::SetParams( int srcno, D3DXVECTOR4 srcsceneamb, char* srcchar, int srcleng )
{
	//"肌色" col(1.000 0.792 0.651 1.000) dif(0.490) amb(0.540) emi(0.530) spc(0.020) power(0.00)


//DbgOut( L"check!!!: mqomat : SetParams : %d, %s, %d\r\n", srcno, srcchar, srcleng );

	materialno = srcno;

	sceneamb = srcsceneamb;//!!!!!!!!!!!!!!!!!

	char pat[12][20] = 
	{
		"col(",
		"dif(",
		"amb(",
		"emi(",
		"spc(",
		"power(",
		"tex(",
		"alpha(",
		"bump(",
		"shader(",
		"vcol(",
		"\"" //!!!tex, alpha, bumpよりも後でないとだめ。
	};

	int pos = 0;
	int stepnum;
	int ret;

	while( pos < srcleng ){
		while( (pos < srcleng) &&  
		( (*(srcchar + pos) == ' ') || (*(srcchar + pos) == '\t') )
		){
		pos++;
		}

		int cmp;
		int patno, patleng;

		int isfind = 0;

		for( patno = 0; patno < 12; patno++ ){
			if( isfind == 1 )
				break;

			patleng = (int)strlen( pat[patno] );
			if( srcleng - pos >= patleng ){
				cmp = strncmp( pat[patno], srcchar + pos, patleng );
				if( cmp == 0 ){
					isfind = 1;
					switch( patno ){
					case 0:
						ret = SetCol( srcchar, pos, srcleng, &stepnum );
						if( ret )
							return ret;
						break;
					case 1:
						ret = SetDif( srcchar, pos, srcleng, &stepnum );
						if( ret )
							return ret;
						break;
					case 2:
						ret = SetAmb( srcchar, pos, srcleng, &stepnum );
						if( ret )
							return ret;
						break;
					case 3:
						ret = SetEmi( srcchar, pos, srcleng, &stepnum );
						if( ret )
							return ret;
						break;
					case 4:
						ret = SetSpc( srcchar, pos, srcleng, &stepnum );
						if( ret )
							return ret;
						break;
					case 5:
						ret = SetPower( srcchar, pos, srcleng, &stepnum );
						if( ret )
							return ret;
						break;
					case 6:
						ret = SetTex( srcchar, pos, srcleng, &stepnum );
						if( ret )
							return ret;
						break;
					case 7:
						ret = SetAlpha( srcchar, pos, srcleng, &stepnum );
						if( ret )
							return ret;
						break;
					case 8:
						ret = SetBump( srcchar, pos, srcleng, &stepnum );
						if( ret )
							return ret;
						break;
					case 9:
						ret = SetShader( srcchar, pos, srcleng, &stepnum );
						if( ret )
							return ret;
						break;
					case 10:
						ret = SetVcolFlag( srcchar, pos, srcleng, &stepnum );
						if( ret )
							return ret;
						break;
					case 11:
						//DbgOut( L"MQOMaterial : SetParams : SetName %d\r\n", pos );
						ret = SetName( srcchar, pos, srcleng, &stepnum );
						if( ret )
							return ret;
						break;
					default:
						_ASSERT( 0 );
						return 1;
						break;
					}

				}
			}
		}

		if( isfind == 1 ){
			pos += stepnum;
		}else{
			pos++;
		}

	}

	ret = ConvParamsTo3F();
	_ASSERT( !ret );


	return 0;
}
Exemple #5
0
// TODO: Move stat mods code to pet passive auras
bool Guardian::InitStatsForLevel(uint8 petlevel)
{
    CreatureTemplate const* cinfo = GetCreatureInfo();
    ASSERT(cinfo);

    SetLevel(petlevel);

    //Determine pet type
    PetType petType = MAX_PET_TYPE;
    if (isPet() && m_owner->GetTypeId() == TYPEID_PLAYER)
    {
        if ((m_owner->getClass() == CLASS_WARLOCK)
            || (m_owner->getClass() == CLASS_SHAMAN)        // Fire Elemental
            || (m_owner->getClass() == CLASS_DEATH_KNIGHT)) // Risen Ghoul
            petType = SUMMON_PET;
        else if (m_owner->getClass() == CLASS_HUNTER)
        {
            petType = HUNTER_PET;
            m_unitTypeMask |= UNIT_MASK_HUNTER_PET;
        }
        else
            sLog->outError("Unknown type pet %u is summoned by player class %u", GetEntry(), m_owner->getClass());
    }

    uint32 creature_ID = (petType == HUNTER_PET) ? 1 : cinfo->Entry;

    SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool));

    SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(petlevel*50));

    SetAttackTime(BASE_ATTACK, BASE_ATTACK_TIME);
    SetAttackTime(OFF_ATTACK, BASE_ATTACK_TIME);
    SetAttackTime(RANGED_ATTACK, BASE_ATTACK_TIME);

    SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0f);

    //scale
    CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cinfo->family);
    if (cFamily && cFamily->minScale > 0.0f && petType == HUNTER_PET)
    {
        float scale;
        if (getLevel() >= cFamily->maxScaleLevel)
            scale = cFamily->maxScale;
        else if (getLevel() <= cFamily->minScaleLevel)
            scale = cFamily->minScale;
        else
            scale = cFamily->minScale + float(getLevel() - cFamily->minScaleLevel) / cFamily->maxScaleLevel * (cFamily->maxScale - cFamily->minScale);

        SetFloatValue(OBJECT_FIELD_SCALE_X, scale);
    }

    // Resistance
    for (uint8 i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
        SetModifierValue(UnitMods(UNIT_MOD_RESISTANCE_START + i), BASE_VALUE, float(cinfo->resistance[i]));

    //health, mana, armor and resistance
    PetLevelInfo const* pInfo = sObjectMgr->GetPetLevelInfo(creature_ID, petlevel);
    if (pInfo)                                      // exist in DB
    {
        SetCreateHealth(pInfo->health);
        if (petType != HUNTER_PET) //hunter pet use focus
            SetCreateMana(pInfo->mana);

        if (pInfo->armor > 0)
            SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor));

        for (uint8 stat = 0; stat < MAX_STATS; ++stat)
            SetCreateStat(Stats(stat), float(pInfo->stats[stat]));
    }
    else                                            // not exist in DB, use some default fake data
    {
        // remove elite bonuses included in DB values
        CreatureBaseStats const* stats = sObjectMgr->GetCreatureBaseStats(petlevel, cinfo->unit_class);
        SetCreateHealth(stats->BaseHealth[cinfo->expansion]);
        SetCreateMana(stats->BaseMana);

        SetCreateStat(STAT_STRENGTH, 22);
        SetCreateStat(STAT_AGILITY, 22);
        SetCreateStat(STAT_STAMINA, 25);
        SetCreateStat(STAT_INTELLECT, 28);
        SetCreateStat(STAT_SPIRIT, 27);
    }

    SetBonusDamage(0);
    switch (petType)
    {
        case SUMMON_PET:
        {
            //the damage bonus used for pets is either fire or shadow damage, whatever is higher
            uint32 fire  = m_owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE);
            uint32 shadow = m_owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW);
            uint32 val  = (fire > shadow) ? fire : shadow;
            SetBonusDamage(int32 (val * 0.15f));
            //bonusAP += val * 0.57;

            SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)));
            SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)));

            //SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, float(cinfo->attackpower));
            break;
        }
        case HUNTER_PET:
        {
            SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32(sObjectMgr->GetXPForLevel(petlevel)*PET_XP_FACTOR));
            //these formula may not be correct; however, it is designed to be close to what it should be
            //this makes dps 0.5 of pets level
            SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)));
            //damage range is then petlevel / 2
            SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)));
            //damage is increased afterwards as strength and pet scaling modify attack power
            break;
        }
        default:
        {
            switch (GetEntry())
            {
                case 510: // mage Water Elemental
                {
                    SetBonusDamage(int32(m_owner->SpellBaseDamageBonus(SPELL_SCHOOL_MASK_FROST) * 0.33f));
                    break;
                }
                case 1964: //force of nature
                {
                    if (!pInfo)
                        SetCreateHealth(30 + 30*petlevel);
                    float bonusDmg = m_owner->SpellBaseDamageBonus(SPELL_SCHOOL_MASK_NATURE) * 0.15f;
                    SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel * 2.5f - (petlevel / 2) + bonusDmg));
                    SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel * 2.5f + (petlevel / 2) + bonusDmg));
                    break;
                }
                case 15352: //earth elemental 36213
                {
                    if (!pInfo)
                        SetCreateHealth(100 + 120*petlevel);
                    SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)));
                    SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)));
                    break;
                }
                case 15438: //fire elemental
                {
                    if (!pInfo)
                    {
                        SetCreateHealth(40*petlevel);
                        SetCreateMana(28 + 10*petlevel);
                    }
                    SetBonusDamage(m_owner->SpellBaseDamageBonus(SPELL_SCHOOL_MASK_FIRE) * 0.5f);
                    SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel * 4 - petlevel));
                    SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel * 4 + petlevel));
                    break;
                }
                case 19668: // Shadowfiend
                {
                    if (!pInfo)
                    {
                        SetCreateMana(28 + 10*petlevel);
                        SetCreateHealth(28 + 30*petlevel);
                    }
                    int32 bonus_dmg = (int32(m_owner->SpellBaseDamageBonus(SPELL_SCHOOL_MASK_SHADOW)* 0.3f));
                    SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float((petlevel * 4 - petlevel) + bonus_dmg));
                    SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float((petlevel * 4 + petlevel) + bonus_dmg));

                    break;
                }
                case 19833: //Snake Trap - Venomous Snake
                {
                    SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float((petlevel / 2) - 25));
                    SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float((petlevel / 2) - 18));
                    break;
                }
                case 19921: //Snake Trap - Viper
                {
                    SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel / 2 - 10));
                    SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel / 2));
                    break;
                }
                case 29264: // Feral Spirit
                {
                    if (!pInfo)
                        SetCreateHealth(30*petlevel);

                    float dmg_multiplier = 0.3f;
                    if (m_owner->GetAuraEffect(63271, 0)) // Glyph of Feral Spirit
                        dmg_multiplier = 0.6f;

                    SetBonusDamage(int32(m_owner->GetTotalAttackPowerValue(BASE_ATTACK) * dmg_multiplier));

                    // 14AP == 1dps, wolf's strike speed == 2s so dmg = basedmg + AP / 14 * 2
                    SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float((petlevel * 4 - petlevel) + (m_owner->GetTotalAttackPowerValue(BASE_ATTACK) * dmg_multiplier * 2 / 14)));
                    SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float((petlevel * 4 + petlevel) + (m_owner->GetTotalAttackPowerValue(BASE_ATTACK) * dmg_multiplier * 2 / 14)));

                    SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(m_owner->GetArmor()) * 0.35f);  //  Bonus Armor (35% of player armor)
                    SetModifierValue(UNIT_MOD_STAT_STAMINA, BASE_VALUE, float(m_owner->GetStat(STAT_STAMINA)) * 0.3f);  //  Bonus Stamina (30% of player stamina)
                    if (!HasAura(58877))//prevent apply twice for the 2 wolves
                        AddAura(58877, this);//Spirit Hunt, passive, Spirit Wolves' attacks heal them and their master for 150% of damage done.
                    break;
                }
                case 31216: // Mirror Image
                {
                    SetBonusDamage(int32(m_owner->SpellBaseDamageBonus(SPELL_SCHOOL_MASK_FROST) * 0.33f));
                    SetDisplayId(m_owner->GetDisplayId());
                    if (!pInfo)
                    {
                        SetCreateMana(28 + 30*petlevel);
                        SetCreateHealth(28 + 10*petlevel);
                    }
                    break;
                }
                case 27829: // Ebon Gargoyle
                {
                    if (!pInfo)
                    {
                        SetCreateMana(28 + 10*petlevel);
                        SetCreateHealth(28 + 30*petlevel);
                    }
                    SetBonusDamage(int32(m_owner->GetTotalAttackPowerValue(BASE_ATTACK) * 0.5f));
                    SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)));
                    SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)));
                    break;
                }
            }
            break;
        }
    }

    UpdateAllStats();

    SetFullHealth();
    SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
    return true;
}
bool ofxCrazyradio::init() {
  int ret = libusb_init(&ctx_);
//  std::cout << "libusb_init: " << ret << std::endl;
//  libusb_set_debug(ctx_, 3);
  
  bool found = false;
  libusb_device **list;
  ssize_t count = libusb_get_device_list(ctx_, &list);
//  std::cout << "libusb_get_device_list: " << count << std::endl;
  for (int i = 0; i < count; i++) {
    struct libusb_device_descriptor desc;
    ret = libusb_get_device_descriptor(list[i], &desc);
    if (desc.idVendor == 0x1915 && desc.idProduct == 0x7777) {
      found = true;
      ret = libusb_open(list[i], &handle_);
//      std::cout << "libusb_open: " << ret << std::endl;
      
//      std::cout << "version: " << std::hex << desc.bcdDevice << std::dec << std::endl;
      
//      uint8_t string_desc[256];
//      ret = libusb_get_string_descriptor_ascii(handle_, desc.iManufacturer, string_desc, 256);
//      std::cout << "libusb_get_string_descriptor_ascii: " << ret << std::endl;
//      std::cout << string_desc << std::endl;
//
      
//      for (int n = 0; n < desc.bNumConfigurations; n++) {
//        libusb_config_descriptor *config_desc;
//        const libusb_interface_descriptor *inter_desc;
//        const libusb_endpoint_descriptor *ep_desc;
//        const libusb_interface *inter;
//        libusb_get_config_descriptor(list[i], n, &config_desc);
//        std::cout << "config: " << (int)config_desc->bConfigurationValue << std::endl;
//        std::cout << "bNumInterfaces: " << (int)config_desc->bNumInterfaces << std::endl;
//        for (int i = 0; i < (int)config_desc->bNumInterfaces; i++) {
//          inter = &config_desc->interface[i];
//          std::cout << "  num_altsetting: " << inter->num_altsetting << std::endl;
//          for (int j = 0; j < inter->num_altsetting; j++) {
//            inter_desc = &inter->altsetting[j];
//            std::cout << "    Interface number: " << (int)inter_desc->bInterfaceNumber << std::endl;
//            std::cout << "    number of endpoint: " << (int)inter_desc->bNumEndpoints << std::endl;
//            for (int k = 0; k < (int)inter_desc->bNumEndpoints; k++) {
//              ep_desc = &inter_desc->endpoint[k];
//              std::cout << "     desc type: " << (int)ep_desc->bDescriptorType << std::endl;
//              std::cout << "     ep address: " << (int)ep_desc->bEndpointAddress << std::endl;
//              std::cout << "     attributes: " << std::hex << (int)ep_desc->bmAttributes << std::dec << std::endl;
//            }
//          }
//        }
//      }
      
//      ret = libusb_kernel_driver_active(handle_, 0);
//      std::cout << "libusb_kernel_driver_active: " << ret << std::endl;
      
      ret = libusb_claim_interface(handle_, 0);
//      std::cout << "libusb_claim_interface: " << ret << std::endl;
      
      libusb_set_configuration(handle_, 1);
      SetDataRate(DR_250KPS);
      SetChannel(2);
      arc_ = -1;
      SetContCarrier(false);
      uint8_t address[] = "\xe7\xe7\xe7\xe7\xe7";
      SetAddress(address);
      SetPower(P_0DBM);
      SetArc(3);
      SetArdBytes(32);
      break;
    }
  }
  libusb_free_device_list(list, 1);
  
  return found;
}
Exemple #7
0
bool Creature::LoadFromDB(uint32 guid, QueryResult *result, uint32 InstanceId)
{
    bool external = (result != NULL);
    if (!external)
        //                                0    1     2            3            4            5             6               7           8                  9                  10                 11          12        13            14           15             16
        result = sDatabase.PQuery("SELECT `id`,`map`,`position_x`,`position_y`,`position_z`,`orientation`,`spawntimesecs`,`spawndist`,`spawn_position_x`,`spawn_position_y`,`spawn_position_z`,`curhealth`,`curmana`,`respawntime`,`DeathState`,`MovementType`,`auras` "
            "FROM `creature` LEFT JOIN `creature_respawn` ON ((`creature`.`guid`=`creature_respawn`.`guid`) AND (`creature_respawn`.`instance` = '%u')) WHERE `creature`.`guid` = '%u'", InstanceId, guid);

    if(!result)
    {
        sLog.outErrorDb("Creature (GUID: %u) not found in table `creature`, can't load. ",guid);
        return false;
    }

    Field *fields = result->Fetch();

    uint32 stored_guid = guid;
    if (InstanceId != 0) guid = objmgr.GenerateLowGuid(HIGHGUID_UNIT);
    SetInstanceId(InstanceId);

    if(!Create(guid,fields[1].GetUInt32(),fields[2].GetFloat(),fields[3].GetFloat(),
        fields[4].GetFloat(),fields[5].GetFloat(),fields[0].GetUInt32()))
    {
        if (!external) delete result;
        return false;
    }

    m_DBTableGuid = stored_guid;

    if(GetCreatureInfo()->rank > 0)
        this->m_corpseDelay *= 3;                           //if creature is elite, then remove corpse later

    SetHealth(fields[11].GetUInt32());
    SetPower(POWER_MANA,fields[12].GetUInt32());

    m_respawnradius = fields[7].GetFloat();
    respawn_cord[0] = fields[8].GetFloat();
    respawn_cord[1] = fields[9].GetFloat();
    respawn_cord[2] = fields[10].GetFloat();

    m_respawnDelay = fields[6].GetUInt32();
    m_deathState = (DeathState)fields[14].GetUInt32();
    if(m_deathState == JUST_DIED)                           // Dont must be set to JUST_DEAD, see Creature::setDeathState JUST_DIED -> CORPSE promoting.
    {
        sLog.outErrorDb("Creature (GUIDLow: %u Entry: %u ) in wrong state: JUST_DEAD (1). State set to ALIVE.",GetGUIDLow(),GetEntry());
        m_deathState = ALIVE;
    }
    else
    if(m_deathState < ALIVE || m_deathState > DEAD)
    {
        sLog.outErrorDb("Creature (GUIDLow: %u Entry: %u ) in wrong state: %d. State set to ALIVE.",GetGUIDLow(),GetEntry(),m_deathState);
        m_deathState = ALIVE;
    }

    m_respawnTime  = (time_t)fields[13].GetUInt64();
    if(m_respawnTime > time(NULL))                          // not ready to respawn
        m_deathState = DEAD;
    else                                                    // ready to respawn
    {
        m_respawnTime = 0;
        sDatabase.PExecute("DELETE FROM `creature_respawn` WHERE `guid` = '%u' AND `instance` = '%u'", m_DBTableGuid, GetInstanceId());
    }

    {
        uint32 mtg = fields[15].GetUInt32();
        if(mtg < MAX_DB_MOTION_TYPE)
            m_defaultMovementType = MovementGeneratorType(mtg);
        else
        {
            m_defaultMovementType = IDLE_MOTION_TYPE;
            sLog.outErrorDb("Creature (GUID: %u ID: %u) have wrong movement generator type value %u, ignore and set to IDLE.",guid,GetEntry(),mtg);
        }
    }

    if(!external) delete result;

    LoadFlagRelatedData();
    
    AIM_Initialize();
    return true;
}
Exemple #8
0
bool Vehicle::LoadFromDB(uint32 guid, Map *map)
{
    CreatureData const* data = objmgr.GetCreatureData(guid);

    if(!data)
    {
        sLog.outErrorDb("Creature (GUID: %u) not found in table `creature`, can't load. ",guid);
        return false;
    }

    uint32 id = 0;
    if(const CreatureInfo *cInfo = objmgr.GetCreatureTemplate(data->id))
        id = cInfo->VehicleId;
    if(!id || !sVehicleStore.LookupEntry(id))
        return false;

    m_DBTableGuid = guid;
    if (map->GetInstanceId() != 0) guid = objmgr.GenerateLowGuid(HIGHGUID_VEHICLE);

    uint16 team = 0;
    if(!Create(guid,map,data->phaseMask,data->id,id,team,data->posX,data->posY,data->posZ,data->orientation,data))
        return false;

    //We should set first home position, because then AI calls home movement
    SetHomePosition(data->posX,data->posY,data->posZ,data->orientation);

    m_respawnradius = data->spawndist;

    m_respawnDelay = data->spawntimesecs;
    m_isDeadByDefault = data->is_dead;
    m_deathState = m_isDeadByDefault ? DEAD : ALIVE;

    m_respawnTime  = objmgr.GetCreatureRespawnTime(m_DBTableGuid,GetInstanceId());
    if(m_respawnTime > time(NULL))                          // not ready to respawn
    {
        m_deathState = DEAD;
        if(canFly())
        {
            float tz = GetMap()->GetHeight(data->posX,data->posY,data->posZ,false);
            if(data->posZ - tz > 0.1)
                Relocate(data->posX,data->posY,tz);
        }
    }
    else if(m_respawnTime)                                  // respawn time set but expired
    {
        m_respawnTime = 0;
        objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),0);
    }

    uint32 curhealth = data->curhealth;
    if(curhealth)
    {
        curhealth = uint32(curhealth*_GetHealthMod(GetCreatureInfo()->rank));
        if(curhealth < 1)
            curhealth = 1;
    }

    SetHealth(m_deathState == ALIVE ? curhealth : 0);
    SetPower(POWER_MANA,data->curmana);

    // checked at creature_template loading
    m_defaultMovementType = MovementGeneratorType(data->movementType);

    m_creatureData = data;

    return true;
}
Exemple #9
0
void RadarDopplerClass::ChangeMode (int newMode)
{
	int maxIdx;
	int wasGround = FALSE;
	
	/*--------------------------------*/
	/* Save the old mode just in case */
	/*--------------------------------*/
	
	//prevMode = mode;
	
	//static float oldseekerElCenter =0.0f;
	
	if (prevMode == SAM || prevMode == TWS
		|| prevMode == RWS || prevMode == LRS|| prevMode == VS)
		oldseekerElCenter = seekerElCenter;//me123
	
	if (prevMode == GM || prevMode == GMT || prevMode == SEA)
	{
		DropGMTrack();
		wasGround = TRUE;
		seekerElCenter = oldseekerElCenter;

		// MD -- 20040228: clear and GM SP related pseudo waypoint and revert to STPT nav
		if (IsSet(SP_STAB))
			ClearFlagBit(SP_STAB);
		if (GMSPWaypt())
		{
			// RV - Biker - Should fix CTD 
			// if (SimDriver.GetPlayerAircraft())
			//	SimDriver.GetPlayerAircraft()->FCC->SetStptMode(FireControlComputer::FCCWaypoint);
			//	SimDriver.GetPlayerAircraft()->FCC->waypointStepCmd = 127;
			AircraftClass *playerAC = SimDriver.GetPlayerAircraft();
			if (playerAC) {
				playerAC->FCC->SetStptMode(FireControlComputer::FCCWaypoint);
				playerAC->FCC->waypointStepCmd = 127;
			}
			SetGMSPWaypt(NULL);
		}
	}
	
	// MD -- 20040118: clean up on mode change from TWS
	// sfr: removes JB hack. Seems to cure memory corruption somehow...
#define NEW_TWS_CHECK 1
#if NEW_TWS_CHECK
	if (newMode != TWS && TWSTrackDirectory){
		TWSTrackDirectory = TWSTrackDirectory->Purge();
	}
#else
	if (newMode != TWS && !F4IsBadReadPtr(TWSTrackDirectory, sizeof(RadarDopplerClass::TWSTrackList))){
		TWSTrackDirectory = TWSTrackDirectory->Purge();
	}
#endif

	// Drop SAM target on mode switch (except when bugging)
	if (mode == SAM && newMode != STT){
		//ClearSensorTarget(); me123 status ok no keep the target on mode switch
	}
	
	isOn = TRUE;
	if (TheHud){
		TheHud->HudData.Clear(HudDataType::RadarSlew);
		TheHud->HudData.Clear(HudDataType::RadarBoresight);
		TheHud->HudData.Clear(HudDataType::RadarVertical);
	}
	
	/*-------------------------------------*/
	/* Set the parameters for the new mode */
	/*-------------------------------------*/
	
   	switch (newMode)
	{
	case RWS:   // Range while search
	case LRS:
		prevMode = mode = (RadarMode)newMode;
		fovStepCmd = 0;	//MI
		SetFlagBit(SpaceStabalized);
		beamWidth = radarData->BeamHalfAngle;
		displayRange = 20.0F;
		curRangeIdx = airRangeIdx;
		displayRange = rangeScales[curRangeIdx];
		curAzIdx = rwsAzIdx;
		azScan = rwsAzs[curAzIdx];
		curBarIdx = rwsBarIdx;
		bars = rwsBars[curBarIdx];
		barWidth = APG68_BAR_WIDTH;
		ClearFlagBit(VerticalScan);
		SetFlagBit(HorizontalScan);
		scanDir  = ScanFwd;
		
		if (!g_bAntElevKnobFix)
			//me123 set the old el center
			seekerElCenter = min ( max (oldseekerElCenter, -MAX_ANT_EL + elScan), MAX_ANT_EL - elScan);
		else
			seekerElCenter = AntElevKnob();

		SetEmitting (TRUE);
		if (wasGround)
		{
            cursorX = cursorY = 0.0F;
		}
		
		// Go to sam if there is a lock
		//MI added check for RWS mode. If this isn't here, we never make it out of RWS/SAM
		//mode. This makes sure that if we switch to RWS, we go to SAM, which is right I think.
		if (lockedTarget  && (mode == RWS || mode == LRS))
		{
            ChangeMode (SAM);
		}
		break;
		
	case TWS:  // Track while scan
		prevMode = mode = TWS;
		fovStepCmd = 0;
		
		SetFlagBit(SpaceStabalized);
		curRangeIdx = airRangeIdx;
		displayRange = rangeScales[curRangeIdx];

		// MD -- 20040124: updated TWS mode gets its own specific scan patterns
		curAzIdx = twsAzIdx = lastTwsAzIdx;
		azScan = twsAzs[curAzIdx];
		displayAzScan = twsAzs[curAzIdx];

		curBarIdx = twsBarIdx = lastTwsBarIdx;
		bars = twsBars[curBarIdx];

		beamWidth = radarData->BeamHalfAngle;
		// 2001-02-21 MODIFIED BY S.G. IN TWS, APG68_BAR_WIDTH IS 3.2 (2.2 * 1.4545455)
		//			barWidth = APG68_BAR_WIDTH * 1.3f;
		barWidth = APG68_BAR_WIDTH * 1.4545455f;
		ClearFlagBit(VerticalScan);
		SetFlagBit(HorizontalScan);
		scanDir  = ScanFwd;

		if (!g_bAntElevKnobFix)
			//me123 set the old el center
			seekerElCenter = min ( max (oldseekerElCenter, -MAX_ANT_EL + elScan), MAX_ANT_EL - elScan);
		else
			if (!lockedTarget)
				seekerElCenter = AntElevKnob();

		SetEmitting (TRUE);
		if (wasGround)
		{
            cursorX = cursorY = 0.0F;
		}

		break;
		
	case VS:   // Velocity search
		mode = VS;
		displayRange = velScales[vsVelIdx];
		curAzIdx = vsAzIdx;
		curBarIdx = vsBarIdx;
		SetFlagBit(SpaceStabalized);
		beamWidth = radarData->BeamHalfAngle;
		azScan = rwsAzs[curAzIdx];
		curBarIdx = rwsBarIdx;
		bars = rwsBars[curBarIdx];
		barWidth = APG68_BAR_WIDTH;
		ClearFlagBit(VerticalScan);
		SetFlagBit(HorizontalScan);
		scanDir  = ScanFwd;

		if (!g_bAntElevKnobFix)
			//me123 set the old el center
			seekerElCenter = min ( max (oldseekerElCenter, -MAX_ANT_EL + elScan), MAX_ANT_EL - elScan);
		else
			seekerElCenter = AntElevKnob();

		SetEmitting (TRUE);
		if (wasGround)
		{
            cursorX = cursorY = 0.0F;
		}
		break;
		
	case ACM_30x20:  // Auto Aquisition - 30x20 FOV
		mode = ACM_30x20;
		seekerAzCenter = 0.0F * DTR;
		seekerElCenter = -5.0F * DTR;
		ClearFlagBit(SpaceStabalized);
		beamWidth = radarData->BeamHalfAngle;
		azScan = 15.0F * DTR - beamWidth;
		elScan = 10.0F * DTR - beamWidth;
		displayRange = 10.0F;
		bars = 4;
		barWidth = APG68_BAR_WIDTH;
		ClearFlagBit(VerticalScan);
		SetFlagBit(HorizontalScan);
		scanDir  = ScanFwd;
		// me123 status ok. We don't always want to stop emitting when we change to an acm mode from a non acm radar mode
		// we just wanna transfer to acm and get the symbolgy for that. 
		//MI but that's how it works in the Block 50 Viper, so let's change it back
		if (prevMode == ACM_30x20 || prevMode == ACM_BORE || prevMode == ACM_10x60 || prevMode == ACM_SLEW || lockedTarget)
            SetEmitting (TRUE);
		else
            SetEmitting (FALSE);
		
		prevMode = mode;
		break;
		
	case ACM_BORE: // Auto Aquisition - Boresight
		mode = ACM_BORE;
		//        ClearSensorTarget(); me123 status ok. don't ever drop the target just becourse we are enterign acm bore. it probaly not possible enyway to enter bore with a lock.
		ClearFlagBit(SpaceStabalized);
		beamWidth = radarData->BeamHalfAngle;
		azScan = 0.0F * DTR;
		displayRange = 10.0F;
		elScan = 0.0F * DTR;
		seekerAzCenter = 0.0F;
		seekerElCenter = -3.0F*DTR;//me123 from 0.00.0F;
		beamAz = 0.0F;
		beamEl = 0.0F;
		bars = 1;
		barWidth = APG68_BAR_WIDTH;
		ClearFlagBit(VerticalScan);
		SetFlagBit(HorizontalScan);
		scanDir  = ScanNone;
		if (TheHud)
		{
            TheHud->HudData.Set(HudDataType::RadarBoresight);
		}
		if (prevMode == ACM_30x20 || prevMode == ACM_BORE || prevMode == ACM_10x60 || prevMode == ACM_SLEW || lockedTarget)
            SetEmitting (TRUE);
		else
            SetEmitting (FALSE);
		
		prevMode = ACM_BORE;
		break;
		
	case ACM_10x60: // Auto Aquisition - Vertical Search
		mode = ACM_10x60;
		//        ClearSensorTarget(); me123 status ok. don't ever drop the target just becourse we are enterign acm
		seekerAzCenter = 0.0F * DTR;
		seekerElCenter = 23.0F * DTR;
		ClearFlagBit(SpaceStabalized);
		beamWidth = radarData->BeamHalfAngle;
		displayRange = 10.0F;
		elScan = 30.0F * DTR - beamWidth;
		azScan = 5.0F * DTR - beamWidth;
		bars = -4;  //JPG 28 Apr 04 - was -3  ????
		barWidth = APG68_BAR_WIDTH;
		SetFlagBit(VerticalScan);
		ClearFlagBit(HorizontalScan);
		scanDir  = ScanFwd;
		if (TheHud)
		{
            TheHud->HudData.Set(HudDataType::RadarVertical);
		}
		if (prevMode == ACM_30x20 || prevMode == ACM_BORE || prevMode == ACM_10x60 || prevMode == ACM_SLEW || lockedTarget)
            SetEmitting (TRUE);
		else
            SetEmitting (FALSE);
		
		prevMode = mode;
		break;
		
	case ACM_SLEW:  // Auto Aquisition - Slewable, 20x60 FOV
		mode = ACM_SLEW;
		//        ClearSensorTarget(); me123 status ok. don't ever drop the target just becourse we are enterign acm
		SetFlagBit(SpaceStabalized);
		beamWidth = radarData->BeamHalfAngle;
		displayRange = 10.0F;
		azScan = 30.0F * DTR - beamWidth;
		elScan = 10.0F * DTR - beamWidth;
		bars = 4;
		barWidth = APG68_BAR_WIDTH;
		ClearFlagBit(VerticalScan);
		SetFlagBit(HorizontalScan);
		scanDir  = ScanFwd;
		if (TheHud)
		{
            TheHud->HudData.Set(HudDataType::RadarSlew);
		}
		if (prevMode == ACM_30x20 || prevMode == ACM_BORE || prevMode == ACM_10x60 || prevMode == ACM_SLEW || lockedTarget)
            SetEmitting (TRUE);
		else
            SetEmitting (FALSE);
		if (wasGround)
		{
            cursorX = cursorY = 0.0F;
		}
		
		prevMode = mode;
		break;
		
	case STT:
		prevMode = mode = STT;
		ClearFlagBit(SpaceStabalized);
		beamWidth = radarData->BeamHalfAngle;
		azScan = 0.0F * DTR;
		bars = 1;
		barWidth = APG68_BAR_WIDTH;
		ClearFlagBit(VerticalScan);
		SetFlagBit(HorizontalScan);
		scanDir  = ScanNone;
		SetEmitting (TRUE);
		break;
		
	case SAM:
		//MI
		if(mode == RWS)
			prevMode = RWS;
		else if(mode == LRS)
			prevMode = LRS;
		mode = SAM;
		fovStepCmd = 0;	//MI
		subMode = SAM_AUTO_MODE;
		displayAzScan = rwsAzs[curAzIdx];
		if (lockedTarget)
		{
			//MI
            //prevMode = RWS;
            CalcSAMAzLimit();
		}
		SetEmitting (TRUE);
		break;
		
	case GM:
	case GMT:
	case SEA:
		fovStepCmd = 0;
		
		mode = (RadarMode)newMode;
		// New to GM radar, start in 40 mile scope
		if (prevMode != GM && prevMode != GMT && prevMode != SEA)
		{
			curRangeIdx = gmRangeIdx;
			displayRange = rangeScales[curRangeIdx];
			tdisplayRange = displayRange * NM_TO_FT;
			groundMapRange = tdisplayRange * 0.5F;
			flags &= SP;
			SetFlagBit(NORM);
			if(WasAutoAGRange && g_bRealisticAvionics && g_bAGRadarFixes)
				SetFlagBit(AutoAGRange);
			if(g_bRealisticAvionics && g_bAGRadarFixes)
			{
				if(mode == GM || mode == SEA)
					curAzIdx = gmAzIdx;
				else
					curAzIdx = gmtAzIdx;				 
				azScan = rwsAzs[curAzIdx];
			}
			else
				azScan = 60.0F * DTR;
			barWidth = APG68_BAR_WIDTH;
			ClearFlagBit(VerticalScan);
			SetFlagBit(HorizontalScan);
			scanDir  = ScanFwd;
			SetGMScan();
		}
		else
		{
			// Reuse current range, within limits of course
			if (flags & (DBS1 | DBS2) || mode == GMT || mode == SEA)
			{
				maxIdx = NUM_RANGES - 3;
			}
			else
			{
				maxIdx = NUM_RANGES - 2;
			}
			
			if (mode != GM)
			{
				ClearFlagBit(DBS1);
				ClearFlagBit(DBS2);
			}
			
			curRangeIdx += rangeChangeCmd;
			if (curRangeIdx > maxIdx)
				curRangeIdx = maxIdx;
			else if (curRangeIdx < 0)
				curRangeIdx = 0;
			
			gmRangeIdx = curRangeIdx;
		}
		//MI make sure we're at the correct range
		if(g_bRealisticAvionics && g_bAGRadarFixes)
		{
			displayRange = rangeScales[curRangeIdx];
  	         tdisplayRange = displayRange * NM_TO_FT;
			 SetGMScan();
			 //Set our gain
			 InitGain = TRUE;
		}
		// GMT starts in snowplow
		//      if (mode == GMT)
		//         flags |= SP;//me123 no don't start in SP
		SetEmitting (TRUE);
		prevMode = mode;
		break;
	case STBY:
		mode = STBY;
		SetEmitting(FALSE);
		break;
		//MI		
	case AGR:
		mode = AGR;
		break;
	case OFF:
		mode = OFF;
		SetPower( FALSE );
		break;
	}
	
	
	
	if (mode == VS)
		tdisplayRange = 80.0F * NM_TO_FT;
	else
		tdisplayRange = displayRange * NM_TO_FT;
	
	SetScan();
	SetFlagBit(HomingBeam);
	
	//MI
	FireControlComputer *FCC = NULL;
	if(SimDriver.GetPlayerAircraft())
		FCC = SimDriver.GetPlayerAircraft()->FCC;
	if(FCC)
	{
		if(FCC->GetMasterMode() == FireControlComputer::ClearOveride)
			return;
		
		if(FCC->IsAAMasterMode())
			LastAAMode = mode;
		else if(FCC->IsNavMasterMode())
			LastNAVMode = mode;
		else if(FCC->IsAGMasterMode())
		{
			if(mode != AGR)
				LastAGMode = mode;
		}
		else if(FCC->GetMasterMode() == FireControlComputer::MissileOverride)
			Missovrradarmode = mode;
		else if(FCC->GetMasterMode() == FireControlComputer::Dogfight)
		{
			if(mode == ACM_30x20 || mode == ACM_10x60 || mode == ACM_SLEW || mode == ACM_BORE)
				Dogfovrradarmode = mode;
		}
	}
}
Exemple #10
0
void Shooter::SetLinearPower(double pwm) {
  SetPower(Linearize(pwm));
}