Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members

LT4.cs

Go to the documentation of this file.
00001 /*
00002 SimImmuno version 1.0
00003 Copyright (C) 2005 sebeuh.ajsinfo.net
00004 
00005 SimImmuno est libre, vous pouvez le redistribuer et/ou le modifier
00006 selon les termes de la Licence Publique Générale GNU publiée par la
00007 Free Software Foundation (version 2).
00008 
00009 SimImmuno est distribué car potentiellement utile, mais SANS AUCUNE GARANTIE,
00010 ni explicite ni implicite, y compris les garanties de commercialisation
00011 ou d'adaptation dans un but spécifique. Reportez-vous à la
00012 Licence Publique Générale GNU pour plus de détails.
00013 
00014 Texte de la license officielle (anglais) :
00015 http://simimmuno.ajsinfo.net/text.aspx?code=no&txt_file=GPL.txt
00016 Traduction francaise (non-officielle) :
00017 http://simimmuno.ajsinfo.net/text.aspx?code=no&txt_file=GPL-fr.txt
00018 */
00019 using System;
00020 
00021 namespace SimImmuno
00022 {
00023         [Serializable]
00024         public class LT4 : Cellule
00025         {
00026                 int last_infect_detect;
00027                 int active_by_il = 0;
00028 
00029                 public LT4(int x, int y) : base(x,y)
00030                 {
00031                         Life = 5000;
00032                         last_infect_detect = 0;
00033                         cell_plusproche = null;
00034                 }
00035 
00036                 public LT4(int x, int y, int spe) : base(x,y)
00037                 {
00038                         Life = 5000;
00039                         specificite = spe;
00040                         last_infect_detect = 0;
00041                         cell_plusproche = null;
00042                 }
00043 
00044                 public LT4(int x, int y, int spe, int life) : base(x,y)
00045                 {
00046                         Life = life;
00047                         specificite = spe;
00048                         last_infect_detect = 0;
00049                         cell_plusproche = null;
00050                 }
00051 
00052                 new public void Action()
00053                 {
00054                         if(active_by_il != 0)
00055                                 active_by_il--;
00056                         Mouvement();
00057                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00058                         int tmp = 0;
00059                         foreach(Cellule cell in ccol_copy)
00060                         {       
00061                                 double dst = DistTo(cell,this);
00062                                 if(dst < 200 && tmp == 0)
00063                                 {
00064                                         if(cell is CellInfect)
00065                                         {
00066                                                 if(specificite == cell.specificite)
00067                                                 {
00068                                                         if(last_infect_detect != cell.index)
00069                                                         {
00070                                                                 frmMain.log.NewEvent("Cellule infectée n°" + cell.index.ToString() + " detectée, prod. d'IL");
00071                                                                 ProdIL(this.specificite);
00072                                                                 int c = rnd.Next(1,5);
00073                                                                 for(int a=0;a<c;a++)
00074                                                                 {
00075                                                                         ProdLT4Memoire(this);
00076                                                                 }
00077                                                                 last_infect_detect = cell.index;
00078                                                                 tmp++;
00079                                                         }
00080                                                 }
00081                                         }
00082                                 }
00083                         }
00084                         return;
00085                 }
00086 
00087                 private void ProdLT4Memoire(Cellule icell)
00088                 {
00089                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00090                         int count = 0;
00091                         foreach(Cellule cell in ccol_copy)
00092                         {
00093                                 if(cell is LT4m)
00094                                         if(cell.specificite == icell.specificite)
00095                                         {
00096                                                 count++;        
00097                                         }
00098                         }
00099                         if(count < 50)
00100                         {
00101                                 int x = rnd.Next(-5,5);
00102                                 int y = rnd.Next(-5,5);
00103                                 LT4m lt4m1 = new LT4m(icell.Location.X+x,icell.Location.Y+y,icell.specificite);
00104                                 frmMain.ccol.Add(lt4m1);
00105                                 frmMain.log.NewEvent("Production d'un LT4m de spé : " + icell.specificite.ToString());
00106                         }
00107                 }
00108 
00109                 private void ProdIL(int spe)
00110                 {
00111                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00112                         foreach(Cellule cell in ccol_copy)
00113                         {
00114                                 if(cell.specificite == spe)
00115                                 {
00116                                         if(cell is LB)
00117                                         {
00118                                                 ((LB)cell).Activation(cell);
00119                                         }
00120                                         else if(cell is LBm)
00121                                         {
00122                                                 ((LBm)cell).Activation(cell);
00123                                         }
00124                                         else if(cell is LT8m)
00125                                         {
00126                                                 ((LT8m)cell).Activation(cell);
00127                                         }
00128                                         else if(cell is LT8)
00129                                         {
00130                                                 ((LT8)cell).Activation(cell);
00131                                         }
00132                                         else if(cell is LT4)
00133                                         {
00134                                                 ((LT4)cell).Activation(cell);
00135                                         }
00136                                         else if(cell is LT4m)
00137                                         {
00138                                                 ((LT4m)cell).Activation(cell);
00139                                         }
00140                                 }
00141                         }               
00142                 }
00143 
00144                 public void Activation(Cellule cell)
00145                 {
00146                         if(active_by_il == 0)
00147                                 active_by_il = 200;
00148                 }
00149 
00150                 private void Mouvement()
00151                 {
00152                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00153                         if(cell_plusproche != null)
00154                         {
00155                                 if((TestIfAlive(cell_plusproche)))
00156                                 {
00157                                         if(cell_plusproche.Location.X < this.Location.X)
00158                                                 this.Location.X = this.Location.X - 5;
00159                                         else
00160                                                 this.Location.X = this.Location.X + 5;
00161                                         if(cell_plusproche.Location.Y < this.Location.Y)
00162                                                 this.Location.Y = this.Location.Y - 5;
00163                                         else
00164                                                 this.Location.Y = this.Location.Y + 5;
00165                                 }
00166                                 else
00167                                         cell_plusproche = null;
00168                         }
00169                         else
00170                         {
00171                                 foreach(Cellule cell in ccol_copy)
00172                                 {
00173                                         int perimetre;
00174                                         if(active_by_il != 0)
00175                                                 perimetre = 65000;
00176                                         else
00177                                                 perimetre = 30000;
00178                                         if(DistTo(this,cell) < perimetre)
00179                                         {
00180                                                 if(cell is CellInfect || cell is InfectVIH)
00181                                                 {
00182                                                         if(cell.specificite == this.specificite)
00183                                                         {
00184                                                                 if(!(TestIfDejaSelect(cell)))
00185                                                                 {
00186                                                                         if(cell_plusproche == null)
00187                                                                                 cell_plusproche = cell;
00188                                                                         if(DistTo(this,cell_plusproche) > DistTo(this,cell))
00189                                                                                 cell_plusproche = cell;
00190                                                                 }
00191                                                         }
00192                                                 }
00193                                         }
00194                                 }
00195                                 int tmp2 = rnd.Next(2);
00196                                 int x,y;
00197                                 if(tmp2 == 0)
00198                                 {
00199                                         x = this.Location.X + rnd.Next(-5,5);
00200                                         y = this.Location.Y + rnd.Next(-5,5);
00201                                 }
00202                                 else
00203                                 {
00204                                         x = this.Location.X - rnd.Next(-5,5);
00205                                         y = this.Location.Y - rnd.Next(-5,5);
00206                                 }
00207                                 this.Location.X = x;
00208                                 this.Location.Y = y;
00209                         }
00210                 }
00211 
00212                 private bool TestIfAlive(Cellule cell)
00213                 {
00214                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00215                         bool tmp = false;
00216                         foreach(Cellule icell in ccol_copy)
00217                         {
00218                                 if(icell.index == cell.index && icell.specificite == cell.specificite  && tmp == false)
00219                                 {
00220                                         if(icell is CellInfect || icell is InfectVIH)
00221                                         {
00222                                                 double dst = DistTo(cell,icell);
00223                                                 if(dst < 200)
00224                                                         tmp = true;
00225                                         }
00226                                 }
00227                         }
00228                         return tmp;
00229                 }
00230 
00231                 private bool TestIfDejaSelect(Cellule cell)
00232                 {
00233                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00234                         bool tmp = false;
00235                         foreach(Cellule icell in ccol_copy)
00236                         {
00237                                 if(icell is LT4 && tmp == false)
00238                                 {
00239                                         if(icell.cell_plusproche == cell)
00240                                                 tmp = true;
00241                                         else
00242                                                 tmp = false;
00243                                 }
00244                         }
00245                         return tmp;
00246                 }
00247         }
00248 }

Generated on Sat Jun 4 15:03:42 2005 for SimImmuno by  doxygen 1.4.2