void EditTOC::SelectTarget() { QModelIndex index = CheckSelection(1); if (!index.isValid()) { return; } QStandardItem *item = m_TableOfContents->itemFromIndex(index); SelectHyperlink select_target(item->text(), NULL, m_Resources, m_Book, this); if (select_target.exec() == QDialog::Accepted) { item->setText(select_target.GetTarget()); } }
void ai::update(const world &w, int dt) { if (m_plane.expired()) return; const float kdt = dt * 0.001f; auto p = m_plane.lock(); vec3 next_pos = p->phys->pos + p->phys->vel * kdt; p->controls.mgun = false; p->controls.brake = 0.0f; if (m_state == state_pursuit) { if ((m_target.expired() || m_target.lock()->hp <= 0) && m_state != state_follow) m_state = state_wander; } //if (m_state != state_pursuit) find_best_target(); if (!m_target.expired()) { p->select_target(std::static_pointer_cast<object>(m_target.lock())); auto t = m_target.lock(); auto target_pos = t->phys->pos + t->phys->vel * (dt * 0.001f); if (m_state == state_pursuit) go_to(target_pos - 20.0 * vec3::normalize(t->phys->vel), dt); //6 o'clock else go_to(target_pos, dt); } if (m_state == state_wander) { if (fabsf(p->get_pos().x) > 4096 || fabsf(p->get_pos().z) > 4096 ) //ToDo: set operation area { auto dir = p->get_dir(); dir.y = 0; dir.normalize(); if (stabilize_course(dir)) p->controls.rot = nya_math::vec3(0.0, 1.0, 0.0); p->controls.throttle = 1.0; } } //evade ground const float minimal_height = 600.0f + w.get_height(next_pos.x, next_pos.z); if (next_pos.y < minimal_height && p->get_dir().y < 0.0f) { if (p->phys->get_speed_kmh() > 700.0f) p->controls.brake = 1.0f; p->controls.rot.x = vec3::up().dot(p->phys->rot.rotate(vec3::up())) < 0.0f ? 1.0f : -1.0f; } if (!p->targets.empty() && p->targets.front().locked) { p->controls.missile = !p->controls.missile; p->controls.mgun = true; //ToDo } else p->controls.missile = false; }
void mob_is_standing( CHAR_DATA * ch ) { short dir; CHAR_DATA *vch; CHAR_DATA *tch; list<CHAR_DATA *>::iterator li; bool ready = TRUE; bool prey_still_exist = FALSE; int number_got_up = 0; int number_of_group = 1; int number_of_other_group = 1; /* * get a light source */ if ( ch->in_room->light <= 0 ) { if ( ch->mana >= mana_cost( ch, skill_lookup( "continual light" ) ) ) { do_cast( ch, "'continual light'" ); do_get( ch, "all" ); do_wear( ch, "all" ); return; } } if ( ( IS_AFFECTED( ch, AFF_POISON ) ) || ( IS_AFFECTED( ch, AFF_BLIND ) ) ) { if ( IS_AFFECTED( ch, AFF_POISON ) ) if ( ch->mana >= mana_cost( ch, skill_lookup( "cure poison" ) ) ) do_cast( ch, "'cure poison'" ); if ( IS_AFFECTED( ch, AFF_BLIND ) ) if ( ch->mana >= mana_cost( ch, skill_lookup( "cure blindness" ) ) ) do_cast( ch, "'cure blindness'" ); return; } /* * is anyone in group being attacked? if so, assist! */ /* * -leaders will be forced to rescue in the 'mob_is_fighting' function * * already so no need to check for it here */ for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( is_same_group( ch, vch ) ) && ( vch->fighting != NULL ) && ( vch != ch ) ) { do_assist( ch, "" ); return; } } if ( ch->leader == NULL ) { for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( is_same_group( ch, vch ) && ( ch != vch ) ) { number_of_group = number_of_group + 1; } } if ( number_of_group < 4 ) { for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( vch->leader != NULL ) continue; if ( ( vch != ch ) && ( IS_NPC( vch ) ) && ( AI_MOB(vch) ) && ( !is_same_group( ch, vch ) ) && ( vch->position == POS_STANDING ) && ( ( vch->get_level("psuedo") - ch->get_level("psuedo") <= 20 && vch->get_level("psuedo") - ch->get_level("psuedo") >= -20 ) || ( ch->get_level("psuedo") - vch->get_level("psuedo") <= 20 && ch->get_level("psuedo") - vch->get_level("psuedo") >= -20 ) ) && ( can_see( vch, ch ) ) && ( can_see( ch, vch ) ) ) { if ( vch->leader == NULL ) { for ( tch = vch->in_room->first_person; tch != NULL; tch = tch->next_in_room ) { if ( is_same_group( tch, vch ) && ( tch != vch ) ) { number_of_other_group = number_of_other_group + 1; } } } if ( number_of_group + number_of_other_group <= 4 ) { get_mob_group( ch, vch ); return; } } } } } /* * do you need to heal? */ if ( ch->hit < ch->max_hit * 85 / 100 ) { if ( ( ch->mana >= mana_cost( ch, skill_lookup( "heal" ) ) ) || ( ch->mana >= mana_cost( ch, skill_lookup( "cure critical" ) ) ) || ( ch->mana >= mana_cost( ch, skill_lookup( "cure serious" ) ) ) ) mob_regen_check( ch, NULL, FALSE ); /* * if leader is ready to move, just keep standing */ if ( ( ch->leader != NULL ) && ( ch->leader->in_room == ch->in_room ) && ( ch->leader->position == POS_STANDING ) && ( ch->leader->mana >= ch->leader->max_mana * 85 / 100 ) && ( ch->leader->hit >= ch->leader->max_hit * 85 / 100 ) ) return; else { if ( ch->mana >= ch->max_mana * 75 / 100 ) ready = ready_heal_room( ch ); if ( ready == TRUE ) do_sleep( ch, "" ); return; } } if ( ch->mana < ch->max_mana * 85 / 100 ) { do_sleep( ch, "" ); return; } /* * do you need to level? if you have a group leader, have the leader * * find a the trainer. if you are the leader just go and find the * * trainer */ // ZEN FIX Have them recall then hunt the room if ( able_to_level( ch ) ) { char_from_room( ch ); char_to_room( ch, get_room_index( 3758 ) ); gain_level( ch ); return; /* dir = h_find_dir ( get_room_index(ch->in_room->vnum), get_room_index(ROOM_VNUM_INT_HEAL), ch->hunt_flags ); if ( dir == -1 ) gain_level ( ch ); else { if ( ( ch->leader != NULL ) && ( ch->leader->in_room == ch->in_room ) ) { hunt_move ( ch->leader, dir ); end_hunt ( ch->leader ); return; } else { hunt_move ( ch, dir ); return; } } */ } /* * if you're leader and you don't need to gain level, does anyone else * * in the group? */ /* * actually, the above function will force the leader to find a trainer * * already. but since i don't want the leader to select a new target * * until the group gains the needed level, i'll put this check here */ for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( is_same_group( vch, ch ) ) && ( vch->in_room == ch->in_room ) && ( vch->leader == ch ) && ( able_to_level( vch ) ) ) { dir = h_find_dir( get_room_index( ch->in_room->vnum ), get_room_index( ROOM_VNUM_INT_HEAL ), ch->hunt_flags ); hunt_move( ch, dir ); return; } } /* * if noone needs to heal or gain level, then let's hunt! */ /* * by the way, only leaders will hunt. followers will just follow and * * assist when needed */ if ( ( ch->leader != NULL ) && ( ch->leader->in_room == ch->in_room ) && ( ch->hunting != NULL ) ) { end_hunt( ch ); } else if ( ( ch->leader != NULL ) && ( ch->leader->in_room == ch->in_room ) && ( ch->hunting == NULL ) ) { return; } else if ( is_group_leader( ch ) ) { for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( vch != ch ) && ( is_same_group( vch, ch ) ) && ( vch->position != POS_STANDING ) ) { get_up( vch, vch->position ); number_got_up = number_got_up + 1; } } if ( number_got_up != 0 ) return; } else { if ( ch->hunting != NULL ) { for ( li = char_list.begin(); li != char_list.end(); li++ ) { vch = *li; if ( vch == ch->hunting ) { prey_still_exist = TRUE; return; } } if ( prey_still_exist == FALSE ) { ch->hunting = NULL; } } if ( ch->hunting == NULL && ch->leader == NULL ) { select_target( ch ); return; } } /* * power_up_mob ( ch ); */ /* * if ( ch->leader != NULL * && ch->in_room != ch->leader->in_room ) * { * do_follow( ch, ch->name ); * } */ return; }
/* i have condensed this function to just three states: MOB_FIGHTING, * MOB_RESTING/ MOB_SLEEPING, and MOB_STANDING. each of these three states * will call it's appropriate function. */ void int_group_handler( NPC_GROUP_DATA * ngroup ) { CHAR_DATA *follower = NULL; CHAR_DATA *leader = ngroup->leader; DL_LIST *follower_ptr; // short followers_want = GRP_STATE_NO_CHANGE; short leader_wants = GRP_STATE_NO_CHANGE; short group_count = 1; // start with leader char monbuf[MSL]; if ( leader == NULL ) { monitor_chan( "No Leader in NPC_GROUP", MONITOR_MOB ); return; } // check for followers needs for ( follower_ptr = ngroup->first_follower; follower_ptr; follower_ptr = follower_ptr->next ) { // check for needing healing, levelling follower = (CHAR_DATA *)follower_ptr->this_one; group_count++; continue; } // check for leader's needs if ( leader->hit < leader->max_hit * 25 / 100 ) { leader_wants = GRP_STATE_CRIT_HEAL; } else if ( leader->mana < leader->max_mana * 25 / 100 ) { leader_wants = GRP_STATE_CRIT_MANA; } else if ( leader->hit < leader->max_hit * 60 / 100 ) { leader_wants = GRP_STATE_NORM_HEAL; } else if ( leader->mana < leader->max_mana * 50 / 100 ) { leader_wants = GRP_STATE_NORM_MANA; } else if ( able_to_level( leader ) ) { leader_wants = GRP_STATE_LEVELING; } snprintf( monbuf, MSL, "NPC Group Handler, Leader is %s, state is %s", ngroup->leader->name.c_str(), group_state_table[ngroup->state] ); monitor_chan( monbuf, MONITOR_MOB ); switch ( ngroup->state ) { case GRP_STATE_CRIT_HEAL: case GRP_STATE_CRIT_MANA: case GRP_STATE_NORM_HEAL: case GRP_STATE_NORM_MANA: { bool everyone_ready = TRUE; bool room_ready = FALSE; // ready_heal_room( leader ); if ( ( leader->mana < leader->max_mana * 85 / 100 ) || ( leader->hit < leader->max_hit * 85 / 100 ) ) { everyone_ready = FALSE; if ( ( ( room_ready = ready_heal_room( leader ) ) == TRUE ) || ( leader->mana < leader->max_mana * 20 / 100 ) ) { do_sleep( leader, "" ); } } else { do_stand( leader, "" ); } for ( follower_ptr = ngroup->first_follower; follower_ptr; follower_ptr = follower_ptr->next ) { follower = (CHAR_DATA *)follower_ptr->this_one; if ( ( follower->mana < follower->max_mana * 75 / 100 ) || ( follower->hit < follower->max_hit * 75 / 100 ) ) { everyone_ready = FALSE; do_sleep( follower, "" ); } else { do_stand( follower, "" ); } } if ( everyone_ready == TRUE ) { ngroup->state = GRP_STATE_IDLE; } break; } case GRP_STATE_FIGHT: { // violence_update will handle if ( ( leader_wants < GRP_STATE_HUNTING ) || ( leader->fighting == NULL ) ) { bool someone_still_fighting = FALSE; ngroup->state = GRP_STATE_FLEE; for ( follower_ptr = ngroup->first_follower; follower_ptr; follower_ptr = follower_ptr->next ) { follower = (CHAR_DATA *)follower_ptr->this_one; if ( follower->fighting != NULL ) { do_flee( follower, "" ); someone_still_fighting = TRUE; } } if ( someone_still_fighting == FALSE ) { ngroup->state = GRP_STATE_REFORM; } if ( leader->fighting != NULL ) { do_flee( leader, "" ); } } break; } case GRP_STATE_FLEE: { bool someone_still_fighting = FALSE; for ( follower_ptr = ngroup->first_follower; follower_ptr; follower_ptr = follower_ptr->next ) { follower = (CHAR_DATA *)follower_ptr->this_one; if ( follower->fighting != NULL ) { do_flee( follower, "" ); someone_still_fighting = TRUE; } } if ( leader->fighting != NULL ) { do_flee( leader, "" ); someone_still_fighting = TRUE; } if ( someone_still_fighting == FALSE ) { ngroup->state = GRP_STATE_REFORM; } break; } case GRP_STATE_IDLE: { // check_re_equip( leader ); // check_rewield( leader ); if ( leader_wants < GRP_STATE_NO_CHANGE ) { ngroup->state = leader_wants; break; } else if ( number_percent( ) < 40 ) { select_target( ngroup->leader ); ngroup->state = GRP_STATE_HUNTING; break; } } case GRP_STATE_HUNTING: { // poll followers later short move_dir; if ( leader->fighting != NULL ) { ngroup->state = GRP_STATE_FIGHT; break; } if ( leader->hunting == NULL ) { // snprintf( monbuf, MSL, "Leader %s not hunting anything in GRP_STATE_HUNTING", // leader->name ); // monitor_chan( monbuf, MONITOR_MOB ); select_target( ngroup->leader ); break; } if ( leader->in_room == leader->hunting->in_room ) { ngroup->state = GRP_STATE_FIGHT; one_hit( leader, leader->hunting, TYPE_UNDEFINED ); break; } move_dir = h_find_dir( leader->in_room, leader->hunting->in_room, HUNT_WORLD | HUNT_OPENDOOR | HUNT_UNLOCKDOOR | HUNT_PICKDOOR ); if ( move_dir < 0 ) // can't get there from here { ngroup->state = GRP_STATE_LOST; break; } hunt_move( leader, move_dir ); break; } case GRP_STATE_LEVELING: { char_from_room( leader ); char_to_room( leader, get_room_index( 3758 ) ); if ( able_to_level( leader ) ) { gain_level( leader ); } for ( follower_ptr = ngroup->first_follower; follower_ptr; follower_ptr = follower_ptr->next ) { follower = (CHAR_DATA *)follower_ptr->this_one; if ( able_to_level( follower ) ) { gain_level( follower ); } } ngroup->state = GRP_STATE_IDLE; break; } case GRP_STATE_REFORM: { bool all_are_here = TRUE; for ( follower_ptr = ngroup->first_follower; follower_ptr; follower_ptr = follower_ptr->next ) { follower = (CHAR_DATA *)follower_ptr->this_one; if ( follower->in_room != leader->in_room ) { short move_dir; all_are_here = FALSE; move_dir = h_find_dir( follower->in_room, leader->in_room, HUNT_WORLD | HUNT_OPENDOOR | HUNT_UNLOCKDOOR | HUNT_PICKDOOR ); if ( move_dir < 0 ) // can't get there from here { ngroup->state = GRP_STATE_LOST; break; } hunt_move( follower, move_dir ); } } if ( all_are_here == TRUE ) { ngroup->state = GRP_STATE_IDLE; } break; } } }
int main(int argc, const char *argv[]) { if (argc < 2) { usage(); exit(EXIT_FAILURE); } parseopts(argv[1]); nfc_init(&context); if (context == NULL) { ERR("Unable to init libnfc (malloc)"); exit(EXIT_FAILURE); } // Try to open the NFC reader pnd = nfc_open(context, NULL); if (pnd == NULL) { ERR("Error opening NFC reader"); nfc_exit(context); exit(EXIT_FAILURE); } if (nfc_initiator_init(pnd) < 0) { nfc_perror(pnd, "nfc_initiator_init"); nfc_close(pnd); nfc_exit(context); exit(EXIT_FAILURE); }; // Let the reader only try once to find a tag if (nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT, false) < 0) { nfc_perror(pnd, "nfc_device_set_property_bool"); nfc_close(pnd); nfc_exit(context); exit(EXIT_FAILURE); } // Disable ISO14443-4 switching in order to read devices that emulate Mifare Classic with ISO14443-4 compliance. if (nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, false) < 0) { nfc_perror(pnd, "nfc_device_set_property_bool"); nfc_close(pnd); nfc_exit(context); exit(EXIT_FAILURE); } // Configure the CRC if (nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, false) < 0) { nfc_perror(pnd, "nfc_device_set_property_bool"); nfc_close(pnd); nfc_exit(context); exit(EXIT_FAILURE); } // Use raw send/receive methods if (nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, false) < 0) { nfc_perror(pnd, "nfc_device_set_property_bool"); nfc_close(pnd); nfc_exit(context); exit(EXIT_FAILURE); } printf("NFC reader: %s opened\n", nfc_device_get_name(pnd)); // Try to find a MIFARE Classic tag if (select_target(pnd, &nt) <= 0) { printf("Error: no tag was found\n"); nfc_close(pnd); nfc_exit(context); exit(EXIT_FAILURE); } // Test if we are dealing with a MIFARE compatible tag if ((nt.nti.nai.btSak & 0x08) == 0) { printf("Warning: tag is probably not a MFC!\n"); } printf("Found MIFARE Classic card:\n"); nt.nm = nmMifare; print_nfc_target(&nt, false); // Guessing size if ((nt.nti.nai.abtAtqa[1] & 0x02) == 0x02) // 4K uiBlocks = 0xff; else if ((nt.nti.nai.btSak & 0x01) == 0x01) // 320b uiBlocks = 0x13; else // 1K/2K, checked through RATS uiBlocks = 0x3f; printf("Guessing size: seems to be a %i-byte card\n", (uiBlocks + 1) * 16); if (parse_card()) { printf("Done, %d blocks read.\n", uiBlocks + 1); fflush(stdout); } if(is_addv) if(!easy_add_value(0xff) || !parse_card()) printf("Failed Add Value!!\n"); printTag(&e); nfc_close(pnd); nfc_exit(context); exit(EXIT_SUCCESS); }