extern Load(string filename) 64;
extern SizeTo(int unit,int x,int y) 65;
extern Print(int i) 66;
extern Action(int unit,int act,int var1,int var2) 67;
extern Create(int nvid,int x,int y,int z) 68;//возвращает уникальный номер созданного объекта
extern GetTime() 69;//возвращает текущее время в 1/1000 секундах
extern PlayAVI(string filename) 70;
extern LoadMenu(string filename) 71;
extern FreeMenu() 72;
extern ScrollLock(int flag) 73;
extern MenuVid() 74;//возвращает nvid нажатой кнопки
extern MenuDir() 75;//возвращает ndirect нажатой кнопки
extern Exit() 76;
extern PlayMidi(string filename) 77;
extern StopMusic() 78;
extern MaxUnit(int nvid,int maxunit) 79;
extern Effect(int effect) 80;
extern SetGraphDetail(int detail) 81;//0-low,1-high
extern SetSound(int volume) 82;//volume=0-100
extern SetMusic(int volume) 83;//volume=0-100
extern SetCursor(int action) 84;//action==-1 -off, 0-15-on and set cursor type
extern Flagman(int army) 85;//возвращает уникальный номер Flagman-а, если его нет, то 0
extern GetObject(int nvid,int x,int y) 86;//возвращает уникальный номер объекта с nvid в x,y
extern AddCommand(int unit,int act,int var1,int var2) 87;
extern GetKey() 88;//возвращает код нажатой кнопки
extern Pause(int flag) 89;
extern Random(int max) 90;//random 0-max
extern PlaySFX(int nsfx) 91;
extern SetGraphMode(int mode) 92;//1-640x480, 2-800x600, 3-1024x768
extern GetInputState() 93;//см #define INPUT_???
extern GetUnitVid(int unit) 94;// unit - уникальный номер объекта, возвращает nvid
extern FirstUnit(int narmy,int typeunit) 95;
       //возвращает ссылку на первого монстра данной армии, данного типа
extern NextUnit() 96;// возвращает ссылку на следующего монстра данной армии
extern PlayAudio(int track1,int track2,int track3,int track4) 97;//проигрывать компашку track=1,...
extern E_InsertTerrain(int x,int y,int nvid,int delflag) 98;
       //вставить или удалить землю с коррекцией окружения
extern FileCopy(string source,string dest) 99;//выполнить системную команду copy
extern Message(string text) 100;//сообщение в окне сообщений на opt_statebar
extern MenuAction(int vid,int dir,int action) 101;//ChangeAction for menu
extern MenuCreate(int nvid,int dir,int x,int y) 102;//возвращает уникальный номер созданного объекта
extern strlen(string str) 103;
extern StateBar(int enable) 104;//if enable!=0 then turn on opt_statebar else turn off
extern MenuSelectVid() 105;//возвращает nvid кнопки над которой мышь
extern SetGamma(int gammaindex) 106;//устанавливает игровую палитру (см. mapedit.exe)
extern SetWind(int wind,int direct) 107;
extern CreateLight(int x,int y,int z,int color) 108;//создать источник света
extern GetX(int unit) 109;//возвращает x кллодтнату
extern GetY(int unit) 110;//возвращает y кллодтнату
extern FWrite(int file,variable) 111;//добавить в файл file переменную variable
extern FRead(int file) 112;//восстановить из файла file переменную
extern FOpen(string filename) 113;//открыть файл возвращает уникальный номер файла
extern FClose(int file) 114;//закрыть файл
extern FCreate(string filename) 115;//создать файл, возвращает уникальный номер файла
extern PrintText(int x,int y,string text,int font) 116;//напечатать текст на экран, возвращает уникальный номер текста
extern PrintFile(int x,int y,string filename,int font) 117;//напечатать текстовой файл на экран,
       //возвращает уникальный номер текста, в файле ESCnn - означает смену фонта
extern DeleteText(int text) 118;//удаляет текст, созданный PrintFile(), PrintText()
extern SetFlagman(int narmy,int unit) 119;//Делает флагманом новую машину
extern Save(string filename) 120;//save map
extern GetCommands(int unit) 121;//возвращает строку команд машины
extern SetCommands(int unit,string com) 122;//устанавливает новые команды из строки комманд
extern AskPlace(int vid,int x,int y,int z) 123;//можно ли поместить данный unit в данные координаты, возвращает мешающий unit
extern GetVidName(int nvid) 124;//возвращает название данного nvid
extern SaveDemo(string filename) 125;//записать следующий файл в demo filename
extern SetPosition(int x,int y) 126;//установить место наблюдения на карте
extern SetVid(int nvid,int type,int var) 127;//изменить параметр внутри вида
extern SetAutoScroll(int flag) 128;
extern GetNetInfo(int type) 129;//возвращает параметры сетевой игры
extern Send(int data) 130;//передает по сети data
extern Receive() 131;//возвращает по сети data
extern SetNet(int flag) 132;//если flag!=0 то устанавливается сетевая игра
extern GetNetKey(int nplayer) 133;//возвращает код нажатой кнопки у сетевого игрока nplayer
extern StopSFX() 134;//прекратить проигрывание SFX
extern mciSendString(string command) 135;//MCI command
extern StopSFX(int nsfx) 136;
extern PlayWAV(string file) 137;//return nsfx for this wav file
extern GetNetInputState(int nplayer) 138;//см #define INPUT_???
extern GetReg(string path,string name) 139;// возвращает строку из реестра

#include "maps\music.ini"
#include "maps\locale.ini"

//type for SetVid
#define VID_MAXHP 1
#define VID_CHILD 2 //2-17
#define VID_GAMMA 18 //18-21
#define VID_PROPERTY 22
#define VID_WEAPONRANGE 23 //вместо nvid -nweapon
#define VID_NARMY 24

//type for GetNetInfo
#define NET_NUMPLAYER  1 //возвращает номер игрока при сетевой игре
#define NET_NAMEPLAYER 2 //возвращает имя игрока при сетевой игре
#define NET_NOPLAYER   6 //возвращает количество игроков в сети
#define NET_CLEARKILL  9 //обнулить счетчики убитых
#define NET_KILLPLAYER 10 //10-25 возвращает число убитых 10-13 1ым игроком, 14-17 2ым игроком,18-21 3им, 22-25 4ым

//type unit
#define u_terrain 1
#define u_object  2
#define u_monster 4
#define u_avia    8
#define u_cannon  16
#define u_sprite  32
#define u_item    64

//sprite state
#define st_command   240
#define st_move    16 //двигаться в направлении gox,goy
#define st_passive 64
#define st_invisible 1024 // невидимый спрайт
#define st_gamma     12288 //номер альтернативной GammaPalette если таковая существует для соответствующего curvid

#define act_stand 0
#define act_build 1
#define act_go    2
#define act_start_move 3
#define act_l_rotate 4
#define act_r_rotate 5
#define act_open   6
#define act_close  7
#define act_fight  8
#define act_salut  9
#define act_stand_open 10
#define act_load   11
#define act_unload 12
#define act_wound  13
#define act_birth  14
#define act_death  15
#define act_menustanddown  0 //action for menu button
#define act_menustandup    1
#define act_menuselectdown 2
#define act_menuselectup   3
#define act_menupressdown  4
#define act_menupressup    5
#define act_menudisable    6 //кнопка не работает

#define act_path_block   31 //path is blocked var1-last dx, var2 -last dy
#define act_additem      32 //var1=nvid
#define act_deleteitem   33 //var1=nvid
#define act_askitem      34 //var1=nvid
#define act_changeweapon 35 //var1=nweapon
#define act_deleteallitem 36
#define act_changeaction 37 //var1=action var2=direct
#define act_path_limit   38 //path is limited of field
#define act_attack       39
#define act_move         40
#define act_buildunit    41 //var1-nvid for building unit
#define act_drawselected 42
#define act_damage       43
#define act_select       44 //вызывает на самом деле act_salut
#define act_nextcommand  45
#define act_init         46 //вызывается из createunit для инициализации нач. значений
#define act_uncom        47 //запрещает выполнение дальнейших команд com для building
#define act_deletetarget 48 //if target ==var1 then target=NULL
#define act_calltact     49
#define act_save         51 //записать информацию относящуюся к данному спрайту в var1
#define act_restore      52
#define act_destroy      54
#define act_coor_attack  56
#define act_child        57 //вызывается из createchild при создании child
#define act_saveframe    58 //записать информацию относящуюся к данному frame в var1
#define act_fullsave     59 //записать всю информацию относящуюся к данному sprite, кроме записанной в act_save
#define act_gettarget    60
#define act_cyclecommand 61 //зацикливание стэка комманд
#define act_changevid    62 //изменить текущий curvid для спрайта, var2 - new action, if var1==-1 action not changed
#define act_addammo      63 //var1-число добавляемых снарядов, var2 - номер оружия
#define act_getammo      64 //var1 - номер оружия
#define act_gethp        65
#define act_clearcom     66 //снять все команды
#define act_setbehave    67 //var1 -new behave
#define act_changecoor   68 //var1-x,var2-y
#define act_getlink      69 //return link sprite
#define act_jump         70 //var1-x,var2-y
#define act_settext      71 //var1-char *
#define act_gettext      72 //return-char *
#define act_settextcount 32 //var1=число выводимых в данный момент символов
#define act_setfile      73 //var1-(char *)filename
#define act_submove      74 //var1-x,var2-y
#define act_setarmy      75 //var1-narmy
#define act_getarmy      76 //return-narmy
#define act_setbuildtime 77 //var1-buildtime
#define act_getbuildtime 78 //return-buildtime
#define act_setstate     79 //var1-new state
#define act_getstate     80 //return-state
#define act_getbehave    81 //return behave
#define act_getaction    82 //return current action
#define act_load_object  83 //var1 loaded object
#define act_unload_object 84 //var1-unloaded object

//for Effect()
#define eff_none       0
#define eff_nuke       1
#define eff_rnuke      2
#define eff_gnuke      3
#define eff_bnuke      4
#define eff_fade       5
#define eff_openwindow 6 //Плавное рождение из центра старой картинки - новой
#define eff_random     255

#define INPUT_LCLICK 1
#define INPUT_RCLICK 2
#define INPUT_LDOWN  16
#define INPUT_RDOWN  32
#define INPUT_LEFT   4
#define INPUT_RIGHT  8
#define INPUT_UP     64
#define INPUT_DOWN   128

#define V_FLYBUSH      31
#define V_M_FIGHTER    46
#define V_M_REPAIR     138
#define V_M_AIRPORT    58
#define V_M_FACTORY    22
#define V_M_FIGHTER    46
#define V_M_CHOPPER    29
#define V_M_RL         79
#define V_M_PLASMATANK 33
#define V_M_GUNTANK    19
#define V_M_MORTIRA    316
#define V_M_LASERTANK  43
#define V_M_MINE       51
#define V_M_MINER      24
#define V_M_AUTOTURREL 157
#define V_M_GUNTURREL  287
#define V_M_MISSILETURREL 188
#define V_M_PLASMATURREL  50
#define V_M_LASERTURREL   198
#define V_M_VIDEOCAMERA   146
#define V_ARTEFACT1    28
#define V_UPGRADE12    271
#define V_MEDIC        114
#define V_AMMO2        230
#define V_FLAGMANHEAD11 88
#define V_FLAGMANHEAD12 202
#define V_FLAGMANHEAD13 207
#define V_TRANSMISSION1 81
#define V_TRANSMISSION2 132
#define V_TRANSMISSION3 143
#define V_RECTANGLE    292
#define V_TEXTMENU     26
#define V_4BUTTON      222
#define V_YOURLOSE     86
#define V_YOURWIN      87
#define V_CREDITS      137
#define V_LOGO         136
#define V_METEORITRAIN 119
#define V_CHOICEMAP    13
#define V_WINNEDMAP    331
#define V_SCREEN       85
#define V_TELEPORT     129
#define V_TP_EFFECT    128
#define V_MANTA        145
#define V_FONT         127

#define OPT_STATEBAR  1
#define OPT_SCROLLING 2 //if non zero then auto scrolling on
#define OPT_DIFFICALT 4 //if non zero then beginner else expert

int cheat;//накопление информации о наборе чит кода
int music1=0,music2=0,music3=0,music4=0;//номнра проигрываемых в уровне трэков
int invisible[4]={0,0,0,0},invulnerable=0;//время начала эффекта, если 0 то нет эффекта
int nukestart,win;
int old_n_map,n_map,map,n_player;//Для передачи информации между разными скриптами
int gamemenu,losemenu,firstmenu=1,net_gamemenu[4]={0,0,0,0};
int opt_player=0,timer_ammo1;
int startnextmap;//время начала отсчета для загрузки следующей карты
string nextmap,player_name;
int noammo[8]={20,80,60,10,10,0,0,0},hp,nweapon[4],weapon[16]={88,0,0,0},kassandra=81;
int upgrade=585;//bit0-weapon11,1-12,...
int count;
int n_flagman=0;//N network flagman
int centr_x,centr_y;//координаты центра экрана
int gamma=0x777,gammamenu=96;//gamma on current map, gamma in menu screen
int menu=0,nmenu,old_nmenu;//menu-уникальный номер textmenu, nmenu-номер textmenu
int gamestate;//если ==1 то работает меню опций, ==2 кончается меню опций, ==3 начинается меню опций, 4 работает меню дизайна, 5 начинается меню дизайна,6-кончается меню дизайна
int opt_detail;//0-low,1-high
int opt_resolution;//0-640x480,1-800x600,2-1024x768
int opt_scrolling;//0-manual scrolling,1-autoscrolling
int opt_sound,opt_music;//0-100%
int text_detail,text_resolution,text_sound,text_music,text_scrolling;
int maxhp=40;
int t_trans,t_weapon[4],t_ammo[4],weapon_screen=0,weapon_noise=0,weapon_text=0;
int weapontable[15];//соотношение номера апгрэйда с nvid
int net_kill[4];//кто кого сколько раз убил в сети
int net_kill_text[4]={0,0,0,0};//спрайты кто кого сколько раз убил в сети
int net_birth[4];//==0 если игрок родился, время смерти если умер
int net_name_text[4]={0,0,0,0};//спрайты имен игроков

NextMap(string nextmapname;int nextmapeffect)
{
  old_n_map=n_map;n_map=0;
  startnextmap=GetTime();Effect(nextmapeffect);nextmap=nextmapname;
}
NextNMap(int next_n_map)
{
  old_n_map=n_map;n_map=next_n_map;
  nextmap="maps\\levels\\01.map";
  nextmap[12]='0'+n_map/10;nextmap[13]='0'+n_map%10;
  startnextmap=GetTime();nextmapeffect=eff_none;Effect(nextmapeffect);
}
SavePlayer()
{
  nextmap="save1";nextmap[4]=n_player+'1';
  win=FCreate(nextmap);
  if(!hp) hp=40;
  FWrite(win,player_name);FWrite(win,map);FWrite(win,nweapon);//del nweapon save
  FWrite(win,hp);
  for(count=0;count<8;count++) FWrite(win,noammo[count]);
  for(count=0;count<4;count++) FWrite(win,weapon[count]);
  FWrite(win,opt_player);
  FWrite(win,kassandra);
  FWrite(win,upgrade);
  FClose(win);nextmap="";
}
LoadPlayer()
{
  nextmap="save1";nextmap[4]=n_player+'1';
  win=FOpen(nextmap);
  player_name=FRead(win);map=FRead(win);nweapon=FRead(win);
  hp=FRead(win);
  for(count=0;count<8;count++) noammo[count]=FRead(win);
  for(count=0;count<4;count++) weapon[count]=FRead(win);
  opt_player=FRead(win);
  kassandra=FRead(win);
  upgrade=FRead(win);
  FClose(win);win=0;nextmap="";
}
Win()
{
  if( !losemenu && nextmap=="" )
  {
    map=map|(1<<(n_map-1));
    hp=Action(Flagman(0),act_gethp,0,0);
    for(count=0;count<8;count++)
      noammo[count]=Action(Flagman(0),act_getammo,count,0);
    for(count=0;count<16;count++)
      if(Action(Flagman(0),act_deleteitem,V_UPGRADE12+count,0))
        upgrade=upgrade|(1<<(count+1));
    SavePlayer();
    Effect(eff_nuke);ScrollLock(1);losemenu=1;win=1;nukestart=GetTime();
  }
}
Lose()
{
  if(!losemenu && nextmap=="")
  {
    Effect(eff_nuke);ScrollLock(1);losemenu=1;win=0;nukestart=GetTime();
  }
}
NetMenuOn()
{
  MenuCreate(25,GetNetInfo(NET_NUMPLAYER),centr_x,centr_y);//network player name
  for(count=0;count<4;count++)
  {
    net_name_text[count]=PrintText(centr_x-9,centr_y-64+count*19,GetNetInfo(NET_NAMEPLAYER+count),V_FONT);
    if(count==0)
      net_kill_text[count]=PrintText(centr_x+131,centr_y-64+count*19,GetNetInfo(NET_KILLPLAYER+count*4+1)+GetNetInfo(NET_KILLPLAYER+count*4+2)+GetNetInfo(NET_KILLPLAYER+count*4+3),V_FONT);
    else if(count==1)
      net_kill_text[count]=PrintText(centr_x+131,centr_y-64+count*19,GetNetInfo(NET_KILLPLAYER+count*4)+GetNetInfo(NET_KILLPLAYER+count*4+2)+GetNetInfo(NET_KILLPLAYER+count*4+3),V_FONT);
    else if(count==2)
      net_kill_text[count]=PrintText(centr_x+131,centr_y-64+count*19,GetNetInfo(NET_KILLPLAYER+count*4)+GetNetInfo(NET_KILLPLAYER+count*4+1)+GetNetInfo(NET_KILLPLAYER+count*4+3),V_FONT);
    else net_kill_text[count]=PrintText(centr_x+131,centr_y-64+count*19,GetNetInfo(NET_KILLPLAYER+count*4)+GetNetInfo(NET_KILLPLAYER+count*4+1)+GetNetInfo(NET_KILLPLAYER+count*4+2),V_FONT);
//    PrintText(centr_x+161,centr_y-64+count*19,GetNetInfo(NET_KILLPLAYER+count*4+1),V_FONT);
//    PrintText(centr_x+191,centr_y-64+count*19,GetNetInfo(NET_KILLPLAYER+count*4+2),V_FONT);
//    PrintText(centr_x+221,centr_y-64+count*19,GetNetInfo(NET_KILLPLAYER+count*4+3),V_FONT);
  }
}
NetMenuOff()
{
  MenuAction(25,GetNetInfo(NET_NUMPLAYER),act_destroy);//destroy network player name
  for(count=0;count<4;count++)
  {
    DeleteText(net_name_text[count]);net_name_text[count]=0;
    DeleteText(net_kill_text[count]);net_kill_text[count]=0;
  }
}
MoveInMenu(int begmenu;int endmenu)
{
  if(GetKey()==4)//down
  {
    Action(menu,act_destroy,0,0);PlaySFX(20);
    if(nmenu<endmenu) menu=MenuCreate(V_TEXTMENU,++nmenu,centr_x,centr_y);
    else menu=MenuCreate(V_TEXTMENU,nmenu=begmenu,centr_x,centr_y);
  } else if(GetKey()==3)//up
  {
    Action(menu,act_destroy,0,0);PlaySFX(20);
    if(nmenu>begmenu) menu=MenuCreate(V_TEXTMENU,--nmenu,centr_x,centr_y);
    else menu=MenuCreate(V_TEXTMENU,nmenu=endmenu,centr_x,centr_y);
  } else return(0);
  return(1);
}
OptionsDraw()
{
  FreeMenu();
  if(opt_resolution) LoadMenu("maps\\options8.men");
  else LoadMenu("maps\\options.men");
  menu=MenuCreate(V_TEXTMENU,nmenu=12,centr_x,centr_y);
  for(count=0;count<10;count++)
    MenuCreate(V_RECTANGLE,count,centr_x-70+(count&1)*200,centr_y-60+(count/2)*19);
  if(opt_resolution==0) text_resolution=PrintText(centr_x-20,centr_y-64,"640x480",V_FONT);
  else text_resolution=PrintText(centr_x-20,centr_y-64,"800x600",V_FONT);
  if(opt_detail) text_detail=PrintText(centr_x-20,centr_y-45,STR_HIGH,V_FONT);
  else text_detail=PrintText(centr_x-20,centr_y-45,STR_LOW,V_FONT);
  text_sound=MenuCreate(268,opt_sound/10,centr_x+63,centr_y-22);
  text_music=MenuCreate(268,opt_music/10,centr_x+63,centr_y-3);
  if(opt_scrolling) text_scrolling=PrintText(centr_x-20,centr_y+12,STR_ON,V_FONT);
  else text_scrolling=PrintText(centr_x-20,centr_y+12,STR_OFF,V_FONT);
}
OptionsOn()
{
  PlaySFX(19);gamestate=1;OptionsDraw();ScrollLock(1);
  if(GetNetInfo(NET_NOPLAYER)) NetMenuOff();
}
OptionsTact()
{
  if( ((MenuVid()==V_4BUTTON || GetKey()==' ' || GetKey()==13) && nmenu==17)
     || GetKey()==27 )
    { startnextmap=GetTime();gamestate=2; }
  if(MenuSelectVid()==V_4BUTTON)
    { Action(menu,act_destroy,0,0);menu=MenuCreate(V_TEXTMENU,nmenu=17,centr_x,centr_y); }
  if(MenuSelectVid()==V_RECTANGLE)
    { Action(menu,act_destroy,0,0);menu=MenuCreate(V_TEXTMENU,nmenu=12+MenuDir()/2,centr_x,centr_y); }
  if((GetTime()-startnextmap)>700 && gamestate==2)
  {
    ScrollLock(0);
    gamestate=0;PlaySFX(19);
    FreeMenu();
    DeleteText(text_resolution);DeleteText(text_detail);DeleteText(text_scrolling);
    count=FCreate("fw.ini");
    FWrite(count,opt_resolution);FWrite(count,opt_detail);
    FWrite(count,opt_sound);FWrite(count,opt_music);
    FWrite(count,opt_scrolling);
    FClose(count);
    if(GetNetInfo(NET_NOPLAYER)) NetMenuOn();
  }
  if(!MoveInMenu(12,17))
    if(GetKey()==1 || GetKey()==2 || GetKey()==13 || GetKey()==' ' || MenuVid()==V_RECTANGLE)//left || right ||...
  {
    if(nmenu==12 && (!GetNetInfo(NET_NOPLAYER) || !net_gamemenu[GetNetInfo(NET_NUMPLAYER)]))
    {
      DeleteText(text_resolution);DeleteText(text_detail);DeleteText(text_scrolling);
      opt_resolution=opt_resolution^1;
      if(opt_resolution==0) { centr_x=320;centr_y=240; }
      else { centr_x=400;centr_y=300; }
      PlaySFX(19);
      SetGraphMode(opt_resolution+1);OptionsDraw();
    } else if(nmenu==13 && !GetNetInfo(NET_NOPLAYER))
    {
      DeleteText(text_detail);opt_detail=opt_detail^1;
      if(opt_detail) text_detail=PrintText(centr_x-20,centr_y-45,STR_HIGH,V_FONT);
      else text_detail=PrintText(centr_x-20,centr_y-45,STR_LOW,V_FONT);
      SetGraphDetail(opt_detail);
    } else if(nmenu==14)
    {
      Action(text_sound,act_destroy,0,0);
      if( GetKey()==2 || (MenuVid()==V_RECTANGLE && (MenuDir()&1)) )
        if(opt_sound<100) opt_sound=opt_sound+10;
      if(GetKey()==1 || (MenuVid()==V_RECTANGLE && !(MenuDir()&1)) )
        if(opt_sound) opt_sound=opt_sound-10;
      text_sound=MenuCreate(268,opt_sound/10,centr_x+63,centr_y-22);
      SetSound(opt_sound);
    } else if(nmenu==15)
    {
      Action(text_music,act_destroy,0,0);
      if( GetKey()==2 || (MenuVid()==V_RECTANGLE && (MenuDir()&1)) )
        if(opt_music<100) opt_music=opt_music+10;
      if(GetKey()==1 || (MenuVid()==V_RECTANGLE && !(MenuDir()&1)) )
        if(opt_music) opt_music=opt_music-10;
      text_music=MenuCreate(268,opt_music/10,centr_x+63,centr_y-3);
      SetMusic(opt_music);
    } else if(nmenu==16 && !GetNetInfo(NET_NOPLAYER))
    {
      DeleteText(text_scrolling);opt_scrolling=opt_scrolling^1;
      if(opt_scrolling) text_scrolling=PrintText(centr_x-20,centr_y+12,STR_ON,V_FONT);
      else text_scrolling=PrintText(centr_x-20,centr_y+12,STR_OFF,V_FONT);
      SetAutoScroll(opt_scrolling);
    }
  }
}
GameMenuOn()
{
  PlayMusic(10,10,10,10);
  FreeMenu();StateBar(0);
  SetGamma(gammamenu);
  if(firstmenu && !GetNetInfo(NET_NOPLAYER)) nmenu=27;else nmenu=31;
  menu=MenuCreate(V_TEXTMENU,nmenu,centr_x,centr_y);
  if((!(map&2) && firstmenu) || GetNetInfo(NET_NOPLAYER)) MenuCreate(298,0,centr_x+195,centr_y+116);//close service centr
  if(GetNetInfo(NET_NOPLAYER) && net_gamemenu[GetNetInfo(NET_NUMPLAYER)]) MenuCreate(298,0,centr_x+251,centr_y+66);//close options
  if(!GetNetInfo(NET_NOPLAYER)) Pause(1);
  nextmap="maps\\levels\\01.txt";
  nextmap[12]='0'+n_map/10;nextmap[13]='0'+n_map%10;
  gamemenu=PrintFile(centr_x-230,centr_y-140,nextmap,V_FONT);nextmap="";
  if(opt_resolution) LoadMenu("maps\\gamemen8.men");
  else LoadMenu("maps\\gamemenu.men");
  if(GetNetInfo(NET_NOPLAYER)) NetMenuOn();
}
GameMenuOff()
{
  PlayMusic(music1,music2,music3,music4);
  PlaySFX(26);
  firstmenu=0;
  SetGamma(gamma);
  DeleteText(gamemenu);gamemenu=0;
  if(GetNetInfo(NET_NOPLAYER)) NetMenuOff();
  FreeMenu();
  if(!GetNetInfo(NET_NOPLAYER)) Pause(0);
  ScrollLock(0);
  StateBar(opt_player&OPT_STATEBAR);
}
DesignMenuOn()
{
  PlayMusic(10,10,10,10);
  PlaySFX(19);
  gamestate=4;StateBar(0);
  SetGamma(624);
  ScrollLock(1);Pause(1);
  FreeMenu();
  if(opt_resolution) LoadMenu("maps\\design8.men");
  else LoadMenu("maps\\design.men");
  menu=MenuCreate(V_TEXTMENU,nmenu=20,centr_x,centr_y);
  weapon_screen=MenuCreate(296,0,centr_x+64,centr_y-84);//картинка оружия
  weapon_noise=0;
  for(count=0;count<4;count++)
  {
    weapontable[count*3]=V_FLAGMANHEAD11+count;
    weapontable[count*3+1]=V_FLAGMANHEAD12+count;
    weapontable[count*3+2]=V_FLAGMANHEAD13+count;
  }
  weapontable[4*3]=V_FLAGMANHEAD11+4;
  for(count=0;count<4;count++)
    if(weapon[count])
    {
      t_weapon[count]=PrintText(centr_x-86,centr_y-37+count*19,GetVidName(weapon[count]),V_FONT);
      if(weapon[count]==V_FLAGMANHEAD13) t_ammo[count]=4;
      else if(weapon[count]>V_FLAGMANHEAD13) t_ammo[count]=weapon[count]-V_FLAGMANHEAD13;
      else if(weapon[count]>=V_FLAGMANHEAD12) t_ammo[count]=weapon[count]-V_FLAGMANHEAD12;
      else if(weapon[count]>=V_FLAGMANHEAD11) t_ammo[count]=weapon[count]-V_FLAGMANHEAD11;
      t_ammo[count]=PrintText(centr_x+127,centr_y-37+count*19,noammo[t_ammo[count]],V_FONT);
    } else
    {
      t_weapon[count]=PrintText(centr_x-86,centr_y-37+count*19,STR_NONE,V_FONT);
      t_ammo[count]=0;
    }
  t_trans=PrintText(centr_x-86,centr_y-37+76,GetVidName(kassandra),V_FONT);
  for(count=0;count<10;count++)
    MenuCreate(V_RECTANGLE,count,centr_x-100+200*(count&1),centr_y-33+(count/2)*19);
}
DesignMenuTact()
{
  if(nmenu!=25)
    if(nmenu==24)
    {
      if(weapon_noise)
      {
        DeleteText(weapon_text);weapon_text=0;
        Action(weapon_noise,act_changeaction,act_death,0);weapon_noise=0;
      }
      if(kassandra==V_TRANSMISSION1)
        Action(weapon_screen,act_changeaction,0,192);
      else if(kassandra==V_TRANSMISSION2)
        Action(weapon_screen,act_changeaction,0,209);
      else Action(weapon_screen,act_changeaction,0,225);
      if(!weapon_text)
      {
        if(kassandra==V_TRANSMISSION1) nextmap="maps\\w13.txt";
        else if(kassandra==V_TRANSMISSION2) nextmap="maps\\w14.txt";
        else nextmap="maps\\w15.txt";
        weapon_text=PrintFile(centr_x-80,centr_y+117,nextmap,V_FONT);
        nextmap="";
      }
    } else
    {
      for(count=0;count<13;count++)
        if(weapontable[count]==weapon[nmenu-20]) break;
      if(count<13)
      {
        if(weapon_noise)
        {
          DeleteText(weapon_text);weapon_text=0;
          Action(weapon_noise,act_changeaction,act_death,0);weapon_noise=0;
        }
        Action(weapon_screen,act_changeaction,0,(count*256+1)/16);
        if(!weapon_text)
        {
          nextmap="maps\\w01.txt";nextmap[6]='0'+(count+1)/10;nextmap[7]='0'+(count+1)%10;
          weapon_text=PrintFile(centr_x-80,centr_y+117,nextmap,V_FONT);
          nextmap="";
        }
      } else if(!weapon_noise)
      {
        DeleteText(weapon_text);weapon_text=0;
        weapon_noise=MenuCreate(105,0,centr_x+64,centr_y-84);
      }
    }
  if( ((MenuVid()==V_4BUTTON || GetKey()==' ' || GetKey()==13) && nmenu==25)
     || GetKey()==27 )
    { startnextmap=GetTime();gamestate=6; }
  if(MenuSelectVid()==V_4BUTTON)
    { Action(menu,act_destroy,0,0);menu=MenuCreate(V_TEXTMENU,nmenu=25,centr_x,centr_y); }
  if(MenuSelectVid()==V_RECTANGLE)
    { Action(menu,act_destroy,0,0);menu=MenuCreate(V_TEXTMENU,nmenu=20+MenuDir()/2,centr_x,centr_y); }
  if( (old_nmenu!=nmenu || MenuVid()==V_RECTANGLE || GetKey()==1 || GetKey()==2 || GetKey()==' ' || GetKey()==13)
      && !weapon_noise )
  {
    DeleteText(weapon_text);weapon_text=0;
    weapon_noise=MenuCreate(105,0,centr_x+64,centr_y-84);
    old_nmenu=nmenu;
  }
  if((GetTime()-startnextmap)>700 && gamestate==6)
  {
    DeleteText(weapon_text);weapon_text=0;
    ScrollLock(0);
    gamestate=0;PlaySFX(19);
    SetGamma(gamma);
    weapon_screen=0;FreeMenu();
    for(count=0;count<4;count++) { DeleteText(t_weapon[count]);DeleteText(t_ammo[count]); }
    DeleteText(t_trans);
    if(kassandra==V_TRANSMISSION1) maxhp=40;
    else if(kassandra==V_TRANSMISSION2) maxhp=50;
    else maxhp=33;
    if( !(opt_player&OPT_DIFFICALT) ) maxhp=(maxhp*3)/2;
    SetVid(kassandra,VID_MAXHP,maxhp);
    if(gamemenu) SavePlayer();//если мы настраивали машину не в середине игры то записать ее конфигурацию
    return;
  }
  MoveInMenu(20,25);
  if(MenuVid()==V_RECTANGLE || GetKey()==1 || GetKey()==2 || GetKey()==' ' || GetKey()==13)
  {
    if(nmenu==20)//первый слот
    {
      Action(t_weapon[0],act_destroy,0,0);Action(t_ammo[0],act_destroy,0,0);
      t_weapon[0]=t_ammo[0]=0;
      for(count=0;count<3;count++) if(upgrade&(1<<count)) break;
      if(count>=3)
      {
        t_weapon[0]=PrintText(centr_x-77,centr_y-37+3*19,STR_NONE,V_FONT);
        weapon[0]=0;
        return;
      }
      for(count=0;count<3;count++)
        if(weapontable[count]==weapon[0]) break;
      if(GetKey()==2 || ((MenuDir()&1) && GetKey()!=1))
      {
        if(++count>=3) count=0;
        while( !(upgrade&(1<<count)) ) if(++count>=3) count=0;
      } else
      {
        if(--count<0) count=2;
        while( !(upgrade&(1<<count)) ) if(--count<0) count=2;
      }
      weapon[0]=weapontable[count];
      t_weapon[0]=PrintText(centr_x-86,centr_y-37,GetVidName(weapon[0]),V_FONT);
      if(weapon[0]==V_FLAGMANHEAD13) t_ammo[0]=4; else t_ammo[0]=0;
      t_ammo[0]=PrintText(centr_x+127,centr_y-37,noammo[t_ammo[0]],V_FONT);
    } else if(nmenu<23)//2,3 слоты
    {
      Action(t_weapon[nmenu-20],act_destroy,0,0);Action(t_ammo[nmenu-20],act_destroy,0,0);
      t_weapon[nmenu-20]=t_ammo[nmenu-20]=0;
      for(count=3;count<9;count++) if(upgrade&(1<<count)) break;
      if(count>=9)
      {
        t_weapon[nmenu-20]=PrintText(centr_x-77,centr_y-37+(nmenu-20)*19,STR_NONE,V_FONT);
        weapon[nmenu-20]=0;
        return;
      }
      for(count=3;count<9;count++)
        if(weapontable[count]==weapon[nmenu-20]) break;
      if(GetKey()==2 || ((MenuDir()&1) && GetKey()!=1))
      {
        if(++count>=9) count=3;
        while( !(upgrade&(1<<count)) ) if(++count>=9) count=3;
      } else
      {
        if(--count<3) count=8;
        while( !(upgrade&(1<<count)) ) if(--count<3) count=8;
      }
      weapon[nmenu-20]=weapontable[count];
      t_weapon[nmenu-20]=PrintText(centr_x-86,centr_y-37+(nmenu-20)*19,GetVidName(weapon[nmenu-20]),V_FONT);
      if(weapon[nmenu-20]>V_FLAGMANHEAD13) t_ammo[nmenu-20]=weapon[nmenu-20]-V_FLAGMANHEAD13;
      else if(weapon[nmenu-20]>=V_FLAGMANHEAD12) t_ammo[nmenu-20]=weapon[nmenu-20]-V_FLAGMANHEAD12;
      else if(weapon[nmenu-20]>=V_FLAGMANHEAD11) t_ammo[nmenu-20]=weapon[nmenu-20]-V_FLAGMANHEAD11;
      t_ammo[nmenu-20]=PrintText(centr_x+127,centr_y-37+(nmenu-20)*19,noammo[t_ammo[nmenu-20]],V_FONT);
    } else if(nmenu==23)// четвертый задний слот
    {
      Action(t_weapon[3],act_destroy,0,0);Action(t_ammo[3],act_destroy,0,0);
      t_weapon[3]=t_ammo[3]=0;
      for(count=9;count<12;count++) if(upgrade&(1<<count)) break;
      if(count>=12)
      {
        t_weapon[3]=PrintText(centr_x-86,centr_y-37+3*19,STR_NONE,V_FONT);
        weapon[3]=0;
        return;
      }
      for(count=9;count<12;count++)
        if(weapontable[count]==weapon[3]) break;
      if(GetKey()==2 || ((MenuDir()&1) && GetKey()!=1))
      {
        if(++count>=12) count=9;
        while( !(upgrade&(1<<count)) ) if(++count>=12) count=9;
      } else
      {
        if(--count<9) count=11;
        while( !(upgrade&(1<<count)) ) if(--count<9) count=11;
      }
      weapon[3]=weapontable[count];
      t_weapon[3]=PrintText(centr_x-86,centr_y-37+3*19,GetVidName(weapon[3]),V_FONT);
      t_ammo[3]=PrintText(centr_x+127,centr_y-37+3*19,noammo[3],V_FONT);
    } else if(nmenu==24)//ходовая часть
    {
      Action(t_trans,act_destroy,0,0);
      if(GetKey()==2 || ((MenuDir()&1) && GetKey()!=1))
        if(kassandra==V_TRANSMISSION1)
          if(upgrade&(1<<14)) kassandra=V_TRANSMISSION2;
          else if(upgrade&(1<<15)) kassandra=V_TRANSMISSION3;else;
        else if(kassandra==V_TRANSMISSION2)
          if(upgrade&(1<<15)) kassandra=V_TRANSMISSION3;
          else kassandra=V_TRANSMISSION1;
        else kassandra=V_TRANSMISSION1;
      else if(kassandra==V_TRANSMISSION1)
          if(upgrade&(1<<15)) kassandra=V_TRANSMISSION3;
          else if(upgrade&(1<<14)) kassandra=V_TRANSMISSION2;else;
        else if(kassandra==V_TRANSMISSION3)
          if(upgrade&(1<<14)) kassandra=V_TRANSMISSION2;
          else kassandra=V_TRANSMISSION1;
        else kassandra=V_TRANSMISSION1;
      t_trans=PrintText(centr_x-86,centr_y-37+76,GetVidName(kassandra),V_FONT);
    }
  }
}
Tact()
{
//  if(GetKey()=='l') ScrollLock(0);//cheat code
//  if(GetKey()=='m') FreeMenu();//cheat code
//  if(GetKey()=='n') Effect(eff_nuke);
//  if(GetKey()=='r') Effect(eff_rnuke);
//  if(GetKey()=='g') Effect(eff_gnuke);
//  if(GetKey()=='b') Effect(eff_bnuke);
//  if(GetKey()=='f') Effect(eff_fade);
  if(cheat=='t')//cheat code
  {
    if(GetKey()=='i') SetVid(kassandra,VID_MAXHP,0);
    else if(GetKey()=='w') Win();
    else if(GetKey()=='a')
      for(count=1;count<5;count++) Action(Flagman(0),act_addammo,256,count);
//    else if(GetKey()=='F')
//      Action(Flagman(0),act_addammo,256,4);
    else if(GetKey()=='A') upgrade=1073741823;//все оружие
    if(GetKey()) cheat=0;
  } else if(cheat=='a' && GetKey()=='t') cheat='t';
  else  if(cheat=='e' && GetKey()=='a') cheat='a';
  else  if(cheat=='h' && GetKey()=='e') cheat='e';
  else  if(cheat=='c' && GetKey()=='h') cheat='h';
  else  if(GetKey()=='c') cheat='c';
  else if(GetKey()) cheat=0;
  iff(n_map>0 && n_map<30)
  {
    SetFlagman(0,0);
    LoadPlayer();
    if(kassandra==V_TRANSMISSION1) maxhp=40;
    else if(kassandra==V_TRANSMISSION2) maxhp=50;
    else maxhp=33;
    if( !(opt_player&OPT_DIFFICALT) ) maxhp=(maxhp*3)/2;
    SetVid(kassandra,VID_MAXHP,maxhp);
    gamemenu=0;losemenu=0;nukestart=0;win=0;
//    if( !(map&(1<<(n_map-1))) )
    {
      GameMenuOn();
      Action(gamemenu,act_settextcount,0,0);
      MenuAction(108,0,act_destroy);//glass destroy
    }
  }
  if(gamestate)
  {
    if(gamestate==3)
      if((GetTime()-startnextmap)>700)
        { DeleteText(gamemenu);OptionsOn(); }
      else return(1);
    if(gamestate==5)
      if((GetTime()-startnextmap)>700)
        { DeleteText(gamemenu);DesignMenuOn(); }
      else return(1);
    if(gamestate==1 || gamestate==2) OptionsTact();
    if(gamestate==4 || gamestate==6) DesignMenuTact();
    if(!gamestate && gamemenu) GameMenuOn();
    return(1);
  }
  if(gamemenu)
  {
    if(nmenu<30)
      if(!(map&2) && firstmenu) MoveInMenu(26,28);else MoveInMenu(26,29);
    else MoveInMenu(30,33);
    if(GetKey()==13 || MenuVid()==V_4BUTTON || GetKey()==' ')
    {
      if(nmenu==26 || nmenu==30) NextMap("maps\\maps.map",eff_none);//logoff
      if(nmenu==27 || nmenu==31) { GameMenuOff();return(0); }
      if(nmenu==28 || nmenu==32) { gamestate=3;startnextmap=GetTime(); }//options
      if(nmenu==29) { gamestate=5;startnextmap=GetTime(); }//service center
      if(nmenu==33) NextNMap(n_map);//restart
    } else if(MenuSelectVid()==V_4BUTTON)
    {
      Action(menu,act_destroy,0,0);
      if(nmenu<30) nmenu=MenuDir()+26;else nmenu=MenuDir()+30;
      menu=MenuCreate(V_TEXTMENU,nmenu,centr_x,centr_y);
    }
  }
  if(losemenu)
  {
    iff((GetTime()-nukestart)>600) StateBar(0);
    iff((GetTime()-nukestart)>2000 && win) { Effect(eff_nuke);MenuCreate(V_YOURWIN,0,centr_x,centr_y); }
    iff((GetTime()-nukestart)>4000 && !win) { Effect(eff_nuke);MenuCreate(V_YOURLOSE,0,centr_x,centr_y); }
    iff((GetTime()-nukestart)>4000 && win) { PlaySFX(37);StopMusic(); }
    iff((GetTime()-nukestart)>6000 && !win) { PlaySFX(36);StopMusic(); }
    iff((GetTime()-nukestart)>20000 && nextmap=="") NextMap("maps\\maps.map",eff_fade);//exit to choice map
    if((GetTime()-nukestart)<4000 && win) return(0);
    if((GetTime()-nukestart)<6000 && !win) return(0);
  }
  if((MenuVid()==V_YOURLOSE || MenuVid()==V_YOURWIN) && nextmap=="")
    NextMap("maps\\maps.map",eff_fade);//exit to choice map
  if(GetKey()==27)
    if(losemenu) NextMap("maps\\maps.map",eff_fade);//exit to choice map
    else if(gamemenu)
      if(!Flagman(0)) NextMap("maps\\maps.map",eff_none);//exit to choice map
      else { GameMenuOff();return(0); }
    else { GameMenuOn();PlaySFX(26); }
  if(nextmap!="")
    if((GetTime()-startnextmap)>700)
    {
      SetVid(kassandra,VID_MAXHP,maxhp);StopSFX();
      if(old_n_map!=27)
        if(nextmapeffect==eff_none) PlaySFX(19);else PlaySFX(26);
      Load(nextmap);return(1);
    }
  if(losemenu || gamemenu) return(1);
  iff(1)
  {
    timer_ammo1=GetTime();
//    PrintText(0,0,"Beta version 2.1        Copyright (c) Gromada, 1998,1999",V_FONT);
    for(count=FirstUnit(1,u_monster); count; count=NextUnit())
    {
      if(!Random(2) && GetUnitVid(count)!=V_M_MINE)
        Action(count,act_additem,V_MEDIC,0);
      if(!Random(2) && (GetUnitVid(count)==V_M_RL || GetUnitVid(count)==V_M_MISSILETURREL) )
        Action(count,act_additem,V_AMMO2+1,0);
      if(!Random(2) && GetUnitVid(count)==V_M_GUNTANK)
        Action(count,act_additem,V_AMMO2,0);
      if(!Random(2) && GetUnitVid(count)==V_M_MINER)
        Action(count,act_additem,V_AMMO2+2,0);
    }
//    Action(Flagman(0),act_damage,maxhp-hp,0);
    Action(Flagman(0),act_changeweapon,weapon[0],0);
    for(count=0;count<8;count++)
      Action(Flagman(0),act_addammo,noammo[count],count);
  }
  if(Flagman(0))
  {
    if(GetKey()>='1' && GetKey()<='4')
      if(weapon[GetKey()-'1'])
        if(Action(Flagman(0),act_changeweapon,weapon[GetKey()-'1'],0)) nweapon=GetKey()-'1';
    if(nweapon)
      if(weapon[nweapon]<V_FLAGMANHEAD11+5)
        if(!Action(Flagman(0),act_getammo,weapon[nweapon]-V_FLAGMANHEAD11,0))
          if(Action(Flagman(0),act_changeweapon,weapon[0],0)) nweapon=0;else;else;
      else if(weapon[nweapon]<V_FLAGMANHEAD12+5)
        if(!Action(Flagman(0),act_getammo,weapon[nweapon]-V_FLAGMANHEAD12,0))
          if(Action(Flagman(0),act_changeweapon,weapon[0],0)) nweapon=0;else;else;
      else
        if(!Action(Flagman(0),act_getammo,weapon[nweapon]-V_FLAGMANHEAD13,0))
          if(Action(Flagman(0),act_changeweapon,weapon[0],0)) nweapon=0;
    if(Action(Flagman(0),act_deleteitem,102,0))//invisible
    {
      for(count=FirstUnit(1,u_avia+u_monster);count;count=NextUnit())
        Action(count,act_deletetarget,Flagman(0),0);
      Action(Flagman(0),act_setstate,Action(Flagman(0),act_getstate,0,0)|st_invisible,0);
      invisible=GetTime();
    }
    if(invisible) if((GetTime()-invisible)>30000)
    {
      Action(Flagman(0),act_setstate,Action(Flagman(0),act_getstate,0,0)&~st_invisible,0);
      invisible=0;
    }
    if(Action(Flagman(0),act_deleteitem,101,0))//invulnerable
      { invulnerable=GetTime();SetVid(kassandra,VID_MAXHP,0); }
    if(invulnerable) if((GetTime()-invulnerable)>15000)
      { invulnerable=0;SetVid(kassandra,VID_MAXHP,maxhp); }
    if(Action(Flagman(0),act_deleteitem,103,0))//extra life
      if((count=Action(Flagman(0),act_gethp,0,0))<=maxhp)
        Action(Flagman(0),act_damage,-maxhp,0);
      else if(count<maxhp*2) Action(Flagman(0),act_damage,count-maxhp*2,0);
    if(Action(Flagman(0),act_deleteitem,V_AMMO2,0))
      if((count=Action(Flagman(0),act_getammo,1,0))<=160)
        Action(Flagman(0),act_addammo,40,1);
      else if(count<200) Action(Flagman(0),act_addammo,200-count,1);
    if(Action(Flagman(0),act_deleteitem,V_AMMO2+1,0))
      if((count=Action(Flagman(0),act_getammo,2,0))<=65)
        Action(Flagman(0),act_addammo,15,2);
      else if(count<80) Action(Flagman(0),act_addammo,80-count,2);
    if(Action(Flagman(0),act_deleteitem,V_AMMO2+2,0))
      if((count=Action(Flagman(0),act_getammo,3,0))<=35)
        Action(Flagman(0),act_addammo,5,3);
      else if(count<40) Action(Flagman(0),act_addammo,40-count,3);
    if(Action(Flagman(0),act_deleteitem,V_AMMO2+3,0))
      if((count=Action(Flagman(0),act_getammo,4,0))<=450)
        Action(Flagman(0),act_addammo,50,4);
      else if(count<450) Action(Flagman(0),act_addammo,500-count,4);
    if((GetTime()-timer_ammo1)>1000)
    {
      timer_ammo1=GetTime();
      if(Action(Flagman(0),act_getammo,0,0)<30)
        Action(Flagman(0),act_addammo,2,0);
    }
  } else Lose();
  if(GetKey()==9 && !gamemenu) { opt_player=opt_player^OPT_STATEBAR;StateBar(opt_player&OPT_STATEBAR); }
  return(0);
}
#define gamma1 2167
#define gamma2 1943
#define gamma3 1927
#define gamma4 1911
//1931
NetTact()
{
  iff(1)
  {
    SetVid(358,VID_NARMY,3);//смена у мины w43 армии на врага всех
    SetVid(12,VID_WEAPONRANGE,280*3/2);//w21
//    SetVid(13,VID_WEAPONRANGE,350*3/2);SetVid(15,VID_WEAPONRANGE,350*3/2);//w33
    SetVid(14,VID_WEAPONRANGE,350*3/2);//w31
    SetVid(16,VID_WEAPONRANGE,280*3/2);//w41
    SetVid(18,VID_WEAPONRANGE,280*3/2);//w11
//    SetVid(23,VID_WEAPONRANGE,400*3/2);//w22
    SetVid(25,VID_WEAPONRANGE,280*3/2);//w23
//    SetVid(26,VID_WEAPONRANGE,280*3/2);//w13
//    SetVid(27,VID_WEAPONRANGE,350*3/2);//w32
    SetVid(28,VID_WEAPONRANGE,280*3/2);//w12
    SetVid(V_TRANSMISSION1,VID_GAMMA,gamma1);SetVid(V_TRANSMISSION1,VID_GAMMA+1,gamma2);SetVid(V_TRANSMISSION1,VID_GAMMA+2,gamma3);SetVid(V_TRANSMISSION1,VID_GAMMA+3,gamma4);
    SetVid(V_TRANSMISSION2,VID_GAMMA,gamma1);SetVid(V_TRANSMISSION2,VID_GAMMA+1,gamma2);SetVid(V_TRANSMISSION2,VID_GAMMA+2,gamma3);SetVid(V_TRANSMISSION2,VID_GAMMA+3,gamma4);
    SetVid(V_TRANSMISSION3,VID_GAMMA,gamma1);SetVid(V_TRANSMISSION3,VID_GAMMA+1,gamma2);SetVid(V_TRANSMISSION3,VID_GAMMA+2,gamma3);SetVid(V_TRANSMISSION3,VID_GAMMA+3,gamma4);
    SetVid(71,VID_GAMMA,gamma1);SetVid(71,VID_GAMMA+1,gamma2);SetVid(71,VID_GAMMA+2,gamma3);SetVid(71,VID_GAMMA+3,gamma4);
    SetVid(139,VID_GAMMA,gamma1);SetVid(139,VID_GAMMA+1,gamma2);SetVid(139,VID_GAMMA+2,gamma3);SetVid(139,VID_GAMMA+3,gamma4);
    SetVid(148,VID_GAMMA,gamma1);SetVid(148,VID_GAMMA+1,gamma2);SetVid(148,VID_GAMMA+2,gamma3);SetVid(148,VID_GAMMA+3,gamma4);
    SetVid(149,VID_GAMMA,gamma1);SetVid(149,VID_GAMMA+1,gamma2);SetVid(149,VID_GAMMA+2,gamma3);SetVid(149,VID_GAMMA+3,gamma4);
    SetVid(106,VID_GAMMA,gamma1);SetVid(106,VID_GAMMA+1,gamma2);SetVid(106,VID_GAMMA+2,gamma3);SetVid(106,VID_GAMMA+3,gamma4);
    SetVid(220,VID_GAMMA,gamma1);SetVid(220,VID_GAMMA+1,gamma2);SetVid(220,VID_GAMMA+2,gamma3);SetVid(220,VID_GAMMA+3,gamma4);
    SetVid(150,VID_GAMMA,gamma1);SetVid(150,VID_GAMMA+1,gamma2);SetVid(150,VID_GAMMA+2,gamma3);SetVid(150,VID_GAMMA+3,gamma4);
    SetVid(314,VID_GAMMA,gamma1);SetVid(314,VID_GAMMA+1,gamma2);SetVid(314,VID_GAMMA+2,gamma3);SetVid(314,VID_GAMMA+3,gamma4);
    for(count=0;count<4;count++)
    {
      weapontable[count*3]=V_FLAGMANHEAD11+count;
      weapontable[count*3+1]=V_FLAGMANHEAD12+count;
      weapontable[count*3+2]=V_FLAGMANHEAD13+count;
    }
    for(count=0;count<4;count++)
    {
      SetVid(V_FLAGMANHEAD11+count,VID_GAMMA,gamma1);SetVid(V_FLAGMANHEAD11+count,VID_GAMMA+1,gamma2);SetVid(V_FLAGMANHEAD11+count,VID_GAMMA+2,gamma3);SetVid(V_FLAGMANHEAD11+count,VID_GAMMA+3,gamma4);
      SetVid(V_FLAGMANHEAD12+count,VID_GAMMA,gamma1);SetVid(V_FLAGMANHEAD12+count,VID_GAMMA+1,gamma2);SetVid(V_FLAGMANHEAD12+count,VID_GAMMA+2,gamma3);SetVid(V_FLAGMANHEAD12+count,VID_GAMMA+3,gamma4);
      SetVid(V_FLAGMANHEAD13+count,VID_GAMMA,gamma1);SetVid(V_FLAGMANHEAD13+count,VID_GAMMA+1,gamma2);SetVid(V_FLAGMANHEAD13+count,VID_GAMMA+2,gamma3);SetVid(V_FLAGMANHEAD13+count,VID_GAMMA+3,gamma4);
    }
    if(kassandra==V_TRANSMISSION1) maxhp=40;
    else if(kassandra==V_TRANSMISSION2) maxhp=50;
    else maxhp=33;
    SetVid(kassandra,VID_MAXHP,maxhp);
    net_gamemenu[0]=net_gamemenu[1]=net_gamemenu[2]=net_gamemenu[3]=0;
    gamemenu=0;losemenu=0;nukestart=0;win=0;
    timer_ammo1=GetTime();
//    PrintText(0,0,"Beta version 2.1        Copyright (c) Gromada, 1998",V_FONT);
    for(count=FirstUnit(1,u_monster); count; count=NextUnit())
    {
      if(!Random(2) && GetUnitVid(count)!=V_M_MINE)
        Action(count,act_additem,V_MEDIC,0);
      if(!Random(2) && (GetUnitVid(count)==V_M_RL || GetUnitVid(count)==V_M_MISSILETURREL) )
        Action(count,act_additem,V_AMMO2+1,0);
      if(!Random(2) && GetUnitVid(count)==V_M_GUNTANK)
        Action(count,act_additem,V_AMMO2,0);
      if(!Random(2) && GetUnitVid(count)==V_M_MINER)
        Action(count,act_additem,V_AMMO2+2,0);
    }
  }
  if(gamestate)
  {
    if(gamestate==3)
      if((GetTime()-startnextmap)>700)
        { DeleteText(gamemenu);OptionsOn(); }
      else;
    else if(gamestate==5)
      if((GetTime()-startnextmap)>700)
        { DeleteText(gamemenu);DesignMenuOn(); }
      else;
    else if(gamestate==1 || gamestate==2) OptionsTact();
    else if(gamestate==4 || gamestate==6) DesignMenuTact();
    if(!gamestate && gamemenu) GameMenuOn();
  } else if(gamemenu)
  {
    MoveInMenu(30,31);
    if(GetKey()==13 || MenuVid()==V_4BUTTON || GetKey()==' ')
    {
      if(nmenu==30) NextMap("maps\\net.map",eff_none);//logoff
      else if(nmenu==31) { net_gamemenu[GetNetInfo(NET_NUMPLAYER)]=0;GameMenuOff();/*return(0);*/ }
//      else if(nmenu==32) { gamestate=3;startnextmap=GetTime(); }//options
//      if(nmenu==33) NextNMap(n_map);//restart
    } else if(MenuSelectVid()==V_4BUTTON)
    {
      Action(menu,act_destroy,0,0);
      nmenu=MenuDir()+30;menu=MenuCreate(V_TEXTMENU,nmenu,centr_x,centr_y);
    }
  }
  for(n_flagman=0;n_flagman<GetNetInfo(NET_NOPLAYER);n_flagman++)
    if(nextmap=="" && GetNetKey(n_flagman)==27)
    {
      SetNet(0);
      NextMap("maps\\net.map",eff_fade);//logoff
//      net_gamemenu[n_flagman]=net_gamemenu[n_flagman]^1;
    }
/*  if(GetKey()==27)
    if(gamemenu)
      if(GetNetInfo(NET_NOPLAYER)<2) NextMap("exit",eff_fade);//logoff
      else { GameMenuOff(); }
    else { GameMenuOn();PlaySFX(26); }*/
  if(nextmap=="" && GetNetInfo(NET_NOPLAYER)<2)// { GameMenuOn();PlaySFX(26); }
  {
    SetNet(0);
    NextMap("maps\\net.map",eff_fade);//logoff
  }
  if(nextmap!="")
    if((GetTime()-startnextmap)>700)
    {
      SetVid(kassandra,VID_MAXHP,maxhp);
      if(nextmap=="exit") Exit();else Load(nextmap);
      if(nextmapeffect==eff_none) PlaySFX(19);
//      return(1);
    }
  if((GetTime()-timer_ammo1)>1000)
  {
    timer_ammo1=GetTime();
    for(n_flagman=0;n_flagman<GetNetInfo(NET_NOPLAYER);n_flagman++)
      if(Action(Flagman(n_flagman),act_getammo,0,0)<30)
        Action(Flagman(n_flagman),act_addammo,2,0);
  }
  for(n_flagman=0;n_flagman<GetNetInfo(NET_NOPLAYER);n_flagman++)
    if(!Flagman(n_flagman) && !net_birth[n_flagman])
    {
      net_birth[n_flagman]=GetTime();++net_kill[n_flagman];
    } else if(Flagman(n_flagman) && net_birth[n_flagman]) net_birth[n_flagman]=0;
  for(n_flagman=0;n_flagman<GetNetInfo(NET_NOPLAYER);n_flagman++)
    if( Flagman(n_flagman) && !net_gamemenu[n_flagman])
    {
      if(GetNetKey(n_flagman)>='1' && GetNetKey(n_flagman)<='4')
        if(weapon[GetNetKey(n_flagman)-'1'+n_flagman*4])
          if(Action(Flagman(n_flagman),act_changeweapon,weapon[GetNetKey(n_flagman)-'1'+n_flagman*4],0)) nweapon[n_flagman]=GetNetKey(n_flagman)-'1';
      if(nweapon[n_flagman])
        if(weapon[nweapon[n_flagman]+n_flagman*4]<V_FLAGMANHEAD11+5)
          if(!Action(Flagman(n_flagman),act_getammo,weapon[nweapon[n_flagman]+n_flagman*4]-V_FLAGMANHEAD11,0))
            if(Action(Flagman(n_flagman),act_changeweapon,weapon[0+n_flagman*4],0)) nweapon[n_flagman]=0;else;else;
        else if(weapon[nweapon[n_flagman]+n_flagman*4]<V_FLAGMANHEAD12+5)
          if(!Action(Flagman(n_flagman),act_getammo,weapon[nweapon[n_flagman]+n_flagman*4]-V_FLAGMANHEAD12,0))
            if(Action(Flagman(n_flagman),act_changeweapon,weapon[0+n_flagman*4],0)) nweapon[n_flagman]=0;else;else;
        else
          if(!Action(Flagman(n_flagman),act_getammo,weapon[nweapon[n_flagman]+n_flagman*4]-V_FLAGMANHEAD13,0))
            if(Action(Flagman(n_flagman),act_changeweapon,weapon[0+n_flagman*4],0)) nweapon[n_flagman]=0;
      if(Action(Flagman(n_flagman),act_deleteitem,102,0))//invisible
      {
        Action(Flagman(n_flagman),act_setstate,Action(Flagman(n_flagman),act_getstate,0,0)|st_invisible,0);
        invisible[n_flagman]=GetTime();
      }
      if(invisible[n_flagman]) if((GetTime()-invisible[n_flagman])>120000)
      {
        Action(Flagman(n_flagman),act_setstate,Action(Flagman(n_flagman),act_getstate,0,0)&~st_invisible,0);
        invisible[n_flagman]=0;
      }
      if(Action(Flagman(n_flagman),act_deleteitem,101,0))//invulnerable
        { invulnerable=GetTime();SetVid(kassandra,VID_MAXHP,0); }
      if(invulnerable) if((GetTime()-invulnerable)>15000)
        { invulnerable=0;SetVid(kassandra,VID_MAXHP,maxhp); }
      if(Action(Flagman(n_flagman),act_deleteitem,103,0))//extra life
        if((count=Action(Flagman(n_flagman),act_gethp,0,0))<=maxhp)
          Action(Flagman(n_flagman),act_damage,-maxhp,0);
        else if(count<maxhp*2) Action(Flagman(n_flagman),act_damage,count-maxhp*2,0);
      if(Action(Flagman(n_flagman),act_deleteitem,V_AMMO2,0))
        if((count=Action(Flagman(n_flagman),act_getammo,1,0))<=160)
          Action(Flagman(n_flagman),act_addammo,40,1);
        else if(count<200) Action(Flagman(n_flagman),act_addammo,200-count,1);
      if(Action(Flagman(n_flagman),act_deleteitem,V_AMMO2+1,0))
        if((count=Action(Flagman(n_flagman),act_getammo,2,0))<=65)
          Action(Flagman(n_flagman),act_addammo,15,2);
        else if(count<80) Action(Flagman(n_flagman),act_addammo,80-count,2);
      if(Action(Flagman(n_flagman),act_deleteitem,V_AMMO2+2,0))
        if((count=Action(Flagman(n_flagman),act_getammo,3,0))<=35)
          Action(Flagman(n_flagman),act_addammo,5,3);
        else if(count<40) Action(Flagman(n_flagman),act_addammo,40-count,3);
      if(Action(Flagman(n_flagman),act_deleteitem,V_AMMO2+3,0))
        if((count=Action(Flagman(n_flagman),act_getammo,4,0))<=450)
          Action(Flagman(n_flagman),act_addammo,50,4);
        else if(count<500) Action(Flagman(n_flagman),act_addammo,500-count,4);
      for(count=1;count<12;count++)
        if(Action(Flagman(n_flagman),act_deleteitem,V_UPGRADE12+count,0))
            weapon[(count+1)/3+n_flagman*4]=weapontable[count+1];
    }
  if(GetKey()==9 && !gamemenu) { opt_player=opt_player^OPT_STATEBAR;StateBar(opt_player&OPT_STATEBAR); }
  return(0);
}
