Bug #209 » 0029-Unhardcode-wld.map-from-can_unit_-paradrop-teleport.patch
| ai/default/aiparatrooper.c | ||
|---|---|---|
| { | ||
|   struct city *pcity = tile_city(unit_tile(punit)); | ||
|   struct tile *ptile_dest = NULL; | ||
|   const struct civ_map *nmap = &(wld.map); | ||
|   int sanity = punit->id; | ||
|   /* defend attacking (and be opportunistic too) */ | ||
|   /* Defend attacking (and be opportunistic too) */ | ||
|   if (!dai_military_rampage(punit, RAMPAGE_ANYTHING, | ||
|                             RAMPAGE_FREE_CITY_OR_BETTER)) { | ||
|     /* dead */ | ||
|     /* Dead */ | ||
|     return; | ||
|   } | ||
|   /* check to recover hit points */ | ||
|   /* Check to recover hit points */ | ||
|   if ((punit->hp < unit_type_get(punit)->hp / 2) && pcity) { | ||
|     UNIT_LOG(LOGLEVEL_PARATROOPER, punit, "Recovering hit points."); | ||
|     return; | ||
|   } | ||
|   /* nothing to do! */ | ||
|   /* Nothing to do! */ | ||
|   if (punit->moves_left == 0) { | ||
|     return; | ||
|   } | ||
| ... | ... | |
|     return; | ||
|   } | ||
|   if (can_unit_paradrop(punit)) { | ||
|   if (can_unit_paradrop(nmap, punit)) { | ||
|     ptile_dest = find_best_tile_to_paradrop_to(ait, punit); | ||
|     if (ptile_dest) { | ||
| ... | ... | |
|       } | ||
|     } | ||
|   } else { | ||
|     /* we can't paradrop :-(  */ | ||
|     /* We can't paradrop :-(  */ | ||
|     struct city *acity = NULL; | ||
|     /* we are in a city, so don't try to find another */ | ||
|     /* We are in a city, so don't try to find another */ | ||
|     if (pcity) { | ||
|       UNIT_LOG(LOGLEVEL_PARATROOPER, punit, | ||
| 	       "waiting in a city for next turn."); | ||
|       return; | ||
|     } | ||
|     /* find a city to go to recover and paradrop from */ | ||
|     /* Find a city to go to recover and paradrop from */ | ||
|     acity = find_nearest_safe_city(punit); | ||
|     if (acity) { | ||
| client/control.c | ||
|---|---|---|
|     return; | ||
|   } | ||
|   unit_list_iterate(punits, punit) { | ||
|     if (can_unit_paradrop(punit)) { | ||
|     if (can_unit_paradrop(&(wld.map), punit)) { | ||
|       can = TRUE; | ||
|       break; | ||
|     } | ||
| ... | ... | |
|   } | ||
|   unit_list_iterate(punits, punit) { | ||
|     if (can_unit_teleport(punit)) { | ||
|     if (can_unit_teleport(&(wld.map), punit)) { | ||
|       can = TRUE; | ||
|       break; | ||
|     } | ||
| client/gui-gtk-3.22/menu.c | ||
|---|---|---|
|   menu_entry_set_sensitive("UNIT_SENTRY", | ||
|                            can_units_do_activity_client(punits, ACTIVITY_SENTRY)); | ||
|   menu_entry_set_sensitive("DO_PARADROP", | ||
|                            can_units_do(punits, can_unit_paradrop)); | ||
|                            can_units_do_on_map(&(wld.map), punits, can_unit_paradrop)); | ||
|   /* FIXME: should conditionally rename "Pillage" to "Pillage..." in cases | ||
|    * where selecting the command results in a dialog box listing options of | ||
|    * what to pillage */ | ||
| client/gui-gtk-4.0/menu.c | ||
|---|---|---|
|                            units_can_do_action(punits, ACTION_ANY, TRUE)); | ||
|   menu_entry_set_sensitive(map, "UNIT_TELEPORT", | ||
|                            can_units_do(punits, can_unit_teleport)); | ||
|                            can_units_do_on_map(&(wld.map), punits, can_unit_teleport)); | ||
|   menu_entry_set_sensitive(map, "BUILD_ROAD", | ||
|                            (can_units_do_any_road(&(wld.map), punits) | ||
| ... | ... | |
|                            can_units_do_activity_client(punits, | ||
|                                                         ACTIVITY_FORTIFYING)); | ||
|   menu_entry_set_sensitive(map, "PARADROP", | ||
|                            can_units_do(punits, can_unit_paradrop)); | ||
|                            can_units_do_on_map(&(wld.map), punits, can_unit_paradrop)); | ||
|   menu_entry_set_sensitive(map, "PILLAGE", | ||
|                            can_units_do_activity_client(punits, ACTIVITY_PILLAGE)); | ||
|   menu_entry_set_sensitive(map, "CLEAN", | ||
| client/gui-gtk-5.0/menu.c | ||
|---|---|---|
|                            units_can_do_action(punits, ACTION_ANY, TRUE)); | ||
|   menu_entry_set_sensitive(map, "UNIT_TELEPORT", | ||
|                            can_units_do(punits, can_unit_teleport)); | ||
|                            can_units_do_on_map(&(wld.map), punits, can_unit_teleport)); | ||
|   menu_entry_set_sensitive(map, "BUILD_ROAD", | ||
|                            (can_units_do_any_road(&(wld.map), punits) | ||
| ... | ... | |
|                            can_units_do_activity_client(punits, | ||
|                                                         ACTIVITY_FORTIFYING)); | ||
|   menu_entry_set_sensitive(map, "PARADROP", | ||
|                            can_units_do(punits, can_unit_paradrop)); | ||
|                            can_units_do_on_map(&(wld.map), punits, can_unit_paradrop)); | ||
|   menu_entry_set_sensitive(map, "PILLAGE", | ||
|                            can_units_do_activity_client(punits, ACTIVITY_PILLAGE)); | ||
|   menu_entry_set_sensitive(map, "CLEAN", | ||
| client/gui-qt/hudwidget.cpp | ||
|---|---|---|
|   } | ||
|   // Paradrop | ||
|   if (can_unit_paradrop(current_unit)) { | ||
|   if (can_unit_paradrop(&(wld.map), current_unit)) { | ||
|     a = new hud_action(this); | ||
|     a->action_shortcut = SC_PARADROP; | ||
|     a->set_pixmap(fc_icons::instance()->get_pixmap("paradrop")); | ||
| client/gui-qt/menu.cpp | ||
|---|---|---|
|         break; | ||
|       case PARADROP: | ||
|         if (can_units_do(punits, can_unit_paradrop)) { | ||
|         if (can_units_do_on_map(&(wld.map), punits, can_unit_paradrop)) { | ||
|           i.value()->setEnabled(true); | ||
|           i.value()->setText(QString(action_id_name_translation(ACTION_PARADROP)) | ||
|                              .replace("&", "&&")); | ||
| ... | ... | |
| void mr_menu::slot_paradrop() | ||
| { | ||
|   unit_list_iterate(get_units_in_focus(), punit) { | ||
|     if (can_unit_paradrop(punit)) { | ||
|     if (can_unit_paradrop(&(wld.map), punit)) { | ||
|       key_unit_paradrop(); | ||
|     } | ||
|   } unit_list_iterate_end; | ||
| client/gui-sdl2/dialogs.c | ||
|---|---|---|
| #endif /* 0 */ | ||
|     /* FIXME: This logic seems to try to mirror do_paradrop() why? */ | ||
|     if (can_unit_paradrop(focus_unit) && client_tile_get_known(ptile) | ||
|     if (can_unit_paradrop(&(wld.map), focus_unit) && client_tile_get_known(ptile) | ||
|         && !(((pcity && pplayers_non_attack(client.conn.playing, city_owner(pcity))) | ||
|               || is_non_attack_unit_tile(ptile, client.conn.playing))) | ||
|         && (unit_type_get(focus_unit)->paratroopers_range >= | ||
| client/gui-sdl2/menu.c | ||
|---|---|---|
|         set_wflag(order_airbase_button, WF_HIDDEN); | ||
|       } | ||
|       if (can_unit_paradrop(punit)) { | ||
|       if (can_unit_paradrop(&(wld.map), punit)) { | ||
|         local_show(ID_UNIT_ORDER_PARADROP); | ||
|       } else { | ||
|         local_hide(ID_UNIT_ORDER_PARADROP); | ||
| client/gui-sdl3/dialogs.c | ||
|---|---|---|
| #endif /* 0 */ | ||
|     /* FIXME: This logic seems to try to mirror do_paradrop() why? */ | ||
|     if (can_unit_paradrop(focus_unit) && client_tile_get_known(ptile) | ||
|     if (can_unit_paradrop(&(wld.map), focus_unit) && client_tile_get_known(ptile) | ||
|         && !(((pcity && pplayers_non_attack(client.conn.playing, city_owner(pcity))) | ||
|               || is_non_attack_unit_tile(ptile, client.conn.playing))) | ||
|         && (unit_type_get(focus_unit)->paratroopers_range >= | ||
| client/gui-sdl3/menu.c | ||
|---|---|---|
|         set_wflag(order_airbase_button, WF_HIDDEN); | ||
|       } | ||
|       if (can_unit_paradrop(punit)) { | ||
|       if (can_unit_paradrop(&(wld.map), punit)) { | ||
|         local_show(ID_UNIT_ORDER_PARADROP); | ||
|       } else { | ||
|         local_hide(ID_UNIT_ORDER_PARADROP); | ||
| common/unit.c | ||
|---|---|---|
|   a friendly city or on an airbase special, has enough movepoints left, and | ||
|   has not paradropped yet this turn. | ||
| **************************************************************************/ | ||
| bool can_unit_teleport(const struct unit *punit) | ||
| bool can_unit_teleport(const struct civ_map *nmap, const struct unit *punit) | ||
| { | ||
|   const struct civ_map *nmap = &(wld.map); | ||
|   action_by_result_iterate(paction, ACTRES_TELEPORT) { | ||
|     if (action_maybe_possible_actor_unit(nmap, action_id(paction), punit)) { | ||
|       return TRUE; | ||
| ... | ... | |
|   a friendly city or on an airbase special, has enough movepoints left, and | ||
|   has not paradropped yet this turn. | ||
| **************************************************************************/ | ||
| bool can_unit_paradrop(const struct unit *punit) | ||
| bool can_unit_paradrop(const struct civ_map *nmap, const struct unit *punit) | ||
| { | ||
|   const struct civ_map *nmap = &(wld.map); | ||
|   action_by_result_iterate(paction, ACTRES_PARADROP) { | ||
|     if (action_maybe_possible_actor_unit(nmap, action_id(paction), punit)) { | ||
|       return TRUE; | ||
| common/unit.h | ||
|---|---|---|
| bool can_unit_unload(const struct unit *punit, const struct unit *ptrans); | ||
| bool can_unit_deboard_or_be_unloaded(const struct unit *pcargo, | ||
|                                      const struct unit *ptrans); | ||
| bool can_unit_teleport(const struct unit *punit); | ||
| bool can_unit_paradrop(const struct unit *punit); | ||
| bool can_unit_teleport(const struct civ_map *nmap, const struct unit *punit); | ||
| bool can_unit_paradrop(const struct civ_map *nmap, const struct unit *punit); | ||
| bool can_unit_change_homecity_to(const struct unit *punit, | ||
|                                  const struct city *pcity); | ||
| bool can_unit_change_homecity(const struct unit *punit); | ||
| common/unitlist.c | ||
|---|---|---|
|   return FALSE; | ||
| } | ||
| /************************************************************************//** | ||
|   Return TRUE if the function returns true for any of the units, | ||
|   on specific map. | ||
| ****************************************************************************/ | ||
| bool can_units_do_on_map(const struct civ_map *nmap, | ||
|                          const struct unit_list *punits, | ||
|                          bool (can_fn)(const struct civ_map *nmap, | ||
|                                        const struct unit *punit)) | ||
| { | ||
|   unit_list_iterate(punits, punit) { | ||
|     if (can_fn(nmap, punit)) { | ||
|       return TRUE; | ||
|     } | ||
|   } unit_list_iterate_end; | ||
|   return FALSE; | ||
| } | ||
| /************************************************************************//** | ||
|   Returns TRUE if any of the units can do the activity. | ||
| ****************************************************************************/ | ||
| common/unitlist.h | ||
|---|---|---|
| bool can_units_do(const struct unit_list *punits, | ||
|                   bool (can_fn)(const struct unit *punit)); | ||
| bool can_units_do_on_map(const struct civ_map *nmap, | ||
|                          const struct unit_list *punits, | ||
|                          bool (can_fn)(const struct civ_map *nmap, | ||
|                                        const struct unit *punit)); | ||
| bool can_units_do_activity(const struct civ_map *nmap, | ||
|                            const struct unit_list *punits, | ||
|                            enum unit_activity activity); | ||