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

LT4m.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 LT4m : Cellule
00025         {
00026                 int last_infect_detect;
00027                 int active_by_il = 0;
00028         
00029                 public LT4m(int x, int y, int spe) : base(x,y)
00030                 {
00031                         Life = 99999999;
00032                         specificite = spe;
00033                         last_infect_detect = 0;
00034                         cell_plusproche = null;
00035                 }
00036 
00037                 public LT4m(int x, int y, int spe, int life) : base(x,y)
00038                 {
00039                         Life = life;
00040                         specificite = spe;
00041                         last_infect_detect = 0;
00042                         cell_plusproche = null;
00043                 }
00044 
00045                 new public void Action()
00046                 {
00047                         if(active_by_il != 0)
00048                                 active_by_il--;
00049                         Mouvement();
00050                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00051                         int tmp = 0;
00052                         foreach(Cellule cell in ccol_copy)
00053                         {       
00054                                 double dst = DistTo(cell,this);
00055                                 if(dst < 200 && tmp == 0)
00056                                 {
00057                                         if(cell is CellInfect)
00058                                         {
00059                                                 if(specificite == cell.specificite)
00060                                                 {
00061                                                         if(last_infect_detect != cell.index)
00062                                                         {
00063                                                                 frmMain.log.NewEvent("Cellule infectée n°" + cell.index.ToString() + " detectée, prod. d'IL");
00064                                                                 ProdIL(this.specificite);
00065                                                                 int c = rnd.Next(1,4);
00066                                                                 for(int a=0;a<c;a++)
00067                                                                 {
00068                                                                         ProdLT4Memoire(this);
00069                                                                 }
00070                                                                 last_infect_detect = cell.index;
00071                                                                 tmp++;
00072                                                         }
00073                                                 }
00074                                         }
00075                                 }
00076                         }
00077                         return;
00078                 }
00079 
00080                 public void Activation(Cellule cell)
00081                 {
00082                         if(active_by_il == 0)
00083                                 active_by_il = 200;
00084                 }
00085 
00086                 private void ProdLT4Memoire(Cellule icell)
00087                 {
00088                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00089                         int count = 0;
00090                         foreach(Cellule cell in ccol_copy)
00091                         {
00092                                 if(cell is LT4m)
00093                                         if(cell.specificite == icell.specificite)
00094                                         {
00095                                                 count++;        
00096                                         }
00097                         }
00098                         if(count < 20)
00099                         {
00100                                 int x = rnd.Next(-15,15);
00101                                 int y = rnd.Next(-15,15);
00102                                 LT4m lt4m1 = new LT4m(icell.Location.X+x,icell.Location.Y+y,icell.specificite);
00103                                 frmMain.ccol.Add(lt4m1);
00104                                 frmMain.log.NewEvent("Production d'un LT4m de spé : " + icell.specificite.ToString());
00105                         }
00106                 }
00107 
00108                 private void ProdIL(int spe)
00109                 {
00110                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00111                         foreach(Cellule cell in ccol_copy)
00112                         {
00113                                 if(cell.specificite == spe)
00114                                 {
00115                                         if(cell is LB)
00116                                         {
00117                                                 ((LB)cell).Activation(cell);
00118                                         }
00119                                         else if(cell is LBm)
00120                                         {
00121                                                 ((LBm)cell).Activation(cell);
00122                                         }
00123                                         else if(cell is LT8m)
00124                                         {
00125                                                 ((LT8m)cell).Activation(cell);
00126                                         }
00127                                         else if(cell is LT8)
00128                                         {
00129                                                 ((LT8)cell).Activation(cell);
00130                                         }
00131                                         else if(cell is LT4)
00132                                         {
00133                                                 ((LT4)cell).Activation(cell);
00134                                         }
00135                                         else if(cell is LT4m)
00136                                         {
00137                                                 ((LT4m)cell).Activation(cell);
00138                                         }
00139                                 }
00140                         }               
00141                 }
00142 
00143                 private void Mouvement()
00144                 {
00145                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00146                         if(cell_plusproche != null)
00147                         {
00148                                 if((TestIfAlive(cell_plusproche)))
00149                                 {
00150                                         if(cell_plusproche.Location.X < this.Location.X)
00151                                                 this.Location.X = this.Location.X - 5;
00152                                         else
00153                                                 this.Location.X = this.Location.X + 5;
00154                                         if(cell_plusproche.Location.Y < this.Location.Y)
00155                                                 this.Location.Y = this.Location.Y - 5;
00156                                         else
00157                                                 this.Location.Y = this.Location.Y + 5;
00158                                 }
00159                                 else
00160                                         cell_plusproche = null;
00161                         }
00162                         else
00163                         {
00164                                 foreach(Cellule cell in ccol_copy)
00165                                 {
00166                                         int perimetre;
00167                                         if(active_by_il != 0)
00168                                                 perimetre = 65000;
00169                                         else
00170                                                 perimetre = 30000;
00171                                         if(DistTo(this,cell) < perimetre)
00172                                         {
00173                                                 if(cell is CellInfect || cell is InfectVIH)
00174                                                 {
00175                                                         if(cell.specificite == this.specificite)
00176                                                         {
00177                                                                 if(!(TestIfDejaSelect(cell)))
00178                                                                 {
00179                                                                         if(cell_plusproche == null)
00180                                                                                 cell_plusproche = cell;
00181                                                                         if(DistTo(this,cell_plusproche) > DistTo(this,cell))
00182                                                                                 cell_plusproche = cell;
00183                                                                 }
00184                                                         }
00185                                                 }
00186                                         }
00187                                 }
00188                                 int tmp2 = rnd.Next(2);
00189                                 int x,y;
00190                                 if(tmp2 == 0)
00191                                 {
00192                                         x = this.Location.X + rnd.Next(-5,5);
00193                                         y = this.Location.Y + rnd.Next(-5,5);
00194                                 }
00195                                 else
00196                                 {
00197                                         x = this.Location.X - rnd.Next(-5,5);
00198                                         y = this.Location.Y - rnd.Next(-5,5);
00199                                 }
00200                                 this.Location.X = x;
00201                                 this.Location.Y = y;
00202                         }
00203                 }
00204 
00205                 private bool TestIfAlive(Cellule cell)
00206                 {
00207                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00208                         bool tmp = false;
00209                         foreach(Cellule icell in ccol_copy)
00210                         {
00211                                 if(icell.index == cell.index && icell.specificite == cell.specificite  && tmp == false)
00212                                 {
00213                                         if(icell is CellInfect || icell is InfectVIH)
00214                                         {
00215                                                 double dst = DistTo(cell,icell);
00216                                                 if(dst < 200)
00217                                                         tmp = true;
00218                                         }
00219                                 }
00220                         }
00221                         return tmp;
00222                 }
00223 
00224                 private bool TestIfDejaSelect(Cellule cell)
00225                 {
00226                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00227                         bool tmp = false;
00228                         foreach(Cellule icell in ccol_copy)
00229                         {
00230                                 if(icell is LT4m && tmp == false)
00231                                 {
00232                                         if(icell.cell_plusproche == cell)
00233                                                 tmp = true;
00234                                         else
00235                                                 tmp = false;
00236                                 }
00237                         }
00238                         return tmp;
00239                 }
00240         }
00241 }

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