forked from github/server
- Schiffe treiben nicht ab. Routine vereinfacht, und evtl. den Bug gefunden
This commit is contained in:
parent
7d2ea7b398
commit
95a8068635
|
@ -558,16 +558,18 @@ static void
|
||||||
drifting_ships(region * r)
|
drifting_ships(region * r)
|
||||||
{
|
{
|
||||||
direction_t d;
|
direction_t d;
|
||||||
ship *sh, *sh2;
|
|
||||||
unit *captain;
|
|
||||||
|
|
||||||
if (rterrain(r) == T_OCEAN) {
|
if (rterrain(r) == T_OCEAN) {
|
||||||
for (sh = r->ships; sh;) {
|
ship** shp = &r->ships;
|
||||||
sh2 = sh->next;
|
while (*shp) {
|
||||||
|
ship * sh = *shp;
|
||||||
|
region * rnext = NULL;
|
||||||
|
unit * captain;
|
||||||
|
int d_offset;
|
||||||
|
|
||||||
/* Schiff schon abgetrieben oder durch Zauber geschützt? */
|
/* Schiff schon abgetrieben oder durch Zauber geschützt? */
|
||||||
if (fval(sh, SF_DRIFTED) || is_cursed(sh->attribs, C_SHIP_NODRIFT, 0)) {
|
if (fval(sh, SF_DRIFTED) || is_cursed(sh->attribs, C_SHIP_NODRIFT, 0)) {
|
||||||
sh = sh2;
|
shp = &sh->next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,77 +583,51 @@ drifting_ships(region * r)
|
||||||
|
|
||||||
assert(sh->type->construction->improvement==NULL); /* sonst ist construction::size nicht ship_type::maxsize */
|
assert(sh->type->construction->improvement==NULL); /* sonst ist construction::size nicht ship_type::maxsize */
|
||||||
if (captain && sh->size==sh->type->construction->maxsize && enoughsailors(r, sh) && cansail(r, sh)) {
|
if (captain && sh->size==sh->type->construction->maxsize && enoughsailors(r, sh) && cansail(r, sh)) {
|
||||||
sh = sh2;
|
shp = &sh->next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Leuchtturm: Ok. */
|
/* Leuchtturm: Ok. */
|
||||||
if (check_leuchtturm(r, NULL)) {
|
if (check_leuchtturm(r, NULL)) {
|
||||||
sh = sh2;
|
shp = &sh->next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Auswahl einer Richtung: Zuerst auf Land, dann
|
/* Auswahl einer Richtung: Zuerst auf Land, dann
|
||||||
* zufällig. Falls unmögliches Resultat: vergiß es. */
|
* zufällig. Falls unmögliches Resultat: vergiß es. */
|
||||||
|
d_offset = rand() % MAXDIRECTIONS;
|
||||||
|
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
||||||
|
region * rn = rconnect(r, (direction_t)((d + d_offset) % MAXDIRECTIONS));
|
||||||
|
terrain_t t = rterrain(rn);
|
||||||
|
if (rn!=NULL && (terrain[t].flags & SAIL_INTO)) {
|
||||||
|
rnext = rn;
|
||||||
|
if (t!=T_OCEAN) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (d = 0; d != MAXDIRECTIONS; d++)
|
if (rnext==NULL) {
|
||||||
if (rconnect(r, d) && rterrain(rconnect(r, d)) != T_OCEAN)
|
shp = &sh->next;
|
||||||
break;
|
|
||||||
|
|
||||||
if (d == MAXDIRECTIONS)
|
|
||||||
d = (direction_t)(rand() % MAXDIRECTIONS);
|
|
||||||
|
|
||||||
if (!rconnect(r, d)) {
|
|
||||||
sh = sh2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
region * r2 = rconnect(r, d);
|
|
||||||
int c = 0;
|
|
||||||
while (sh->type->coast[c]!=NOTERRAIN) {
|
|
||||||
if (rterrain(r2) == sh->type->coast[c]) break;
|
|
||||||
++c;
|
|
||||||
}
|
|
||||||
if (sh->type->coast[c]==NOTERRAIN) {
|
|
||||||
sh = sh2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!(terrain[rterrain(rconnect(r, d))].flags & SAIL_INTO)) {
|
|
||||||
sh = sh2;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Das Schiff und alle Einheiten darin werden nun von r
|
/* Das Schiff und alle Einheiten darin werden nun von r
|
||||||
* nach rconnect(r, d) verschoben. Danach eine Meldung. */
|
* nach rnext verschoben. Danach eine Meldung. */
|
||||||
if (fval(sh, SF_DRIFTED)) {
|
sh = move_ship(sh, r, rnext, NULL);
|
||||||
region_list * route = NULL;
|
|
||||||
region * to = rconnect(r, d);
|
|
||||||
/* wenn schon einmal abgetrieben, dann durchreise eintragen */
|
|
||||||
add_regionlist(&route, r);
|
|
||||||
add_regionlist(&route, to);
|
|
||||||
sh = move_ship(sh, r, to, route);
|
|
||||||
free_regionlist(route);
|
|
||||||
} else sh = move_ship(sh, r, rconnect(r, d), NULL);
|
|
||||||
if (!sh) {
|
|
||||||
sh = sh2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (sh!=NULL) {
|
||||||
fset(sh, SF_DRIFTED);
|
fset(sh, SF_DRIFTED);
|
||||||
|
|
||||||
if (rterrain(rconnect(r, d)) != T_OCEAN) {
|
if (rterrain(rnext) != T_OCEAN) {
|
||||||
/* Alle Attribute
|
|
||||||
* sicherheitshalber loeschen und
|
|
||||||
* gegebenenfalls neu setzen. */
|
|
||||||
sh->coast = dir_invert(d);
|
sh->coast = dir_invert(d);
|
||||||
}
|
}
|
||||||
damage_ship(sh, 0.02);
|
damage_ship(sh, 0.02);
|
||||||
|
|
||||||
if (sh->damage>=sh->size * DAMAGE_SCALE)
|
if (sh->damage>=sh->size * DAMAGE_SCALE) {
|
||||||
destroy_ship(sh, rconnect(r, d));
|
destroy_ship(sh, rnext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sh = sh2;
|
if (*shp != sh) shp = &sh->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue