void mousekey_task(void) { if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_interval : mk_delay*10)) return; if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) return; if (mousekey_repeat != UINT8_MAX) mousekey_repeat++; if (mouse_report.x > 0) mouse_report.x = move_unit(); if (mouse_report.x < 0) mouse_report.x = move_unit() * -1; if (mouse_report.y > 0) mouse_report.y = move_unit(); if (mouse_report.y < 0) mouse_report.y = move_unit() * -1; /* diagonal move [1/sqrt(2) = 0.7] */ if (mouse_report.x && mouse_report.y) { mouse_report.x *= 0.7; mouse_report.y *= 0.7; } if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_wheel_interval : mk_delay*10)) return; if (mouse_report.v > 0) mouse_report.v = wheel_unit(); if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1; if (mouse_report.h > 0) mouse_report.h = wheel_unit(); if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1; mousekey_send(); }
static int gate_handle(trigger * t, void *data) { /* call an event handler on gate. * data.v -> ( variant event, int timer ) */ gate_data *gd = (gate_data *) t->data.v; struct building *b = gd->gate; struct region *r = gd->target; if (b && b->region && r) { unit **up = &b->region->units; while (*up) { unit *u = *up; if (u->building == b) move_unit(u, r, NULL); if (*up == u) up = &u->next; } } else { log_error("could not perform gate::handle()\n"); return -1; } unused_arg(data); return 0; }
static int wormhole_age(struct attrib *a) { wormhole_data *data = (wormhole_data *)a->data.v; int maxtransport = data->entry->size; region *r = data->entry->region; unit *u = r->units; for (; u != NULL && maxtransport != 0; u = u->next) { if (u->building == data->entry) { message *m = NULL; if (u->number > maxtransport || has_limited_skills(u)) { m = msg_message("wormhole_requirements", "unit region", u, u->region); } else if (data->exit != NULL) { move_unit(u, data->exit, NULL); maxtransport -= u->number; m = msg_message("wormhole_exit", "unit region", u, data->exit); add_message(&data->exit->msgs, m); } if (m != NULL) { add_message(&u->faction->msgs, m); msg_release(m); } } } remove_building(&r->buildings, data->entry); ADDMSG(&r->msgs, msg_message("wormhole_dissolve", "region", r)); /* age returns 0 if the attribute needs to be removed, !=0 otherwise */ return AT_AGE_KEEP; }
/** ** GM: TELEPORT <unit> <x> <y> ** requires: permission-key "gmtele" **/ static void gm_teleport(const void *tnext, struct unit *u, struct order *ord) { const struct plane *p = rplane(u->region); unit *to = findunit(getid()); int x = rel_to_abs(p, u->faction, getint(), 0); int y = rel_to_abs(p, u->faction, getint(), 1); region *r = findregion(x, y); if (r == NULL || p != rplane(r)) { mistake(u, ord, "region is in another plane."); } else if (to == NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found", "")); } else if (rplane(to->region) != rplane(r) && !ucontact(to, u)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_no_contact", "target", to)); } else { /* checking permissions */ attrib *permissions = a_find(u->faction->attribs, &at_permissions); if (!permissions || !has_permission(permissions, atoi36("gmtele"))) { mistake(u, ord, "permission denied."); } else move_unit(to, r, NULL); } }
void mousekey_on(uint8_t code) { if (code == KC_MS_UP) mouse_report.y = move_unit() * -1; else if (code == KC_MS_DOWN) mouse_report.y = move_unit(); else if (code == KC_MS_LEFT) mouse_report.x = move_unit() * -1; else if (code == KC_MS_RIGHT) mouse_report.x = move_unit(); else if (code == KC_MS_WH_UP) mouse_report.v = wheel_unit(); else if (code == KC_MS_WH_DOWN) mouse_report.v = wheel_unit() * -1; else if (code == KC_MS_WH_LEFT) mouse_report.h = wheel_unit() * -1; else if (code == KC_MS_WH_RIGHT) mouse_report.h = wheel_unit(); else if (code == KC_MS_BTN1) mouse_report.buttons |= MOUSE_BTN1; else if (code == KC_MS_BTN2) mouse_report.buttons |= MOUSE_BTN2; else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3; else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4; else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5; else if (code == KC_MS_ACCEL0) mousekey_accel |= (1<<0); else if (code == KC_MS_ACCEL1) mousekey_accel |= (1<<1); else if (code == KC_MS_ACCEL2) mousekey_accel |= (1<<2); }
void move_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: "<< *this << std::endl; assert(is_success()); move_spectator_.set_unit(get_info().units.find(from_)); if (from_ != to_) { move_unit( /*move_unit_spectator* move_spectator*/ &move_spectator_, /*std::vector<map_location> route*/ route_.steps, /*replay* move_recorder*/ &recorder, /*undo_list* undo_stack*/ NULL, /*bool show_move*/ preferences::show_ai_moves(), /*map_location *next_unit*/ NULL, /*bool continue_move*/ true, //@todo: 1.9 set to false after implemeting interrupt awareness /*bool should_clear_shroud*/ true, /*bool is_replay*/ false); if ( move_spectator_.get_ambusher().valid() || !move_spectator_.get_seen_enemies().empty() || !move_spectator_.get_seen_friends().empty() ) { set_gamestate_changed(); } else if (move_spectator_.get_unit().valid()){ unit_location_ = move_spectator_.get_unit()->first; if (unit_location_ != from_) { set_gamestate_changed(); } } } else { assert(remove_movement_); } if (move_spectator_.get_unit().valid()){ unit_location_ = move_spectator_.get_unit()->first; if ( remove_movement_ && ( move_spectator_.get_unit()->second.movement_left() > 0 ) && (unit_location_==to_)) { stopunit_result_ptr stopunit_res = actions::execute_stopunit_action(get_side(),true,unit_location_,true,false); if (!stopunit_res->is_ok()) { set_error(stopunit_res->get_status()); } if (stopunit_res->is_gamestate_changed()) { set_gamestate_changed(); } } } else { unit_location_ = map_location(); } if (is_gamestate_changed()) { try { manager::raise_gamestate_changed(); } catch (...) { is_ok(); //Silences "unchecked result" warning throw; } } }
static int enter_arena(unit * u, const item_type * itype, int amount, order * ord) { skill_t sk; region *r = u->region; unit *u2; int fee = u->faction->score / 5; unused(ord); unused(amount); unused(itype); if (fee > 2000) fee = 2000; if (getplane(r) == arena) return -1; if (u->number != 1 && enter_fail(u)) return -1; if (get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, fee) < fee && enter_fail(u)) return -1; for (sk = 0; sk != MAXSKILLS; ++sk) { if (get_level(u, sk) > 1 && enter_fail(u)) return -1; } for (u2 = r->units; u2; u2 = u2->next) if (u2->faction == u->faction) break; assert(!"not implemented"); /* for (res=0;res!=MAXRESOURCES;++res) if (res!=R_SILVER && res!=R_ARENA_GATE && (is_item(res) || is_herb(res) || is_potion(res))) { int x = get_resource(u, res); if (x) { if (u2) { change_resource(u2, res, x); change_resource(u, res, -x); } else if (enter_fail(u)) return -1; } } */ if (get_money(u) > fee) { if (u2) change_money(u2, get_money(u) - fee); else if (enter_fail(u)) return -1; } ADDMSG(&u->faction->msgs, msg_message("arena_enter_fail", "region unit", u->region, u)); use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE, 1); use_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, fee); set_money(u, 109); fset(u, UFL_ANON_FACTION); move_unit(u, start_region[rng_int() % 6], NULL); return 0; }
static int use_museumexitticket(unit * u, const struct item_type *itype, int amount, order * ord) { attrib *a; region *r; unit *warden = findunit(atoi36("mwar")); int unit_cookie; unused_arg(amount); /* Prüfen ob in Eingangshalle */ if (u->region->x != 9525 || u->region->y != 9525) { cmistake(u, ord, 266, MSG_MAGIC); return 0; } a = a_find(u->attribs, &at_museumexit); assert(a); r = findregion(a->data.sa[0], a->data.sa[1]); assert(r); a_remove(&u->attribs, a); /* Übergebene Gegenstände zurückgeben */ a = a_find(u->attribs, &at_museumgivebackcookie); if (a) { unit_cookie = a->data.i; a_remove(&u->attribs, a); for (a = a_find(warden->attribs, &at_museumgiveback); a && a->type == &at_museumgiveback; a = a->next) { if (((museumgiveback *)(a->data.v))->cookie == unit_cookie) break; } if (a && a->type == &at_museumgiveback) { museumgiveback *gb = (museumgiveback *)(a->data.v); item *it; for (it = gb->items; it; it = it->next) { i_change(&u->items, it->type, it->number); } ADDMSG(&u->faction->msgs, msg_message("museumgiveback", "region unit sender items", r, u, warden, gb->items)); a_remove(&warden->attribs, a); } } /* Benutzer zurück teleportieren */ move_unit(u, r, NULL); /* Exitticket abziehen */ i_change(&u->items, itype, -1); return 0; }
static int use_museumticket(unit * u, const struct item_type *itype, int amount, order * ord) { attrib *a; region *r = u->region; plane *pl = rplane(r); unused_arg(amount); /* Pruefen ob in normaler Plane und nur eine Person */ if (pl != get_homeplane()) { cmistake(u, ord, 265, MSG_MAGIC); return 0; } if (u->number != 1) { cmistake(u, ord, 267, MSG_MAGIC); return 0; } if (has_horses(u)) { cmistake(u, ord, 272, MSG_MAGIC); return 0; } /* In diesem Attribut merken wir uns, wohin die Einheit zurückgesetzt * wird, wenn sie das Museum verläßt. */ a = a_add(&u->attribs, a_new(&at_museumexit)); a->data.sa[0] = (short)r->x; a->data.sa[1] = (short)r->y; /* Benutzer in die Halle teleportieren */ move_unit(u, findregion(9525, 9525), NULL); /* Ticket abziehen */ i_change(&u->items, itype, -1); /* Benutzer ein Exitticket geben */ i_change(&u->items, itype, 1); return 0; }
void Board::on_click(uint8_t button, uint16_t clicked_x, uint16_t clicked_y) { if (!(clicked_x > render_bounds.x && clicked_x < render_bounds.x + render_bounds.w && clicked_y > render_bounds.y && clicked_y < render_bounds.y + render_bounds.h)) return; clicked_x -= BORDER_SIZE_X; clicked_y -= BORDER_SIZE_Y; clicked_x = clicked_x / TILE_SIZE; clicked_y = clicked_y / TILE_SIZE; switch (button) { case MOUSERIGHT: deselect_unit(); break; case MOUSELEFT: if (!unit_selected && !select_unit(clicked_x, clicked_y)) return; if (!can_move_unit(clicked_x, clicked_y) || !check_path(clicked_x, clicked_y)) return; kill_enemy_unit(clicked_x, clicked_y); move_unit(clicked_x, clicked_y); break; } }
static void move_iceberg(region * r) { attrib *a; direction_t dir; region *rc; a = a_find(r->attribs, &at_iceberg); if (!a) { dir = (direction_t) (rng_int() % MAXDIRECTIONS); a = a_add(&r->attribs, make_iceberg(dir)); } else { if (rng_int() % 100 < 20) { dir = (direction_t) (rng_int() % MAXDIRECTIONS); a->data.i = dir; } else { dir = (direction_t) a->data.i; } } rc = rconnect(r, dir); if (rc && !fval(rc->terrain, ARCTIC_REGION)) { if (fval(rc->terrain, SEA_REGION)) { /* Eisberg treibt */ ship *sh, *shn; unit *u; int x, y; for (u = r->units; u; u = u->next) freset(u->faction, FFL_SELECT); for (u = r->units; u; u = u->next) if (!fval(u->faction, FFL_SELECT)) { fset(u->faction, FFL_SELECT); ADDMSG(&u->faction->msgs, msg_message("iceberg_drift", "region dir", r, dir)); } x = r->x; y = r->y; runhash(r); runhash(rc); r->x = rc->x; r->y = rc->y; rc->x = x; rc->y = y; rhash(rc); rhash(r); /* rc ist der Ozean (Ex-Eisberg), r der Eisberg (Ex-Ozean) */ /* Schiffe aus dem Zielozean werden in den Eisberg transferiert * und nehmen Schaden. */ for (sh = r->ships; sh; sh = sh->next) freset(sh, SF_SELECT); for (sh = r->ships; sh; sh = sh->next) { /* Meldung an Kapitän */ float dmg = get_param_flt(global.parameters, "rules.ship.damage.intoiceberg", 0.10F); damage_ship(sh, dmg); fset(sh, SF_SELECT); } /* Personen, Schiffe und Gebäude verschieben */ while (rc->buildings) { rc->buildings->region = r; translist(&rc->buildings, &r->buildings, rc->buildings); } while (rc->ships) { float dmg = get_param_flt(global.parameters, "rules.ship.damage.withiceberg", 0.10F); fset(rc->ships, SF_SELECT); damage_ship(rc->ships, dmg); move_ship(rc->ships, rc, r, NULL); } while (rc->units) { building *b = rc->units->building; u = rc->units; u->building = 0; /* prevent leaving in move_unit */ move_unit(rc->units, r, NULL); u_set_building(u, b); /* undo leave-prevention */ } /* Beschädigte Schiffe können sinken */ for (sh = r->ships; sh;) { shn = sh->next; if (fval(sh, SF_SELECT)) { u = ship_owner(sh); if (sh->damage >= sh->size * DAMAGE_SCALE) { if (u != NULL) { ADDMSG(&u->faction->msgs, msg_message("overrun_by_iceberg_des", "ship", sh)); } remove_ship(&sh->region->ships, sh); } else if (u != NULL) { ADDMSG(&u->faction->msgs, msg_message("overrun_by_iceberg", "ship", sh)); } } sh = shn; } } else if (rng_int() % 100 < 20) { /* Eisberg bleibt als Gletscher liegen */ unit *u; rsetterrain(r, T_GLACIER); a_remove(&r->attribs, a); for (u = r->units; u; u = u->next) freset(u->faction, FFL_SELECT); for (u = r->units; u; u = u->next) if (!fval(u->faction, FFL_SELECT)) { fset(u->faction, FFL_SELECT); ADDMSG(&u->faction->msgs, msg_message("iceberg_land", "region", r)); } } } }
/** creates a new unit. * * @param dname: name, set to NULL to get a default. * @param creator: unit to inherit stealth, group, building, ship, etc. from */ unit *create_unit(region * r, faction * f, int number, const struct race *urace, int id, const char *dname, unit * creator) { unit *u = (unit *)calloc(1, sizeof(unit)); assert(urace); if (f) { assert(f->alive); u_setfaction(u, f); if (f->locale) { order *deford = default_order(f->locale); if (deford) { set_order(&u->thisorder, NULL); addlist(&u->orders, deford); } } } u_seteffstealth(u, -1); u_setrace(u, urace); u->irace = NULL; set_number(u, number); /* die nummer der neuen einheit muss vor name_unit generiert werden, * da der default name immer noch 'Nummer u->no' ist */ createunitid(u, id); /* zuerst in die Region setzen, da zb Drachennamen den Regionsnamen * enthalten */ if (r) move_unit(u, r, NULL); /* u->race muss bereits gesetzt sein, wird für default-hp gebraucht */ /* u->region auch */ u->hp = unit_max_hp(u) * number; if (!dname) { name_unit(u); } else { u->name = _strdup(dname); } if (creator) { attrib *a; /* erbt Kampfstatus */ setstatus(u, creator->status); /* erbt Gebäude/Schiff */ if (creator->region == r) { if (creator->building) { u_set_building(u, creator->building); } if (creator->ship && fval(u_race(u), RCF_CANSAIL)) { u_set_ship(u, creator->ship); } } /* Tarnlimit wird vererbt */ if (fval(creator, UFL_STEALTH)) { attrib *a = a_find(creator->attribs, &at_stealth); if (a) { int stealth = a->data.i; a = a_add(&u->attribs, a_new(&at_stealth)); a->data.i = stealth; } } /* Temps von parteigetarnten Einheiten sind wieder parteigetarnt */ if (fval(creator, UFL_ANON_FACTION)) { fset(u, UFL_ANON_FACTION); } /* Daemonentarnung */ set_racename(&u->attribs, get_racename(creator->attribs)); if (fval(u_race(u), RCF_SHAPESHIFT) && fval(u_race(creator), RCF_SHAPESHIFT)) { u->irace = creator->irace; } /* Gruppen */ if (creator->faction == f && fval(creator, UFL_GROUP)) { a = a_find(creator->attribs, &at_group); if (a) { group *g = (group *) a->data.v; set_group(u, g); } } a = a_find(creator->attribs, &at_otherfaction); if (a) { a_add(&u->attribs, make_otherfaction(get_otherfaction(a))); } a = a_add(&u->attribs, a_new(&at_creator)); a->data.v = creator; } return u; }
void screen_play(SDL_Renderer * render,game_t * game) { char gold_buf[128]; char mana_buf[128]; SDL_Event event; int tile_num; int unit_num; int city_num; int encounter_num; int i; int j; int x; LBXAnimation_t * anim_ptr; city_t * city; local_render = render; end_screen = -1; selected_group = NULL; city = (city_t*)game->wiz[0].city->data; cur_tile_x = city->x; cur_tile_y = city->y; load_font(); /* Load resource */ if(anim==NULL) { anim = load_graphics(render,"MAIN.LBX"); if(anim == NULL) { exit(EXIT_FAILURE); } } /* Load tiles */ if(tile==NULL) { tile = load_graphics(render,"TERRAIN.LBX"); if(tile == NULL) { exit(EXIT_FAILURE); } } /* Load unit */ if(unit1==NULL) { unit1 = load_graphics(render,"UNITS1.LBX"); if(unit1 == NULL) { exit(EXIT_FAILURE); } } if(unit2==NULL) { unit2 = load_graphics(render,"UNITS2.LBX"); if(unit2 == NULL) { exit(EXIT_FAILURE); } } /* Concat unit1 and unit2 */ if(unit==NULL) { j=0; anim_ptr = unit1; for(i=0; i<2; i++) { while(anim_ptr->num_frame!=0) { unit = (LBXAnimation_t*)realloc(unit,(j+1)*sizeof(LBXAnimation_t)); memcpy(&unit[j],anim_ptr,sizeof(LBXAnimation_t)); anim_ptr++; j++; } anim_ptr= unit2; } } /* Load back */ if(back==NULL) { back = load_graphics(render,"MAPBACK.LBX"); if(back == NULL) { exit(EXIT_FAILURE); } } j=0; item_init(&item_ui[j]); item_set_frame(&item_ui[j],0,0,&anim[j]); j++; x=7; item_init(&item_ui[j]); item_set_frame(&item_ui[j],x,4,&anim[j]); item_set_frame_click(&item_ui[j],1); j++; x+=item_ui[j-1].anim->w + 1; item_init(&item_ui[j]); item_set_frame(&item_ui[j],x,4,&anim[j]); item_set_frame_click(&item_ui[j],1); j++; x+=item_ui[j-1].anim->w + 1; item_init(&item_ui[j]); item_set_frame(&item_ui[j],x,4,&anim[j]); item_set_frame_click(&item_ui[j],1); j++; x+=item_ui[j-1].anim->w + 1; item_init(&item_ui[j]); item_set_frame(&item_ui[j],x,4,&anim[j]); item_set_frame_click(&item_ui[j],1); j++; x+=item_ui[j-1].anim->w + 1; item_init(&item_ui[j]); item_set_frame(&item_ui[j],x,4,&anim[j]); item_set_frame_click(&item_ui[j],1); j++; x+=item_ui[j-1].anim->w + 1; item_init(&item_ui[j]); item_set_frame(&item_ui[j],x,4,&anim[j]); item_set_frame_click(&item_ui[j],1); j++; x+=item_ui[j-1].anim->w + 1; item_init(&item_ui[j]); item_set_frame(&item_ui[j],x,4,&anim[j]); item_set_frame_click(&item_ui[j],1); item_set_click_left(&item_ui[j],cb_plane,NULL); j++; /* Main loop */ while( end_screen == -1) { tile_num = draw_tile(game); city_num = draw_city(game); encounter_num = draw_encounter(game); unit_num = draw_unit(game); /* Print gold */ item_init(&item_ui[8]); item_set_font(&item_ui[8],font); sprintf(gold_buf,"%d GP",game->wiz[0].gold); item_set_string(&item_ui[8],gold_buf); item_set_frame(&item_ui[8],264,71,NULL); /* Print mana */ item_init(&item_ui[9]); item_set_font(&item_ui[9],font); sprintf(mana_buf,"%d MP",game->wiz[0].mana); item_set_string(&item_ui[9],mana_buf); item_set_frame(&item_ui[9],300,71,NULL); while (SDL_PollEvent(&event)) { if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_ESCAPE) { return; } /* Move selected_unit */ if(event.type==SDL_KEYDOWN ) { move_unit(game,event.key.keysym.sym); } sdl_screen_manager(&event); sdl_mouse_manager(&event,item_ui,ITM_UI_NUM); sdl_mouse_manager(&event,item_city,city_num); sdl_mouse_manager(&event,item_encounter,encounter_num); sdl_mouse_manager(&event,item_tile,tile_num); sdl_mouse_manager(&event,item_unit,unit_num); sdl_keyboard_manager(&event); } SDL_RenderClear(render); sdl_blit_item_list(item_tile,tile_num); sdl_blit_item_list(item_city,city_num); sdl_blit_item_list(item_encounter,encounter_num); sdl_blit_item_list(item_back,unit_num); sdl_blit_item_list(item_unit,unit_num); sdl_blit_item_list(item_ui,ITM_UI_NUM); sdl_blit_to_screen(); sdl_loop_manager(); } return; }