Skip to content

Commit

Permalink
Make flak only show up on the map after discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
ec429 committed Mar 13, 2016
1 parent 0e5cd67 commit d40c85e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ SDL_Surface *render_flak(date now)
SDL_FillRect(rv, &(SDL_Rect){.x=0, .y=0, .w=rv->w, .h=rv->h}, ATG_ALPHA_TRANSPARENT&0xff);
for(unsigned int i=0;i<nflaks;i++)
{
if(!flaks[i].mapped) continue;
if(!datewithin(now, flaks[i].entry, flaks[i].exit)) continue;
bool rad=!datebefore(now, flaks[i].radar);
unsigned int x=flaks[i].lon, y=flaks[i].lat, str=flaks[i].strength;
Expand Down
9 changes: 8 additions & 1 deletion run_raid.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ screen_id run_raid_screen(atg_canvas *canvas, game *state)
state->bombers[k].navlon=0;
state->bombers[k].driftlat=0;
state->bombers[k].driftlon=0;
state->bombers[k].flakreport=-1;
double askill=0; // Airmanship
for(unsigned int l=0;l<MAX_CREW;l++)
{
Expand Down Expand Up @@ -1026,6 +1027,9 @@ screen_id run_raid_screen(atg_canvas *canvas, game *state)
unsigned int x=flaks[i].lon/2, y=flaks[i].lat/2;
double wea=((x<128)&&(y<128))?state->weather.p[x][y]-1000:0;
double preccap=160.0/(5.0*(moonillum+.3)/(double)(8+max(4-wea, 0)));
// We have been fired at by this flak, so we know it exists
if(!flaks[i].mapped)
state->bombers[k].flakreport=i;
if(rad) preccap=min(preccap, window?960.0:480.0);
if(brandp(flaks[i].strength*flakscale/min((12+flaks[i].shots++)*40.0, preccap)))
{
Expand Down Expand Up @@ -1899,7 +1903,10 @@ screen_id run_raid_screen(atg_canvas *canvas, game *state)
i--;
continue;
}
else if(state->bombers[i].damage>50)
int fr=state->bombers[i].flakreport;
if(fr>=0&&fr<(int)nflaks)
flaks[fr].mapped=true;
if(state->bombers[i].damage>50)
{
fa_append(&state->hist, state->now, (harris_time){11, 00}, state->bombers[i].id, false, type, 1);
state->bombers[i].failed=true; // mark as u/s
Expand Down
4 changes: 4 additions & 0 deletions save/save-format
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ for(i=0;i<nfighters;i++)
"Type %u:%u,%u,NOID\n", fighter[i].type, fighter[i].base, fighter[i].radar
or
"Type %u:%u,%u,%s\n", fighter[i].type, fighter[i].base, fighter[i].radar, pacid(fighter[i].id)
"Flaks:%u\n", nflaks // should be a constant
optional // else assume flags=0 for all sites
for(i=0;i<nflaks;i++)
"Site %u:%u\n", i, flags // flag 1 is flaks[i].mapped; no others defined
either
{
"Targets:%hhu\n", ntargs // should be a constant
Expand Down
53 changes: 53 additions & 0 deletions saving.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ int loadgame(const char *fn, game *state)
state->weather.seed=0;
for(unsigned int i=0;i<DIFFICULTY_CLASSES;i++) // default everything to medium
state->difficulty[i]=1;
for(unsigned int i=0;i<nflaks;i++) // all flaksites are unmapped if not saved
flaks[i].mapped=false;
while(!feof(fs))
{
char *line=fgetl(fs);
Expand Down Expand Up @@ -506,6 +508,51 @@ int loadgame(const char *fn, game *state)
}
}
}
else if(strcmp(tag, "Flaks")==0)
{
unsigned int snflaks;
f=sscanf(dat, "%u\n", &snflaks);
if(f!=1)
{
fprintf(stderr, "1 Too few arguments to tag \"%s\"\n", tag);
e|=1;
}
else if(snflaks!=nflaks)
{
fprintf(stderr, "2 Value mismatch: different nflaks value\n");
e|=2;
}
else
{
for(unsigned int i=0;i<nflaks;i++)
{
free(line);
line=fgetl(fs);
if(!line)
{
fprintf(stderr, "64 Unexpected EOF in tag \"%s\"\n", tag);
e|=64;
break;
}
unsigned int j;
unsigned int flags;
f=sscanf(line, "Site %u:%u\n", &j, &flags);
if(f!=2)
{
fprintf(stderr, "1 Too few arguments to part %u of tag \"%s\"\n", i, tag);
e|=1;
break;
}
if(j!=i)
{
fprintf(stderr, "4 Index mismatch in part %u (%u?) of tag \"%s\"\n", j, i, tag);
e|=4;
break;
}
flaks[i].mapped=flags&1;
}
}
}
else if(strcmp(tag, "Targets init")==0)
{
double dmg,flk,heat,flam;
Expand Down Expand Up @@ -807,6 +854,12 @@ int savegame(const char *fn, game state)
flags |= 1;
fprintf(fs, "Type %u:%u,%u,%s\n", state.fighters[i].type, state.fighters[i].base, flags, p_id);
}
fprintf(fs, "Flaks:%u\n", nflaks);
for(unsigned int i=0;i<nflaks;i++)
{
unsigned int flags=(flaks[i].mapped?1:0);
fprintf(fs, "Site %u:%u\n", i, flags);
}
fprintf(fs, "Targets:%u\n", ntargs);
for(unsigned int i=0;i<ntargs;i++)
fprintf(fs, "Targ %u:"FLOAT","FLOAT","FLOAT","FLOAT"\n", i, CAST_FLOAT state.dmg[i], CAST_FLOAT (targs[i].flak?state.flk[i]*100.0/(double)targs[i].flak:0), CAST_FLOAT state.heat[i], CAST_FLOAT state.flam[i]);
Expand Down
2 changes: 2 additions & 0 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ typedef struct
//STRENGTH:LAT:LONG:ENTRY:RADAR:EXIT
unsigned int strength, lat, lon;
date entry, radar, exit;
bool mapped; /* Have we learned of this flaksite's existence? */
/* for Himmelbett fighter control */
unsigned int heat; // number of bombers in the vicinity
signed int ftr; // index of fighter under this radar's control (-1 for none)
Expand Down Expand Up @@ -283,6 +284,7 @@ typedef struct
bool fix; // have a navaid fix? (controls whether to drop skymarker)
unsigned int startt; // take-off time
unsigned int fuelt; // when t (ticks) exceeds this value, turn for home
int flakreport; // first unmapped flaksite we encountered
}
ac_bomber;

Expand Down

0 comments on commit d40c85e

Please sign in to comment.