📄 tac_class.cpp
字号:
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// Tactical Engagement - Robin Heydon
//
// Implements the user interface for the tactical engagement section
// of falcon 4.0
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#include "falclib.h"
#include "vu2.h"
#include "chandler.h"
#include "ui95_ext.h"
#include "uicomms.h"
#include "userids.h"
#include "textids.h"
#include "F4Error.h"
#include "F4Find.h"
//#include "sim\include\simbase.h"
#include "cmpclass.h"
#include "tac_class.h"
#include "te_defs.h"
#include "team.h"
#include "unit.h"
#include "team.h"
#include "CmpGlobl.h"
#include "CampCell.h"
#include "CampTerr.h"
#include "find.h"
#include "division.h"
#include "cmap.h"
#include "flight.h"
#include "campwp.h"
#include "Listadt.h"
#include "objectiv.h"
#include "Campaign.h"
#include "classtbl.h"
#include "falcsess.h"
#include "gps.h"
#include "teamdata.h"
#include "Dispcfg.h"
#include "msginc\senduimsg.h"
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
int get_tactical_number_of_teams (void);
int get_tactical_number_of_aircraft (int);
int get_tactical_number_of_f16s (int);
void update_team_victory_window (void);
void UpdateVCOptions(victory_condition *vc);
extern long ShowGameOverWindow;
extern char gUI_CampaignFile[];
extern _TCHAR gUI_ScenarioName[];
extern uchar gSelectedTeam;
extern C_Map
*gMapMgr;
extern C_TreeList
*gVCTree;
extern long gRefreshScoresList;
extern short InCleanup;
int string_compare_extensions (char*, char*);
extern FILE* OpenCampFile (char *filename, char *ext, char *mode);
extern void StartCampaignGame (int local, int game_type);
extern void CloseCampFile (FILE *fp);
C_Victory *MakeVCControl(victory_condition *vc);
void MakeTacEngScoreList();
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
int tactical_mission::hide_enemy_on(void)
{
return (TheCampaign.TE_flags & tf_hide_enemy) && TRUE;
}
int tactical_mission::lock_ato_on(void)
{
return (TheCampaign.TE_flags & tf_lock_ato) && TRUE;
}
int tactical_mission::lock_oob_on(void)
{
return (TheCampaign.TE_flags & tf_lock_oob) && TRUE;
}
int tactical_mission::start_paused_on(void)
{
return (TheCampaign.TE_flags & tf_start_paused) && TRUE;
}
int tactical_mission::is_flag_on(long value)
{
return (TheCampaign.TE_flags & value) && TRUE;
}
void tactical_mission::set_flag(long value)
{
TheCampaign.TE_flags |= value;
}
void tactical_mission::clear_flag(long value)
{
TheCampaign.TE_flags &= ~value;
}
tactical_mission::tactical_mission (char *the_filename)
{
TheCampaign.TE_type = tt_unknown;
filename = new char[strlen (the_filename) + 1];
strcpy (filename, the_filename);
is_new = FALSE;
is_online = FALSE;
number_teams = 0;
memset (number_aircraft, 0, sizeof (number_aircraft));
memset (number_players, 0, sizeof (number_players));
memset (number_f16s, 0, sizeof (number_f16s));
memset (team_name, 0, sizeof (team_name));
memset (team_pts, 0, sizeof (team_pts));
conditions = NULL;
TheCampaign.TE_flags = 0;
filter = vcf_all;
team = 1;
game_over=0;
points_required = 0;
info_load (the_filename);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
tactical_mission::tactical_mission (void)
{
TheCampaign.TE_type = tt_engagement;
filename = NULL;
is_new = FALSE;
is_online = TRUE;
number_teams = 0;
memset (number_aircraft, 0, sizeof (number_aircraft));
memset (number_players, 0, sizeof (number_players));
memset (number_f16s, 0, sizeof (number_f16s));
memset (team_name, 0, sizeof (team_name));
memset (team_pts, 0, sizeof (team_pts));
conditions = NULL;
TheCampaign.TE_flags = 0;
filter = vcf_all;
team = 1;
points_required = 0;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
tactical_mission::~tactical_mission (void)
{
if (filename)
{
delete filename;
filename = NULL;
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void tactical_mission::set_type (tactical_type new_type)
{
TheCampaign.TE_type = new_type;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
tactical_type tactical_mission::get_type (void)
{
return (tactical_type) TheCampaign.TE_type;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
char *tactical_mission::get_title (void)
{
static char
buffer[100];
char
*end,
*dst,
*ptr;
if (filename)
{
end = filename;
ptr = filename;
dst = buffer;
while (*ptr)
{
*dst = *ptr;
if (*ptr == '\\')
{
dst = buffer;
end = NULL;
}
else if (*ptr == '.')
{
end = dst ++;
}
else
{
dst ++;
}
ptr ++;
}
*dst = '\0';
if (end)
{
*end = '\0';
}
}
else
{
strcpy (buffer, "MIA");
}
return buffer;
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
void tactical_mission::save_data (char *savefile)
{
FILE
*fp;
VU_ID
id;
victory_condition
*vc;
int
loop;
if ((fp = OpenCampFile (savefile, "te", "wb")) == NULL)
return;
if (conditions)
{
fprintf (fp, ":Victory\n");
victory_condition::enter_critical_section ();
vc = conditions;
while (vc)
{
id = vc->get_vu_id ();
// team, type, vu_id, value, tolerance, points
fprintf
(
fp,
"%d %d %d %d %d %d %d\n",
vc->get_team (),
vc->get_type (),
id.num_,
id.creator_,
vc->get_sub_objective (),
vc->get_tolerance (),
vc->get_points ()
);
vc = vc->succ;
}
victory_condition::leave_critical_section ();
}
if (points_required)
{
fprintf (fp, ":Required\n%d\n", points_required);
}
fprintf (fp, ":Teams\n%d\n", get_tactical_number_of_teams ());
for (loop = 1; loop < 8; loop ++)
{
if(TeamInfo[loop])
{
fprintf
(
fp,
":Team\n%d %d %d\n",
loop,
get_tactical_number_of_aircraft (loop),
get_tactical_number_of_f16s (loop)
);
fprintf (fp, ":TeamName\n%s\n", TeamInfo[loop]->GetName ());
fprintf (fp, ":TeamFlag\n%d\n", TeamInfo[loop]->GetFlag ());
}
}
if (filename)
{
strcpy (gUI_CampaignFile, filename);
}
CloseCampFile (fp);
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
void tactical_mission::save (char *filename)
{
long saveIP,saveIter;
if(TheCampaign.Flags & CAMP_TACTICAL_EDIT)
{
TheCampaign.SetCreatorIP(0);
TheCampaign.SetCreationTime(0);
TheCampaign.SetCreationIter(0);
TheCampaign.SaveCampaign (game_TacticalEngagement, filename, 0); // Save Normal
}
else
{
if(FalconLocalGame->IsLocal())
{
gCommsMgr->SaveStats();
TheCampaign.SetCreationIter(TheCampaign.GetCreationIter()+1);
TheCampaign.SaveCampaign (game_TacticalEngagement, filename, 0); // Save Normal
if(gCommsMgr->Online())
{
// Send messages to remote players with new Iter Number
// So they can save their stats & update Iter in their campaign
gCommsMgr->UpdateGameIter();
}
}
else
{ // This person is making a LOCAL copy of someone elses game...
// we can save His stats... but remote people will be SOL if he
// tries to make this a remote game for them
saveIP=TheCampaign.GetCreatorIP();
saveIter=TheCampaign.GetCreationIter();
TheCampaign.SetCreatorIP(FalconLocalSessionId.creator_);
TheCampaign.SetCreationIter(1);
gCommsMgr->SaveStats();
TheCampaign.SaveCampaign (game_TacticalEngagement, filename, 0); // Save Normal
TheCampaign.SetCreatorIP(saveIP);
TheCampaign.SetCreationIter(saveIter);
}
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
void tactical_mission::process_load (char *data, int size, int)
{
char
*ptr=NULL,
buffer[1000];
int
len=0,
team=0,
x=0,
y=0,
loop=0;
enum tokens
{
t_null,
t_type,
t_marque,
t_victory_condition,
t_flags,
t_points_required,
t_number_teams,
t_team_info,
t_team_name,
t_team_flag
}
current_state = t_null;
struct
{
char *str;
tokens token;
}
token_str[] =
{
"type", t_type,
"victory", t_victory_condition,
"flags", t_flags,
"required", t_points_required,
"teams", t_number_teams,
"team", t_team_info,
"teamname", t_team_name,
"teamflag", t_team_flag,
NULL, t_null
};
while (size)
{
ptr = buffer;
while (size)
{
*ptr = *data;
if ((*ptr == '\r') || (*ptr == '\n'))
{
while ((size) && ((*data == '\n') || (*data == '\r') || (*data == '\t') || (*data == ' ')))
{
data ++;
size --;
}
break;
}
ptr ++;
data ++;
size --;
}
*ptr = '\0';
// Find the length of the input
len = strlen (buffer);
// while we have some characters and they are not "good" characters, just chop the string shorter.
while
(
(len > 0) &&
(
(buffer[len - 1] == '\n') ||
(buffer[len - 1] == '\r') ||
(buffer[len - 1] == '\t') ||
(buffer[len - 1] == ' ')
)
)
{
buffer[len - 1] = '\0';
len --;
}
// Ok, we are now stripped.
// Is it a command we know about, if so, update the current_state.
if (buffer[0] == ':')
{
current_state = t_null;
for (loop = 0; token_str[loop].str; loop ++)
{
if (_stricmp (token_str[loop].str, &buffer[1]) == 0)
{
current_state = token_str[loop].token;
break;
}
}
}
else if (buffer[0] != '\0') // Otherwise, do we have something to set this state's value to.
{
switch (current_state)
{
case t_type:
{
if (strnicmp (buffer, "Training", 8) == 0)
{
TheCampaign.TE_type = tt_training;
}
else if (strnicmp (buffer, "Engagement", 10) == 0)
{
TheCampaign.TE_type = tt_engagement;
}
else if (strnicmp (buffer, "Single", 6) == 0)
{
TheCampaign.TE_type = tt_single;
}
else if (strnicmp (buffer, "Load", 4) == 0)
{
//support old files
TheCampaign.TE_type = tt_engagement;
}
else
{
MonoPrint ("Unknown Type: ");
MonoPrint (filename);
MonoPrint (" ");
MonoPrint (buffer);
MonoPrint ("\n");
}
break;
}
case t_flags:
{
TheCampaign.TE_flags = atoi (buffer);
TheCampaign.TE_flags &= ~tf_start_paused; // Don't set the paused flag
break;
}
case t_victory_condition:
{
setup_victory_condition (buffer);
break;
}
case t_points_required:
{
set_points_required (atoi (buffer));
break;
}
case t_number_teams:
{
number_teams = atoi (buffer);
break;
}
case t_team_info:
{
sscanf (buffer, "%d %d %d", &team, &x, &y);
number_aircraft[team] = x;
number_f16s[team] = y;
break;
}
case t_team_name:
{
set_team_name (team, buffer);
break;
}
case t_team_flag:
{
set_team_flag (team, atoi (buffer));
break;
}
default:
{
break;
}
}
}
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
char *tactical_mission::read_te_file (char *filename, int *size)
{
FILE
*fp;
int
str_len,
num_files,
offset;
char
name[100],
te_filename[100],
*ext,
*src,
*dst,
*ptr;
ptr = filename;
ext = ptr;
dst = te_filename;
src = NULL;
while (*ptr)
{
*dst ++ = *ptr;
if (*ptr == '.')
{
src = dst;
ext = ptr + 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -