Esempio n. 1
0
Creature *monster::attack_target()
{
    if( plans.empty() ) {
        return nullptr;
    }

    point target_point = move_target();
    Creature *target = g->critter_at( target_point.x, target_point.y );
    if( target == nullptr || attitude_to( *target ) == Creature::A_FRIENDLY ||
        !sees(*target) ) {
        return nullptr;
    }
    return target;
}
Esempio n. 2
0
point editmap::edit(point coords)
{
    target.x = g->u.posx + g->u.view_offset_x;
    target.y = g->u.posy + g->u.view_offset_y;
    int ch;
    InputEvent input;

    uberdraw = uistate.editmap_nsa_viewmode;
    infoHeight = 14;

    w_info = newwin(infoHeight, width, TERRAIN_WINDOW_HEIGHT - infoHeight, TERRAIN_WINDOW_WIDTH + VIEW_OFFSET_X);
    w_help = newwin(3, width - 2, TERRAIN_WINDOW_HEIGHT - 3, TERRAIN_WINDOW_WIDTH + VIEW_OFFSET_X + 1);
    for ( int i = 0; i < getmaxx(w_help); i++ ) {
        mvwaddch(w_help, 2, i, LINE_OXOX);
    }

    do {
        if ( target_list.empty() ) {
            target_list.push_back(target); // 'editmap.target_list' always has point 'editmap.target' at least
        }
        if ( target_list.size() == 1 ) {
            origin = target;               // 'editmap.origin' only makes sense if we have a list of target points.
        }
        update_view(true);
        uphelp("[t]rap, [f]ield, [HJKL] move++, [v] showall", "[g] terrain/furniture, [i]tems, [q]uit", "Looking around");
        ch = (int)getch();

        if(ch) {
            input = get_input(ch); // get_input: Not very useful for arbitrary keys, so check getch value first.
        }
        if(ch == 'g') {
            edit_ter( target );
            lastop = 'g';
        } else if ( ch == 'f' ) {
            edit_fld( target );
            lastop = 'f';
        } else if ( ch == 'i' ) {
            edit_itm( target );
            lastop = 'i';
        } else if ( ch == 't' ) {
            edit_trp( target );
            lastop = 't';
        } else if ( ch == 'v' ) {
            uberdraw = !uberdraw;
        } else if ( ch == 'o' ) {
            apply_mapgen( target );
            lastop = 'o';
            target_list.clear();
            origin = target;
            target_list.push_back( target);
        } else {
            if ( move_target(input, ch, 1) == true ) {
                recalc_target(editshape);           // target_list must follow movement
                if (target_list.size() > 1 ) {
                    blink = true;                       // display entire list if it's more than just target point
                }
            }
        }
    } while (input != Close && input != Cancel && ch != 'q');

    uistate.editmap_nsa_viewmode = uberdraw;

    if (input == Confirm) {
        return point(target.x, target.y);
    }
    return point(-1, -1);
}
Esempio n. 3
0
/*!
  execute action
*/
bool
Bhv_GoalieFreeKick::execute( rcsc::PlayerAgent * agent )
{
    static bool s_first_move = false;
    static bool s_second_move = false;
    static int s_second_wait_count = 0;

    rcsc::dlog.addText( rcsc::Logger::TEAM,
                        __FILE__": Bhf_GoalieFreeKick" );
    if ( agent->world().gameMode().type() != rcsc::GameMode::GoalieCatch_
         || agent->world().gameMode().side() != agent->world().ourSide()
         || ! agent->world().self().isKickable() )
    {
        rcsc::dlog.addText( rcsc::Logger::TEAM,
                            __FILE__": Bhv_GoalieFreeKick. Not a goalie catch mode" );

        Bhv_GoalieBasicMove().execute( agent );
        return true;
    }


    const long time_diff
        = agent->world().time().cycle()
        - agent->effector().getCatchTime().cycle();
    //- M_catch_time.cycle();

    // reset flags & wait
    if ( time_diff <= 2 )
    {
        s_first_move = false;
        s_second_move = false;
        s_second_wait_count = 0;

        doWait( agent );
        return true;
    }

    // first move
    if ( ! s_first_move )
    {
        //rcsc::Vector2D move_target( rcsc::ServerParam::i().ourPenaltyAreaLine() - 0.8, 0.0 );
        rcsc::Vector2D move_target( rcsc::ServerParam::i().ourPenaltyAreaLineX() - 1.5,
                                    agent->world().ball().pos().y > 0.0 ? -17.0 : 17.0 );
        //rcsc::Vector2D move_target( -45.0, 0.0 );
        s_first_move = true;
        s_second_move = false;
        s_second_wait_count = 0;
        agent->doMove( move_target.x, move_target.y );
        agent->setNeckAction( new rcsc::Neck_ScanField );
        return true;
    }

    // after first move
    // check stamina recovery or wait teammate
    rcsc::Rect2D our_pen( rcsc::Vector2D( -52.5, -40.0 ),
                          rcsc::Vector2D( -36.0, 40.0 ) );
    if ( time_diff < 50
         || agent->world().setplayCount() < 3
         || ( time_diff < rcsc::ServerParam::i().dropBallTime() - 15
              && ( agent->world().self().stamina() < rcsc::ServerParam::i().staminaMax() * 0.9
                   || agent->world().existTeammateIn( our_pen, 20, true )
                   )
              )
         )
    {
        doWait( agent );
        return true;
    }

    // second move
    if ( ! s_second_move )
    {
        rcsc::Vector2D kick_point = getKickPoint( agent );
        agent->doMove( kick_point.x, kick_point.y );
        agent->setNeckAction( new rcsc::Neck_ScanField );
        s_second_move = true;
        s_second_wait_count = 0;
        return true;
    }

    s_second_wait_count++;

    // after second move
    // wait see info
    if ( s_second_wait_count < 5
         || agent->world().seeTime() != agent->world().time() )
    {
        doWait( agent );
        return true;
    }

    s_first_move = false;
    s_second_move = false;
    s_second_wait_count = 0;

    // register kick intention
    doKick( agent );

    return true;
}
Esempio n. 4
0
/*
 * Interactively select, resize, and move the list of target coords
 */
int editmap::select_shape(shapetype shape, int mode)
{
    point orig = target;
    point origor = origin;
    int ch = 0;
    InputEvent input = Undefined;
    bool update = false;
    blink = true;
    if ( mode >= 0 ) {
        moveall = ( mode == 0 ? false : true );
    }
    altblink = moveall;
    update_view(false);
    timeout(BLINK_SPEED);
    do {
        uphelp(
            ( moveall == true ? "[s] resize, [y] swap" :
              "[m]move, [s]hape, [y] swap, [z] to start" ),
            "[enter] accept, [q] abort, [v] showall",
            ( moveall == true ? "Moving selection" : "Resizing selection" ) );
        ch = getch();
        timeout(BLINK_SPEED);
        if(ch != ERR) {
            blink = true;
            input = get_input(ch);
            if(ch == 's') {
                if ( ! moveall ) {
                    timeout(-1);
                    uimenu smenu;
                    smenu.text = "Selection type";
                    smenu.w_x = (TERRAIN_WINDOW_WIDTH + VIEW_OFFSET_X - 16) / 2;
                    smenu.addentry(editmap_rect, true, 'r', "Rectangle");
                    smenu.addentry(editmap_rect_filled, true, 'f', "Filled Rectangle");
                    smenu.addentry(editmap_line, true, 'l', "Line");
                    smenu.addentry(editmap_circle, true, 'c', "Filled Circle");
                    smenu.addentry(-2, true, 'p', "Point");
                    smenu.selected = (int)shape;
                    smenu.query();
                    if ( smenu.ret != -2 ) {
                        shape = (shapetype)smenu.ret;
                        update = true;
                    } else {
                        target_list.clear();
                        origin = target;
                        target_list.push_back(target);
                        moveall = true;
                    }
                    timeout(BLINK_SPEED);
                } else {
                    moveall = false;
                }
            } else if ( moveall == false && ch == 'z' ) {
                target = origin;
                update = true;
            } else if ( ch == 'y' ) {
                point tmporigin = origin;
                origin = target;
                target = tmporigin;
                update = true;
            } else if ( ch == 'm' ) {
                moveall = true;
            } else if ( ch == 'v' ) {
                uberdraw = !uberdraw;
            } else if ( ch == '\t' ) {
                if ( moveall ) {
                    moveall = false;
                    altblink = moveall;
                    input = Confirm;
                } else {
                    moveall = true;
                }
            } else {
                if ( move_target(input, ch) == true ) {
                    update = true;
                }
            }
            if (update) {
                blink = true;
                update = false;
                recalc_target( shape );
                altblink = moveall;
                update_view(false);
            }
        } else {
            blink = !blink;
        }
        altblink = moveall;
        update_view(false);
    } while (ch != 'q' && input != Confirm);
    timeout(-1);
    blink = true;
    altblink = false;
    if ( input == Confirm ) {
        editshape = shape;
        update_view(false);
        return target_list.size();
    } else {
        target_list.clear();
        target = orig;
        origin = origor;
        target_list.push_back(target);
        blink = false;
        update_view(false);
        return -1;
    }
}