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

VIH.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 VIH : Cellule
00025         {
00026                 int tmp_count = 0;
00027                 bool mutation = false;
00028 
00029                 public VIH(int x, int y) : base(x,y)
00030                 {
00031                         Life = 99999999;
00032                         specificite = 5;
00033                         cell_plusproche = null;
00034                 }
00035 
00036                 public VIH(int x, int y, int life) : base(x,y)
00037                 {
00038                         Life = life;
00039                         specificite = 5;
00040                         cell_plusproche = null;
00041                 }
00042 
00043                 public VIH(int x, int y, bool mute) : base(x,y)
00044                 {
00045                         Life = 99999999;
00046                         if(mute)
00047                 specificite = 6;
00048                         else
00049                                 specificite = 5;
00050                         cell_plusproche = null;
00051                 }
00052 
00053                 new public void Action()
00054                 {
00055                         Mouvement();
00056                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00057                         int tmp = 0;
00058                         foreach(Cellule cell in ccol_copy)
00059                         {
00060                                 double dst = DistTo(cell,this);
00061                                 if(dst < 200)
00062                                 {
00063                                         if(tmp == 0 && (cell is LT4) || (cell is LT4m) || (cell is Phagocyte))
00064                                         {
00065                                                 InfectionVIH(cell);
00066                                                 if(mutation)
00067                                                         frmMain.log.NewEvent("Infection VIH muté sur l'élément n°" + cell.index.ToString());
00068                                                 else
00069                                                         frmMain.log.NewEvent("Infection VIH sur l'élément n°" + cell.index.ToString());
00070                                                 tmp++;
00071                                         }
00072                                 }
00073                         }
00074                         //mutation
00075                         if(this.mutation == false)
00076                         {
00077                                 int ran = rnd.Next(1,2000);
00078                                 if(ran == 1)
00079                                 {
00080                                         this.mutation = true;
00081                                         this.specificite = 6;
00082                                         frmMain.log.NewEvent("Mutation du VIH n°" + this.index.ToString());
00083                                 }
00084                         }
00085                         return;
00086                 }
00087 
00088                 private void InfectionVIH(Cellule cell)
00089                 {
00090                         int x = cell.Location.X;
00091                         int y = cell.Location.Y;
00092                         frmMain.ccol.RemoveAt(cell.index);
00093                         InfectVIH ivih = new InfectVIH(x,y,mutation);
00094                         frmMain.ccol.Add(ivih);
00095                 }
00096 
00097                 private void Mouvement()
00098                 {
00099                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00100                         if(cell_plusproche != null)
00101                         {
00102                                 if((TestIfAlive(cell_plusproche)))
00103                                 {
00104                                         if(cell_plusproche.Location.X < this.Location.X)
00105                                                 this.Location.X = this.Location.X - 5;
00106                                         else
00107                                                 this.Location.X = this.Location.X + 5;
00108                                         if(cell_plusproche.Location.Y < this.Location.Y)
00109                                                 this.Location.Y = this.Location.Y - 5;
00110                                         else
00111                                                 this.Location.Y = this.Location.Y + 5;
00112                                         tmp_count++;
00113                                 }
00114                                 else
00115                                 {
00116                                         cell_plusproche = null;
00117                                         tmp_count = 0;
00118                                 }
00119                         }
00120                         else
00121                         {
00122                                 foreach(Cellule cell in ccol_copy)
00123                                 {
00124                                         if(DistTo(this,cell) < 12000)
00125                                         {
00126                                                 if(cell is LT4 || cell is LT4m || cell is Phagocyte)
00127                                                 {
00128                                                         if(!(TestIfDejaSelect(cell)))
00129                                                         {
00130                                                                 if(cell_plusproche == null)
00131                                                                         cell_plusproche = cell;
00132                                                                 if(DistTo(this,cell_plusproche) > DistTo(this,cell))
00133                                                                         cell_plusproche = cell;
00134                                                         }
00135                                                 }
00136                                         }
00137                                 }
00138                                 int tmp2 = rnd.Next(2);
00139                                 int x,y;
00140                                 if(tmp2 == 0)
00141                                 {
00142                                         x = this.Location.X + rnd.Next(-5,5);
00143                                         y = this.Location.Y + rnd.Next(-5,5);
00144                                 }
00145                                 else
00146                                 {
00147                                         x = this.Location.X - rnd.Next(-5,5);
00148                                         y = this.Location.Y - rnd.Next(-5,5);
00149                                 }
00150                                 this.Location.X = x;
00151                                 this.Location.Y = y;
00152                                 tmp_count = 0;
00153                         }
00154                         if(tmp_count > 20)
00155                                 cell_plusproche = null;
00156                 }
00157 
00158                 private bool TestIfAlive(Cellule cell)
00159                 {
00160                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00161                         bool tmp = false;
00162                         foreach(Cellule icell in ccol_copy)
00163                         {
00164                                 if(icell.index == cell.index  && tmp == false)
00165                                 {
00166                                         if(icell is LT4 || cell is LT4m || cell is Phagocyte)
00167                                         {
00168                                                 double dst = DistTo(cell,icell);
00169                                                 if(dst < 200)
00170                                                         tmp = true;
00171                                         }
00172                                 }
00173                         }
00174                         return tmp;
00175                 }
00176 
00177                 private bool TestIfDejaSelect(Cellule cell)
00178                 {
00179                         ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00180                         bool tmp = false;
00181                         foreach(Cellule icell in ccol_copy)
00182                         {
00183                                 if(icell is VIH && tmp == false)
00184                                 {
00185                                         if(icell.cell_plusproche == cell)
00186                                                 tmp = true;
00187                                         else
00188                                                 tmp = false;
00189                                 }
00190                         }
00191                         return tmp;
00192                 }
00193         }
00194 }

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