00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 using System;
00020
00021 namespace SimImmuno
00022 {
00023 [Serializable]
00024 public class LT8m : Cellule
00025 {
00026 int last_infect_detect;
00027 int active_by_il = 0;
00028
00029 public LT8m(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 LT8m(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 public void Activation(Cellule cell)
00045 {
00046 if(active_by_il == 0)
00047 active_by_il = 200;
00048 }
00049
00050 new public void Action()
00051 {
00052 if(active_by_il != 0)
00053 active_by_il--;
00054 Mouvement();
00055 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00056 int tmp = 0;
00057 foreach(Cellule cell in ccol_copy)
00058 {
00059 double dst = DistTo(cell,this);
00060 if(dst < 200 && tmp == 0)
00061 {
00062 if(cell is CellInfect)
00063 {
00064 if(specificite == cell.specificite)
00065 {
00066 if(last_infect_detect != cell.index)
00067 {
00068 int b = rnd.Next(1,3);
00069 for(int a=0;a<b;a++)
00070 {
00071 ProdLTc(this);
00072 }
00073 frmMain.log.NewEvent("Cellule infectée n°" + cell.index.ToString() + " detectée,création de LTc de spé:" + specificite.ToString());
00074 last_infect_detect = cell.index;
00075 tmp++;
00076 }
00077 }
00078 else if(cell is InfectVIH)
00079 {
00080 if(last_infect_detect != cell.index)
00081 {
00082 int b = rnd.Next(1,3);
00083 for(int a=0;a<b;a++)
00084 {
00085 ProdLTc(this);
00086 }
00087 frmMain.log.NewEvent("Cell. infectée VIH n°" + cell.index.ToString() + " detectée,création de LTc de spé:" + specificite.ToString());
00088 tmp++;
00089 last_infect_detect = cell.index;
00090 }
00091 }
00092 }
00093 }
00094 }
00095 return;
00096 }
00097
00098 private void ProdLTc(Cellule lt8_producteur)
00099 {
00100 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00101 int count = 0;
00102 foreach(Cellule cell in ccol_copy)
00103 {
00104 if(cell is LTc)
00105 if(cell.specificite == lt8_producteur.specificite)
00106 {
00107 count++;
00108 }
00109 }
00110 if(count < 30)
00111 {
00112 int x = rnd.Next(-5,5);
00113 int y = rnd.Next(-5,5);
00114 LTc ltc1 = new LTc(lt8_producteur.Location.X+x,lt8_producteur.Location.Y+y,lt8_producteur.specificite);
00115 frmMain.ccol.Add(ltc1);
00116 int c = rnd.Next(1,5);
00117 for(int a=0;a<c;a++)
00118 {
00119 ProdLT8Memoire(this);
00120 }
00121 }
00122 }
00123
00124 private void ProdLT8Memoire(Cellule icell)
00125 {
00126 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00127 int count = 0;
00128 foreach(Cellule cell in ccol_copy)
00129 {
00130 if(cell is LT8m)
00131 if(cell.specificite == icell.specificite)
00132 {
00133 count++;
00134 }
00135 }
00136 if(count < 20)
00137 {
00138 int x = rnd.Next(-5,5);
00139 int y = rnd.Next(-5,5);
00140 LT8m lt8m1 = new LT8m(icell.Location.X+x,icell.Location.Y+y,icell.specificite);
00141 frmMain.ccol.Add(lt8m1);
00142 frmMain.log.NewEvent("Production d'un LT8m de spé : " + icell.specificite.ToString());
00143 }
00144 }
00145
00146 private void Mouvement()
00147 {
00148 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00149 if(cell_plusproche != null)
00150 {
00151 if((TestIfAlive(cell_plusproche)))
00152 {
00153 if(cell_plusproche.Location.X < this.Location.X)
00154 this.Location.X = this.Location.X - 5;
00155 else
00156 this.Location.X = this.Location.X + 5;
00157 if(cell_plusproche.Location.Y < this.Location.Y)
00158 this.Location.Y = this.Location.Y - 5;
00159 else
00160 this.Location.Y = this.Location.Y + 5;
00161 }
00162 else
00163 cell_plusproche = null;
00164 }
00165 else
00166 {
00167 foreach(Cellule cell in ccol_copy)
00168 {
00169 int perimetre;
00170 if(active_by_il != 0)
00171 perimetre = 45000;
00172 else
00173 perimetre = 20000;
00174 if(DistTo(this,cell) < perimetre)
00175 {
00176 if(cell is CellInfect || cell is InfectVIH)
00177 {
00178 if(cell.specificite == this.specificite)
00179 {
00180 if(!(TestIfDejaSelect(cell)))
00181 {
00182 if(cell_plusproche == null)
00183 cell_plusproche = cell;
00184 if(DistTo(this,cell_plusproche) > DistTo(this,cell))
00185 cell_plusproche = cell;
00186 }
00187 }
00188 }
00189 }
00190 }
00191 int tmp2 = rnd.Next(2);
00192 int x,y;
00193 if(tmp2 == 0)
00194 {
00195 x = this.Location.X + rnd.Next(-5,5);
00196 y = this.Location.Y + rnd.Next(-5,5);
00197 }
00198 else
00199 {
00200 x = this.Location.X - rnd.Next(-5,5);
00201 y = this.Location.Y - rnd.Next(-5,5);
00202 }
00203 this.Location.X = x;
00204 this.Location.Y = y;
00205 }
00206 }
00207
00208 private bool TestIfAlive(Cellule cell)
00209 {
00210 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00211 bool tmp = false;
00212 foreach(Cellule icell in ccol_copy)
00213 {
00214 if(icell.index == cell.index && icell.specificite == cell.specificite && tmp == false)
00215 {
00216 if(icell is CellInfect || cell is InfectVIH)
00217 {
00218 double dst = DistTo(cell,icell);
00219 if(dst < 200)
00220 tmp = true;
00221 }
00222 }
00223 }
00224 return tmp;
00225 }
00226
00227 private bool TestIfDejaSelect(Cellule cell)
00228 {
00229 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00230 bool tmp = false;
00231 foreach(Cellule icell in ccol_copy)
00232 {
00233 if(icell is LT8m && tmp == false)
00234 {
00235 if(icell.cell_plusproche == cell)
00236 tmp = true;
00237 else
00238 tmp = false;
00239 }
00240 }
00241 return tmp;
00242 }
00243 }
00244 }