home *** CD-ROM | disk | FTP | other *** search
/ WarCraft 2000 - Nuclear Epidemic / W2000.nrg / SOURCE.War2000 / Upgrade.cpp < prev    next >
C/C++ Source or Header  |  1998-09-28  |  5KB  |  208 lines

  1. #include "ddini.h"
  2. #include "ResFile.h"
  3. #include "FastDraw.h"
  4. #include "mgraph.h"
  5. #include "mouse.h"
  6. #include "menu.h"
  7. #include "MapDiscr.h"
  8. #include "multipl.h"
  9. #include "fog.h"
  10. #include "walls.h"
  11. #include "Nature.h"
  12.  
  13. Upgrade::Upgrade(){
  14.     NUpgrades=0;
  15. };
  16. void PerformUpgradeLink(OneObject* OBJ);
  17. void OneObject::PerformUpgrade(word NewU){
  18.     if(Nat->UPG.NUpgrades<=NewU||!Ready)return;
  19.     word NUP=Ref.General->NUpgrades;
  20.     word* UPL=Ref.General->Upg;
  21.     bool canU=false;
  22.     for(int pp=0;pp<NUP;pp++)if(UPL[pp]==NewU)canU=true;
  23.     if(!canU)return;
  24.     if(!Nat->UPG.utp[NewU]->Enabled)return;
  25.     if(!CheckCost(NNUM,1,Nat->UPG.utp[NewU]->Cost))return;
  26.     Order1* Or1=GetOrdBlock();
  27.     Or1->PrioryLevel=0;
  28.     Or1->NextOrder=LocalOrder;
  29.     Or1->OrderType=75;//Upgrade
  30.     Or1->OrderTime=0;
  31.     Or1->DoLink=&PerformUpgradeLink;
  32.     Or1->info.PUpgrade.NewUpgrade=NewU;
  33.     Or1->info.PUpgrade.Stage=1;
  34.     Or1->info.PUpgrade.NStages=Nat->UPG.utp[NewU]->Time;
  35.     //Nat->UPG.utp[NewU]->Stage=1;
  36.     Order1* LOR=LocalOrder;
  37.     if(int(InLineCom))FreeAsmLink();
  38.     LocalOrder=Or1;
  39.     //OrderReport=NULL;
  40.     //MessageKind=0;
  41.     //Sender=0xFFFF;
  42.     SimpleUTP* SU=Nat->UPG.utp[NewU];
  43.     //if(SU->OneTime)
  44.     if(SU->OneTime){
  45.         SU->Done=true;
  46.         SU->Enabled=false;
  47.     };
  48.     Ustage=0;
  49.     NUstages=SU->Time;
  50.     Ready=false;
  51. };    
  52. void PerformUpgradeLink(OneObject* OBJ){
  53.     word OI=OBJ->LocalOrder->info.PUpgrade.NewUpgrade;
  54.     Nation* NT=OBJ->Nat;
  55.     byte NI=NT->NNUM;
  56.     SimpleUTP* SU=NT->UPG.utp[OI];
  57.     if(!CheckCost(NI,1,SU->Cost))return;
  58.     OBJ->LocalOrder->info.PUpgrade.Stage++;
  59.     OBJ->Ustage=OBJ->LocalOrder->info.PUpgrade.Stage;
  60.     if(OBJ->LocalOrder->info.PUpgrade.Stage>=OBJ->LocalOrder->info.PUpgrade.NStages){
  61.         OBJ->Ready=true;
  62.         for(int i=0;i<SU->NLinks;i++)
  63.             NT->UPG.utp[SU->Links[i]]->Enabled=true;
  64.         if(SU->NLinks)SU->Enabled=false;
  65.         for(i=0;i<SU->NAuto;i++)
  66.             NT->UPG.utp[SU->AutoPerf[i]]->DoUpgrade(NI,OBJ);
  67.         RESRC[NT->NNUM][1]-=SU->Cost;
  68.         SU->DoUpgrade(NT->NNUM,OBJ);
  69.         SU->Finished=true;
  70.         if(int(OBJ->LocalOrder)){
  71.             Order1* Or1=OBJ->LocalOrder->NextOrder;
  72.             OBJ->FreeOrdBlock(OBJ->LocalOrder);
  73.             OBJ->LocalOrder=Or1;
  74.             OBJ->Important=false;
  75.             return;
  76.         };
  77.     };
  78. };
  79. void SimpleUTP::DoUpgrade(byte NI,OneObject *OB){
  80.     switch(Kind){
  81.     case 1:{
  82.             UTP1* ut1=(UTP1*)this;
  83.             RESADD[NI][ut1->ResType]+=ut1->AddVal;
  84.         };
  85.         break;
  86.     case 2:{
  87.             UTP2* ut2=(UTP2*)this;
  88.             //CharID:
  89.             //0-Damage
  90.             //1-Health
  91.             //2-AttackRange
  92.             Visuals* VS=(Visuals*) NATIONS[NI].Mon[ut2->MID];
  93.             switch(ut2->CharID){
  94.                 case 0://Damage
  95.                     VS->info.Basic.MinDamage+=ut2->AddVal;
  96.                     //VS->info.Basic.MaxDamage+=ut2->AddVal;
  97.                     break;
  98.                 case 1://Health
  99.                     VS->info.Basic.MaxLife+=ut2->AddVal;
  100.                     break;
  101.                 case 2://attack range
  102.                     if(VS->info.Basic.AttackRange>1)
  103.                         VS->info.Basic.AttackRange+=ut2->AddVal;
  104.                     break;
  105.                 case 3://Shield
  106.                     VS->info.Basic.MaxShield+=ut2->AddVal;
  107.                     if(VS->info.Basic.MaxShield>99)
  108.                         VS->info.Basic.MaxShield=99;
  109.                     break;
  110.                 case 4://Visibility radius
  111.                     VS->SpotSize+=ut2->AddVal;
  112.                     break;
  113.                 case 5://Refresh life
  114.                     VS->RefreshLife=true;
  115.                     break;
  116.             };
  117.             for(int i=0;i<MAXOBJECT;i++){
  118.                 OneObject* OB=Group[i];
  119.                 if(int(OB)&&OB->Ref.Visual==VS){
  120.                     OB->MaxLife=
  121.                         VS->info.Basic.MaxLife;
  122.                     OB->Life=
  123.                         VS->info.Basic.MaxLife;
  124.                     OB->SpotSize=
  125.                         VS->SpotSize;
  126.                 };
  127.             };
  128.         };
  129.         break;
  130.     case 3:{
  131.         UTP3* ut3=(UTP3*)this;
  132.         Visuals* GO=(Visuals*)NATIONS[NI].Mon[ut3->FinalMID];
  133.         OB->Ref.Visual=GO;
  134.         OneObject* G=OB;
  135.         G->DefaultSettings(GO);
  136.         while(G->LocalOrder){
  137.             Order1* ord1=G->LocalOrder->NextOrder;
  138.             G->FreeOrdBlock(G->LocalOrder);
  139.             G->LocalOrder=ord1;
  140.         };
  141.         G->NIndex=ut3->FinalMID;
  142.         G->Teleport=false;
  143.         G->capTeleport=GO->Teleport;
  144.         G->VisRadius=GO->VisRadius;
  145.         G->VisSpots=GO->VisSpots;
  146.         G->SpotType=GO->SpotType;
  147.         G->SpotSize=GO->SpotSize;
  148.         G->DangerZone=GO->DangerZone;
  149.         G->NoSearchVictim=GO->NoSearchVictim;
  150.         G->NoAnswer=GO->NoAnswer;
  151.         G->NeedNoHelp=GO->NeedNoHelp;
  152.         G->Ready=true;
  153.         G->wepX=GO->wepX;
  154.         G->wepY=GO->wepY;
  155.         G->MaxDelay=GO->delay;
  156.         G->delay=0;
  157.         G->NearBase=0xFFFF;
  158.         G->capBase=GO->cpbBase;
  159.         G->RStage=0;
  160.         G->RType=0;
  161.         G->RAmount=0;
  162.         G->AnmGoKind=1;
  163.         G->capBuild=GO->cpbBuild;
  164.         G->GroupIndex=NULL;
  165.         G->cpbMoving=GO->cpbMoving;
  166.         G->AbRes=0;
  167.         if(GO->AGold)G->AbRes|=2;
  168.         if(GO->AWood)G->AbRes|=4;
  169.         if(!GO->SizeX)GO->SizeX=1;
  170.         if(!GO->SizeY)GO->SizeY=1;
  171.         G->Lx=GO->SizeX;
  172.         G->Ly=GO->SizeY;
  173.         G->TempFlag=false;
  174.         G->Mobilised=false;
  175.         G->Wars=NULL;
  176.         G->Selected=false;
  177.         G->Borg=false;
  178.         G->Life=GO->info.Basic.MaxLife;
  179.         G->MaxLife=GO->info.Basic.MaxLife;
  180.         G->Ref.Visual=GO;
  181.         G->Push=false;
  182.         memset(&(G->ARegs),0,sizeof G->ARegs);
  183.         G->LoadAnimation(0,0,0);
  184.         G->LoadCurAnm(0);
  185.         G->LocalOrder=NULL;
  186.         G->Attack=false;
  187.         //G->OrderReport=NULL;
  188.         //G->MessageFlags=0;
  189.         G->PrioryLevel=0;
  190.         //G->MessageKind=0;
  191.         G->Ticks=0;
  192.         G->TicksPerChange=10;
  193.         G->Wait=0;
  194.         G->Addx=0;
  195.         G->Addy=0;
  196.         G->Npush=0;
  197.         G->StandTime=100;
  198.         G->Sdoxlo=false;
  199.         G->Weap=GO->Weap;}
  200.         break;
  201.     case 4://enable strange weapon
  202.         UTP3* ut3=(UTP3*)this;
  203.         Nation* NT=&NATIONS[NI];
  204.         NT->SWP[ut3->FinalMID].Enabled=true;
  205.         ut3->Enabled=false;
  206.         break;
  207.     };
  208. };