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 LBm : Cellule
00025 {
00026 int active_by_il = 0;
00027 int last_ag_detect;
00028
00029 public LBm(int x, int y, int spe) : base(x,y)
00030 {
00031 Life = 99999999;
00032 specificite = spe;
00033 last_ag_detect = 0;
00034 cell_plusproche = null;
00035 }
00036
00037 public LBm(int x, int y, int spe, int life) : base(x,y)
00038 {
00039 Life = life;
00040 specificite = spe;
00041 last_ag_detect = 0;
00042 cell_plusproche = null;
00043 }
00044
00045 public void Activation(Cellule cell)
00046 {
00047 if(active_by_il == 0)
00048 active_by_il = 200;
00049 }
00050
00051 new public void Action()
00052 {
00053 if(active_by_il != 0)
00054 active_by_il--;
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 && tmp == 0)
00062 {
00063 if(cell is Antigen)
00064 {
00065 if(specificite == cell.specificite)
00066 {
00067 if(last_ag_detect != cell.index)
00068 {
00069 int b = rnd.Next(1,3);
00070 for(int a=0;a<b;a++)
00071 {
00072 ProdPlasmo(this);
00073 }
00074 frmMain.log.NewEvent("Ag n°" + cell.index.ToString() + " detecté,prod. de Plasmocyte(s) de spé:" + specificite.ToString());
00075 int c = rnd.Next(1,2);
00076 for(int a=0;a<c;a++)
00077 {
00078 ProdLBMemoire(this);
00079 }
00080 last_ag_detect = cell.index;
00081 tmp++;
00082 }
00083 }
00084 }
00085 else if(cell is VIH && specificite == cell.specificite && last_ag_detect != cell.index)
00086 {
00087 int b = rnd.Next(1,10);
00088 for(int a=0;a<b;a++)
00089 {
00090 ProdPlasmo(this);
00091 }
00092 frmMain.log.NewEvent("VIH n°" + cell.index.ToString() + " detecté,prod. de Plasmocyte(s) de spé:" + specificite.ToString());
00093 int c = rnd.Next(1,10);
00094 for(int a=0;a<c;a++)
00095 {
00096 ProdLBMemoire(this);
00097 }
00098 last_ag_detect = cell.index;
00099 tmp++;
00100 }
00101 }
00102 }
00103 return;
00104 }
00105
00106 private void ProdPlasmo(Cellule icell)
00107 {
00108 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00109 int count = 0;
00110 foreach(Cellule cell in ccol_copy)
00111 {
00112 if(cell is Plasmocyte)
00113 if(cell.specificite == icell.specificite)
00114 {
00115 count++;
00116 }
00117 }
00118 if(count < 20)
00119 {
00120 int x = rnd.Next(-5,5);
00121 int y = rnd.Next(-5,5);
00122 Plasmocyte pc1 = new Plasmocyte(icell.Location.X+x,icell.Location.Y+y,specificite);
00123 frmMain.ccol.Add(pc1);
00124 pc1.Activation(this);
00125 }
00126 }
00127
00128 private void ProdLBMemoire(Cellule icell)
00129 {
00130 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00131 int count = 0;
00132 foreach(Cellule cell in ccol_copy)
00133 {
00134 if(cell is LBm)
00135 if(cell.specificite == icell.specificite)
00136 {
00137 count++;
00138 }
00139 }
00140 if(count < 20)
00141 {
00142 int x = rnd.Next(-5,5);
00143 int y = rnd.Next(-5,5);
00144 LBm lbm1 = new LBm(icell.Location.X+x,icell.Location.Y+y,icell.specificite);
00145 frmMain.ccol.Add(lbm1);
00146 frmMain.log.NewEvent("Production d'un LBm de spé : " + icell.specificite.ToString());
00147 }
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 = 45000;
00176 else
00177 perimetre = 20000;
00178 if(DistTo(this,cell) < perimetre)
00179 {
00180 if(cell is Antigen || cell is VIH)
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 Antigen || cell is VIH)
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 LBm && 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 }