Skip to content

Commit d2dc9ce

Browse files
committed
fix CLNE(SPRK) by moving the rest of the important create_part things into Simulation::part_create
1 parent a186e4e commit d2dc9ce

3 files changed

Lines changed: 76 additions & 76 deletions

File tree

build/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ INST. Possible element search crash fix. Fix STKM(AIR) blowing ability.
647647
------------------------------------------------------------------------------
648648
-------------------------------------Bugs-------------------------------------
649649
------------------------------------------------------------------------------
650-
figure out why STKM die if comm/pcomm aren't reset
650+
figure out why STKM die if comm/pcomm aren't reset, also it seems like stickmen can be created with high life randomly
651651
when using console, particles may not be killed properly (ChangeType function not called)
652652
//None (at least that I know of)
653653

src/powder.cpp

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -876,80 +876,15 @@ void part_change_type(int i, int x, int y, int t)//changes the type of particle
876876
globalSim->part_change_type(i, x, y, t);
877877
}
878878

879-
int create_part(int p, int x, int y, int tv)//the function for creating a particle, use p=-1 for creating a new particle, -2 is from a brush, or a particle number to replace a particle.
879+
//the function for creating a particle, use p=-1 for creating a new particle, -2 is from a brush, or a particle number to replace a particle.
880+
//TODO: replace with Simulation::part_create now
881+
int create_part(int p, int x, int y, int tv)
880882
{
881883
int i;
882884

883885
int t = tv & 0xFF;
884886
int v = (tv >> 8) & 0xFFFFFFFF;
885-
886-
if (x<0 || y<0 || x>=XRES || y>=YRES || t<=0 || t>=PT_NUM)
887-
return -1;
888-
if (t>=0 && t<PT_NUM && !ptypes[t].enabled)
889-
return -1;
890-
891-
//activate BUTN here
892-
if (p == -2 && (pmap[y][x]&0xFF) == PT_BUTN && parts[pmap[y][x]>>8].life == 10)
893-
{
894-
globalSim->spark_conductive(pmap[y][x]>>8, x, y);
895-
return pmap[y][x]>>8;
896-
}
897-
if (t==PT_SPRK)
898-
{
899-
int type = pmap[y][x]&0xFF;
900-
int index = pmap[y][x]>>8;
901-
if(type == PT_WIRE)
902-
{
903-
parts[index].ctype = PT_DUST;
904-
return index;
905-
}
906-
if (p==-2 && ((globalSim->elements[type].Properties & PROP_DRAWONCTYPE) || type==PT_CRAY))
907-
{
908-
parts[index].ctype = PT_SPRK;
909-
return index;
910-
}
911-
if (!(type == PT_INST || (ptypes[type].properties&PROP_CONDUCTS)))
912-
return -1;
913-
if (parts[index].life!=0)
914-
return -1;
915-
if (p == -2 && type == PT_INST)
916-
{
917-
INST_flood_spark(globalSim, x, y);
918-
return index;
919-
}
920887

921-
globalSim->spark_conductive_attempt(index, x, y);
922-
return index;
923-
}
924-
if (p==-2)//creating from brush
925-
{
926-
if (pmap[y][x])
927-
{
928-
int drawOn = pmap[y][x]&0xFF;
929-
//If an element has the PROP_DRAWONCTYPE property, and the element being drawn to it does not have PROP_NOCTYPEDRAW (Also some special cases), set the element's ctype
930-
if (((ptypes[drawOn].properties & PROP_DRAWONCTYPE) ||
931-
(drawOn == PT_STOR && !(ptypes[t].properties & TYPE_SOLID)) ||
932-
(drawOn == PT_PCLN && t != PT_PSCN && t != PT_NSCN) ||
933-
(drawOn == PT_PBCN && t != PT_PSCN && t != PT_NSCN))
934-
&& (!(ptypes[t].properties & PROP_NOCTYPEDRAW)))
935-
{
936-
parts[pmap[y][x]>>8].ctype = t;
937-
if (t == PT_LIFE && v < NGOL && drawOn != PT_STOR)
938-
parts[pmap[y][x]>>8].tmp = v;
939-
}
940-
else if ((drawOn == PT_DTEC || (drawOn == PT_PSTN && t != PT_FRME)) && drawOn != t)
941-
{
942-
parts[pmap[y][x]>>8].ctype = t;
943-
if (drawOn == PT_DTEC && t==PT_LIFE && v<NGOL)
944-
parts[pmap[y][x]>>8].tmp = v;
945-
}
946-
return -1;
947-
}
948-
else if (IsWallBlocking(x, y, t))
949-
return -1;
950-
if (photons[y][x] && (ptypes[t].properties & TYPE_ENERGY))
951-
return -1;
952-
}
953888
i = globalSim->part_create(p, x, y, t, v);
954889
return i;
955890
}

src/simulation/Simulation.cpp

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* This program is free software; you can redistribute it and/or modify
33
* it under the terms of the GNU General Public License as published by
44
* the Free Software Foundation; either version 3 of the License, or
@@ -103,6 +103,74 @@ int Simulation::part_create(int p, int x, int y, int t, int v)
103103
{
104104
return -1;
105105
}
106+
107+
// Spark Checks here
108+
if (p == -2 && (pmap[y][x]&0xFF) == PT_BUTN && parts[pmap[y][x]>>8].life == 10)
109+
{
110+
spark_conductive(pmap[y][x]>>8, x, y);
111+
return pmap[y][x]>>8;
112+
}
113+
if (t==PT_SPRK)
114+
{
115+
int type = pmap[y][x]&0xFF;
116+
int index = pmap[y][x]>>8;
117+
if(type == PT_WIRE)
118+
{
119+
parts[index].ctype = PT_DUST;
120+
return index;
121+
}
122+
if (p==-2 && ((elements[type].Properties & PROP_DRAWONCTYPE) || type==PT_CRAY))
123+
{
124+
parts[index].ctype = PT_SPRK;
125+
return index;
126+
}
127+
if (!(type == PT_INST || (elements[type].Properties&PROP_CONDUCTS)))
128+
return -1;
129+
if (parts[index].life!=0)
130+
return -1;
131+
if (p == -2 && type == PT_INST)
132+
{
133+
INST_flood_spark(this, x, y);
134+
return index;
135+
}
136+
137+
spark_conductive_attempt(index, x, y);
138+
return index;
139+
}
140+
// End Spark checks
141+
142+
//Brush Creation
143+
if (p == -2)
144+
{
145+
if (pmap[y][x])
146+
{
147+
int drawOn = pmap[y][x]&0xFF;
148+
//If an element has the PROP_DRAWONCTYPE property, and the element being drawn to it does not have PROP_NOCTYPEDRAW (Also some special cases), set the element's ctype
149+
if (((ptypes[drawOn].properties & PROP_DRAWONCTYPE) ||
150+
(drawOn == PT_STOR && !(ptypes[t].properties & TYPE_SOLID)) ||
151+
(drawOn == PT_PCLN && t != PT_PSCN && t != PT_NSCN) ||
152+
(drawOn == PT_PBCN && t != PT_PSCN && t != PT_NSCN))
153+
&& (!(ptypes[t].properties & PROP_NOCTYPEDRAW)))
154+
{
155+
parts[pmap[y][x]>>8].ctype = t;
156+
if (t == PT_LIFE && v < NGOL && drawOn != PT_STOR)
157+
parts[pmap[y][x]>>8].tmp = v;
158+
}
159+
else if ((drawOn == PT_DTEC || (drawOn == PT_PSTN && t != PT_FRME)) && drawOn != t)
160+
{
161+
parts[pmap[y][x]>>8].ctype = t;
162+
if (drawOn == PT_DTEC && t==PT_LIFE && v<NGOL)
163+
parts[pmap[y][x]>>8].tmp = v;
164+
}
165+
return -1;
166+
}
167+
else if (IsWallBlocking(x, y, t))
168+
return -1;
169+
if (photons[y][x] && (ptypes[t].properties & TYPE_ENERGY))
170+
return -1;
171+
}
172+
// End Brush Creation
173+
106174
// If the element has a Func_Create_Override, use that instead of the rest of this function
107175
if (elements[t].Func_Create_Override)
108176
{
@@ -120,7 +188,7 @@ int Simulation::part_create(int p, int x, int y, int t, int v)
120188
return -1;
121189
}
122190

123-
if (p==-1)
191+
if (p == -1)
124192
{
125193
// Check whether the particle can be created here
126194

@@ -134,11 +202,11 @@ int Simulation::part_create(int p, int x, int y, int t, int v)
134202
}
135203
i = part_alloc();
136204
}
137-
else if (p==-3) // skip pmap checks, e.g. for sing explosion
205+
else if (p == -3) // skip pmap checks, e.g. for sing explosion
138206
{
139207
i = part_alloc();
140208
}
141-
else if (p>=0) // Replace existing particle
209+
else if (p >= 0) // Replace existing particle
142210
{
143211
int oldX = (int)(parts[p].x+0.5f);
144212
int oldY = (int)(parts[p].y+0.5f);
@@ -161,9 +229,6 @@ int Simulation::part_create(int p, int x, int y, int t, int v)
161229
if (i<0)
162230
return -1;
163231

164-
// set the pmap/photon maps to the newly created particle
165-
pmap_add(i, x, y, t);// TODO: ? only set pmap if (t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH)
166-
167232
// Set some properties
168233
parts[i] = elements[t].DefaultProperties;
169234
parts[i].type = t;

0 commit comments

Comments
 (0)