TempleOSCDV4.12.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:47:56 +02:00
1 parent 93ca216483
commit b84bbff6db
381 files changed
+18356 -18798

No files matched your search

+2 -2
View File
@@ -132,7 +132,7 @@ Bool TakeTurn()
}
res=TRUE;
}
WinMgrSync;
Refresh;
Fs->song_task=NULL;
return res;
}
@@ -151,7 +151,7 @@ U0 TMsg(CDC *dc,U8 *msg)
dc->color=YELLOW;
GrPrint(dc,(GR_WIDTH-StrLen(msg)*FONT_WIDTH)/2,
GR_HEIGHT-5*FONT_HEIGHT/2,"%s",msg);
WinMgrSync;
Refresh;
if (ScanChar)
throw;
}
Binary file not shown.
+8 -8
View File
@@ -2,25 +2,25 @@ U0 ViewComics()
{
I64 i=0;
U8 *st;
CDirEntry *tempde=FilesFind("Comics/*.DD*"),*tempde1=tempde;
CDirEntry *tmpde=FilesFind("Comics/*.DD*"),*tmpde1=tmpde;
CDoc *doc=DocNew;
DocPrint(doc,"$$LTBLUE$$");
while (tempde) {
st=StrNew(tempde->name);
while (tmpde) {
st=StrNew(tmpde->name);
FileExtRem(st);
tempde->user_data=DocPrint(doc,"$$MU-UL,\"%-10ts\",LE=%d$$ ",st,tempde);
tmpde->user_data=DocPrint(doc,"$$MU-UL,\"%-10ts\",LE=%d$$ ",st,tmpde);
Free(st);
tempde=tempde->next;
tmpde=tmpde->next;
if ((i++&3)==3)
DocPrint(doc,"\n");
}
while (TRUE) {
if ((tempde=PopUpMenu(doc))>0)
Ed(tempde->full_name);
if ((tmpde=PopUpMenu(doc))>0)
Ed(tmpde->full_name);
else
break;
}
DocDel(doc);
DirTreeDel(tempde1);
DirTreeDel(tmpde1);
}
+23 -23
View File
@@ -7,47 +7,47 @@ U0 MPDrawHoreb(CDC *dc2)
CDC *dc=DCAlias(dc2,task);
I64 i,j,dx,dy,dz,w=task->pix_width,h=task->pix_height,r[16],cx=w>>1;
F64 s,m,a,x1,y1,x2,y2;
Obj *tempo;
Obj *tmpo;
Mat4x4IdentEqu(r);
Mat4x4RotY(r,-é);
Mat4x4RotX(r,77*ã/180);
for (i=Gs->num;i<O_NUM_OBJS+O_NUM_PEBBLES;i+=mp_cnt) {
tempo=&objs[i];
tempo->x1=tempo->x+vx; tempo->y1=tempo->y; tempo->z1=tempo->z+vz;
Mat4x4MulXYZ(r,&tempo->x1,&tempo->y1,&tempo->z1);
if (tempo->type==OT_SHEEP ||
tempo->type==OT_GOAT1 || tempo->type==OT_GOAT2) {
dx=100*tempo->dx; dy=100*tempo->dy; dz=100*tempo->dz;
tmpo=&objs[i];
tmpo->x1=tmpo->x+vx; tmpo->y1=tmpo->y; tmpo->z1=tmpo->z+vz;
Mat4x4MulXYZ(r,&tmpo->x1,&tmpo->y1,&tmpo->z1);
if (tmpo->type==OT_SHEEP ||
tmpo->type==OT_GOAT1 || tmpo->type==OT_GOAT2) {
dx=100*tmpo->dx; dy=100*tmpo->dy; dz=100*tmpo->dz;
Mat4x4MulXYZ(r,&dx,&dy,&dz);
if (dx<0)
tempo->sym=TRUE;
tmpo->sym=TRUE;
else
tempo->sym=FALSE;
tmpo->sym=FALSE;
}
if (tempo->z1>=0) {
s=100.0/(AbsI64(tempo->z1)+50);
if (tempo->type) {
if (tmpo->z1>=0) {
s=100.0/(AbsI64(tmpo->z1)+50);
if (tmpo->type) {
Mat4x4IdentEqu(dc->r);
Mat4x4Scale(dc->r,s*2);
DCMat4x4Set(dc,dc->r);
dc->flags|=DCF_TRANSFORMATION;
if (tempo->sym) {
if (tmpo->sym) {
dc->flags|=DCF_SYMMETRY|DCF_JUST_MIRROR;
DCSymmetrySet(dc,s*tempo->x1+cx,s*tempo->y1+h,
s*tempo->x1+cx,s*tempo->y1+h+10);
DCSymmetrySet(dc,s*tmpo->x1+cx,s*tmpo->y1+h,
s*tmpo->x1+cx,s*tmpo->y1+h+10);
}
Sprite3B(dc,s*tempo->x1+cx,s*tempo->y1+h,tempo->z1,imgs[tempo->type]);
Sprite3B(dc,s*tmpo->x1+cx,s*tmpo->y1+h,tmpo->z1,imgs[tmpo->type]);
} else {
dc->flags&=~DCF_TRANSFORMATION;
dc->color=pebble_colors[tempo->num&3];
GrPlot3(dc,s*tempo->x1+cx,s*tempo->y1+h,tempo->z1);
dc->color=pebble_colors[tmpo->num&3];
GrPlot3(dc,s*tmpo->x1+cx,s*tmpo->y1+h,tmpo->z1);
}
dc->flags&=~(DCF_SYMMETRY|DCF_JUST_MIRROR);
if (tempo==&objs[O_BURNING_BUSH]) {//draw burning bush
dc->x=s*tempo->x1+cx;
dc->y=s*tempo->y1+h;
dc->z=tempo->z1;
if (tmpo==&objs[O_BURNING_BUSH]) {//draw burning bush
dc->x=s*tmpo->x1+cx;
dc->y=s*tmpo->y1+h;
dc->z=tmpo->z1;
dc->pen_width=1;
dc->color=winmgr.updates&15;
for (j=0;j<45;j++) {
@@ -57,7 +57,7 @@ U0 MPDrawHoreb(CDC *dc2)
P2R(&x2,&y2,m,a);
GrLine3(dc,20*x1,20*y1-25,0,20*x2,20*y2-25,0);
}
if (SqrI64(s*tempo->x1)+SqrI64(s*tempo->y1)<300*300)
if (SqrI64(s*tmpo->x1)+SqrI64(s*tmpo->y1)<300*300)
horeb_done=TRUE;
}
}
+23 -23
View File
@@ -12,7 +12,7 @@ U0 DrawHoreb(CTask *task,CDC *dc)
h=task->pix_height,r[16],
cx=w>>1,cy=h>>1;
F64 s,m,a,x1,y1,x2,y2;
Obj *o_sort[O_NUM_OBJS+O_NUM_PEBBLES],*tempo;
Obj *o_sort[O_NUM_OBJS+O_NUM_PEBBLES],*tmpo;
Mat4x4IdentEqu(r);
Mat4x4RotY(r,-é);
@@ -30,46 +30,46 @@ U0 DrawHoreb(CTask *task,CDC *dc)
}
for (i=0;i<O_NUM_OBJS+O_NUM_PEBBLES;i++) {
tempo=&objs[i];
o_sort[i]=tempo;
tempo->x1=tempo->x+vx; tempo->y1=tempo->y; tempo->z1=tempo->z+vz;
Mat4x4MulXYZ(r,&tempo->x1,&tempo->y1,&tempo->z1);
if (tempo->type==OT_SHEEP ||
tempo->type==OT_GOAT1 || tempo->type==OT_GOAT2) {
dx=100*tempo->dx; dy=100*tempo->dy; dz=100*tempo->dz;
tmpo=&objs[i];
o_sort[i]=tmpo;
tmpo->x1=tmpo->x+vx; tmpo->y1=tmpo->y; tmpo->z1=tmpo->z+vz;
Mat4x4MulXYZ(r,&tmpo->x1,&tmpo->y1,&tmpo->z1);
if (tmpo->type==OT_SHEEP ||
tmpo->type==OT_GOAT1 || tmpo->type==OT_GOAT2) {
dx=100*tmpo->dx; dy=100*tmpo->dy; dz=100*tmpo->dz;
Mat4x4MulXYZ(r,&dx,&dy,&dz);
if (dx<0)
tempo->sym=TRUE;
tmpo->sym=TRUE;
else
tempo->sym=FALSE;
tmpo->sym=FALSE;
}
}
QSortI64(o_sort,O_NUM_OBJS+O_NUM_PEBBLES,&ObjCompare);
for (i=0;i<O_NUM_OBJS+O_NUM_PEBBLES;i++) {
tempo=o_sort[i];
if (tempo->z1<0) break;
s=100.0/(AbsI64(tempo->z1)+50);
if (tempo->type) {
tmpo=o_sort[i];
if (tmpo->z1<0) break;
s=100.0/(AbsI64(tmpo->z1)+50);
if (tmpo->type) {
Mat4x4IdentEqu(dc->r);
Mat4x4Scale(dc->r,s*2);
DCMat4x4Set(dc,dc->r);
dc->flags|=DCF_TRANSFORMATION;
if (tempo->sym) {
if (tmpo->sym) {
dc->flags|=DCF_SYMMETRY|DCF_JUST_MIRROR;
DCSymmetrySet(dc,s*tempo->x1+cx,s*tempo->y1+h,
s*tempo->x1+cx,s*tempo->y1+h+10);
DCSymmetrySet(dc,s*tmpo->x1+cx,s*tmpo->y1+h,
s*tmpo->x1+cx,s*tmpo->y1+h+10);
}
Sprite3B(dc,s*tempo->x1+cx,s*tempo->y1+h,0,imgs[tempo->type]);
Sprite3B(dc,s*tmpo->x1+cx,s*tmpo->y1+h,0,imgs[tmpo->type]);
} else {
dc->flags&=~DCF_TRANSFORMATION;
dc->color=pebble_colors[tempo->num&3];
GrPlot3(dc,s*tempo->x1+cx,s*tempo->y1+h,tempo->z1);
dc->color=pebble_colors[tmpo->num&3];
GrPlot3(dc,s*tmpo->x1+cx,s*tmpo->y1+h,tmpo->z1);
}
dc->flags&=~(DCF_SYMMETRY|DCF_JUST_MIRROR);
if (o_sort[i]==&objs[O_BURNING_BUSH]) {//draw burning bush
dc->x=s*tempo->x1+cx;
dc->y=s*tempo->y1+h;
dc->x=s*tmpo->x1+cx;
dc->y=s*tmpo->y1+h;
dc->z=0;
dc->pen_width=1;
@@ -82,7 +82,7 @@ U0 DrawHoreb(CTask *task,CDC *dc)
GrLine3(dc,20*x1,20*y1-25,0,20*x2,20*y2-25,0);
}
if (SqrI64(s*tempo->x1)+SqrI64(s*tempo->y1)<300*300)
if (SqrI64(s*tmpo->x1)+SqrI64(s*tmpo->y1)<300*300)
horeb_done=TRUE;
}
}
+19 -19
View File
@@ -2,18 +2,18 @@ U0 AnimateTask(I64)
{
I64 i;
F64 t;
Obj *tempo;
Obj *tmpo;
while (TRUE) {
t=tS;
for (i=0;i<O_NUM_OBJS+O_NUM_PEBBLES;i++) {
tempo=&objs[i];
if (tempo->type==OT_SHEEP ||
tempo->type==OT_GOAT1 || tempo->type==OT_GOAT2) {
tempo->x+=tempo->dx;
tempo->y+=tempo->dy;
tempo->z+=tempo->dz;
tempo->dx=5*Cos(0.5*t+tempo->é);
tempo->dz=5*Sin(0.5*t+tempo->é);
tmpo=&objs[i];
if (tmpo->type==OT_SHEEP ||
tmpo->type==OT_GOAT1 || tmpo->type==OT_GOAT2) {
tmpo->x+=tmpo->dx;
tmpo->y+=tmpo->dy;
tmpo->z+=tmpo->dz;
tmpo->dx=5*Cos(0.5*t+tmpo->é);
tmpo->dz=5*Sin(0.5*t+tmpo->é);
}
}
Sleep(20);
@@ -22,7 +22,7 @@ U0 AnimateTask(I64)
U0 Init()
{
Obj *tempo;
Obj *tmpo;
I64 i,j,k,total=0;
for (i=0;i<OT_NUM_TYPES;i++)
@@ -30,13 +30,13 @@ U0 Init()
MemSet(objs,0,sizeof(objs));
for (i=0;i<O_NUM_OBJS+O_NUM_PEBBLES;i++) {
tempo=&objs[i];
tempo->num=i;
tempo->x=RandU32&0x1FFF-0x1000;
tempo->y=0;
tempo->z=RandU32&0x1FFF-0x1000;
tempo->é=2*ã*Rand;
tempo->sym=RandU16&1;
tmpo=&objs[i];
tmpo->num=i;
tmpo->x=RandU32&0x1FFF-0x1000;
tmpo->y=0;
tmpo->z=RandU32&0x1FFF-0x1000;
tmpo->é=2*ã*Rand;
tmpo->sym=RandU16&1;
if (i<O_NUM_OBJS) {
k=0;
@@ -48,9 +48,9 @@ U0 Init()
else
k++;
}
tempo->type=k;
tmpo->type=k;
} else
tempo->type=OT_PEBBLE;
tmpo->type=OT_PEBBLE;
}
objs[O_BURNING_BUSH].type=OT_BUSH1;
Binary file not shown.
Binary file not shown.
+22 -22
View File
@@ -1,24 +1,24 @@
U0 BgtAcctsUpdate()
{
CBgtEntry *tempb;
CBgtTemplate *tempt;
tempb=b_head.next;
while (tempb!=&b_head) {
if (tempb->type!=BE_TEMPLATE_COPY) {
tempb->credit_idx=StrFileAdd(tempb->credit,
CBgtEntry *tmpb;
CBgtTemplate *tmpt;
tmpb=b_head.next;
while (tmpb!=&b_head) {
if (tmpb->type!=BE_TEMPLATE_COPY) {
tmpb->credit_idx=StrFileAdd(tmpb->credit,
&accts_table_strs,accts_table);
tempb->debit_idx =StrFileAdd(tempb->debit,
tmpb->debit_idx =StrFileAdd(tmpb->debit,
&accts_table_strs,accts_table);
}
tempb=tempb->next;
tmpb=tmpb->next;
}
tempt=t_head.next;
while (tempt!=&t_head) {
tempt->b.credit_idx=StrFileAdd(tempt->b.credit,
tmpt=t_head.next;
while (tmpt!=&t_head) {
tmpt->b.credit_idx=StrFileAdd(tmpt->b.credit,
&accts_table_strs,accts_table);
tempt->b.debit_idx =StrFileAdd(tempt->b.debit,
tmpt->b.debit_idx =StrFileAdd(tmpt->b.debit,
&accts_table_strs,accts_table);
tempt=tempt->next;
tmpt=tmpt->next;
}
}
@@ -44,9 +44,9 @@ U0 BgtAcctsRead()
I64 BgtAcctColor(U8 *st)
{
CHashGeneric *temph;
if (temph=HashFind(st,accts_table,SFT_GENERIC))
return temph->user_data1;
CHashGeneric *tmph;
if (tmph=HashFind(st,accts_table,SFT_GENERIC))
return tmph->user_data1;
else
return BLACK;
}
@@ -57,19 +57,19 @@ U8 *BgtPopUpAcct(U8 *header=NULL,U8 *dft=NULL)
U8 *res;
CDoc *doc=DocNew;
CDocEntry *doc_e,*doc_dft=NULL;
CHashGeneric *temph;
CHashGeneric *tmph;
if (header)
DocPrint(doc,"%s",header);
for (i=0;i<=accts_table->mask;i++) {
temph=accts_table->body[i];
while (temph) {
tmph=accts_table->body[i];
while (tmph) {
doc_e=DocPrint(doc,"$$FG,%d$$$$MU-UL,\"%s\",LE=0x%X$$\n",
temph->user_data1,temph->str,temph->str);
if (dft && !StrCmp(dft,temph->str))
tmph->user_data1,tmph->str,tmph->str);
if (dft && !StrCmp(dft,tmph->str))
doc_dft=doc_e;
temph=temph->next;
tmph=tmph->next;
}
}
+24 -24
View File
@@ -1,24 +1,24 @@
U0 BgtEntryDel2(CBgtEntry *tempb)
U0 BgtEntryDel2(CBgtEntry *tmpb)
{
if (tempb->type!=BE_TEMPLATE_COPY) {
Free(tempb->credit);
Free(tempb->debit);
Free(tempb->desc);
if (tmpb->type!=BE_TEMPLATE_COPY) {
Free(tmpb->credit);
Free(tmpb->debit);
Free(tmpb->desc);
}
}
U0 BgtEntryDel(CBgtEntry *tempb)
U0 BgtEntryDel(CBgtEntry *tmpb)
{
BgtEntryDel2(tempb);
Free(tempb);
BgtEntryDel2(tmpb);
Free(tmpb);
}
U0 BgtIns(CBgtEntry *tempb)
U0 BgtIns(CBgtEntry *tmpb)
{
CBgtEntry *tempb1=b_head.next;
while (tempb1!=&b_head && tempb1->date<tempb->date)
tempb1=tempb1->next;
QueIns(tempb,tempb1->last);
CBgtEntry *tmpb1=b_head.next;
while (tmpb1!=&b_head && tmpb1->date<tmpb->date)
tmpb1=tmpb1->next;
QueIns(tmpb,tmpb1->last);
}
class CBgtEntryForm
@@ -33,7 +33,7 @@ class CBgtEntryForm
CBgtEntry *BgtEntryPmt(CBgtEntry *dft=NULL)
{
CBgtEntryForm b;
CBgtEntry *tempb;
CBgtEntry *tmpb;
U8 *st;
MemSet(&b,0,sizeof(CBgtEntryForm));
StrCpy(&b.date,"*");
@@ -55,16 +55,16 @@ CBgtEntry *BgtEntryPmt(CBgtEntry *dft=NULL)
if (st!=DOCM_CANCEL)
StrCpy(b.debit,st);
} else {
tempb=CAlloc(sizeof(CBgtEntry));
tempb->date =Str2Date(b.date);
tempb->amount=b.amount;
tempb->credit=StrNew(b.credit);
tempb->debit =StrNew(b.debit);
tempb->desc =StrNew(b.desc);
tempb->type =BE_NORMAL;
StrFileAdd(tempb->credit,&accts_table_strs,accts_table);
StrFileAdd(tempb->debit,&accts_table_strs,accts_table);
return tempb;
tmpb=CAlloc(sizeof(CBgtEntry));
tmpb->date =Str2Date(b.date);
tmpb->amount=b.amount;
tmpb->credit=StrNew(b.credit);
tmpb->debit =StrNew(b.debit);
tmpb->desc =StrNew(b.desc);
tmpb->type =BE_NORMAL;
StrFileAdd(tmpb->credit,&accts_table_strs,accts_table);
StrFileAdd(tmpb->debit,&accts_table_strs,accts_table);
return tmpb;
}
} else
return NULL;
+59 -59
View File
@@ -1,7 +1,7 @@
U0 BgtDataRead()
{
CBgtEntry *tempb;
CBgtTemplate *tempt;
CBgtEntry *tmpb;
CBgtTemplate *tmpt;
I64 i,cnt,size;
U8 *b,*ptr;
I64 max_num;
@@ -17,26 +17,26 @@ U0 BgtDataRead()
if (ptr=b=FileRead(BGT_DATA_FILE,&size)) {
cnt=*ptr(I64 *)++;
for (i=0;i<cnt;i++) {
tempb=CAlloc(sizeof(CBgtEntry));
MemCpy(&tempb->start,ptr,BE_SIZE);
tempb->credit=StrNew(s[tempb->credit_idx]);
tempb->debit =StrNew(s[tempb->debit_idx]);
tempb->desc =StrNew(s[tempb->desc_idx]);
QueIns(tempb,b_head.last);
tmpb=CAlloc(sizeof(CBgtEntry));
MemCpy(&tmpb->start,ptr,BE_SIZE);
tmpb->credit=StrNew(s[tmpb->credit_idx]);
tmpb->debit =StrNew(s[tmpb->debit_idx]);
tmpb->desc =StrNew(s[tmpb->desc_idx]);
QueIns(tmpb,b_head.last);
ptr+=BE_SIZE;
}
cnt=*ptr(I64 *)++;
for (i=0;i<cnt;i++) {
tempt=CAlloc(sizeof(CBgtTemplate));
MemCpy(&tempt->start,ptr,BT_SIZE);
tmpt=CAlloc(sizeof(CBgtTemplate));
MemCpy(&tmpt->start,ptr,BT_SIZE);
ptr+=BT_SIZE;
MemCpy(&tempt->b.start,ptr,BE_SIZE);
MemCpy(&tmpt->b.start,ptr,BE_SIZE);
ptr+=BE_SIZE;
tempt->b.credit=StrNew(s[tempt->b.credit_idx]);
tempt->b.debit =StrNew(s[tempt->b.debit_idx]);
tempt->b.desc =StrNew(s[tempt->b.desc_idx]);
QueIns(tempt,t_head.last);
tmpt->b.credit=StrNew(s[tmpt->b.credit_idx]);
tmpt->b.debit =StrNew(s[tmpt->b.debit_idx]);
tmpt->b.desc =StrNew(s[tmpt->b.desc_idx]);
QueIns(tmpt,t_head.last);
}
}
@@ -50,39 +50,39 @@ U0 BgtDataWrite()
{
I64 i,num=0,size,cnt1,cnt2;
CHashTable *table=HashTableNew(1024);
CBgtEntry *tempb;
CBgtTemplate *tempt;
CHashGeneric *temph;
CBgtEntry *tmpb;
CBgtTemplate *tmpt;
CHashGeneric *tmph;
U8 *buf,*ptr;
for (i=0;i<=accts_table->mask;i++) {
temph=accts_table->body[i];
while (temph) {
StrFileAdd(temph->str,&num,table); //Cosmetics -- make accts appear first.
temph=temph->next;
tmph=accts_table->body[i];
while (tmph) {
StrFileAdd(tmph->str,&num,table); //Cosmetics -- make accts appear first.
tmph=tmph->next;
}
}
tempb=b_head.next;
tmpb=b_head.next;
cnt1=0;
while (tempb!=&b_head) {
if (tempb->type!=BE_TEMPLATE_COPY) {
tempb->credit_idx =StrFileAdd(tempb->credit,&num,table);
tempb->debit_idx =StrFileAdd(tempb->debit,&num,table);
tempb->desc_idx =StrFileAdd(tempb->desc,&num,table);
while (tmpb!=&b_head) {
if (tmpb->type!=BE_TEMPLATE_COPY) {
tmpb->credit_idx =StrFileAdd(tmpb->credit,&num,table);
tmpb->debit_idx =StrFileAdd(tmpb->debit,&num,table);
tmpb->desc_idx =StrFileAdd(tmpb->desc,&num,table);
cnt1++;
}
tempb=tempb->next;
tmpb=tmpb->next;
}
tempt=t_head.next;
tmpt=t_head.next;
cnt2=0;
while (tempt!=&t_head) {
tempt->b.credit_idx =StrFileAdd(tempt->b.credit,&num,table);
tempt->b.debit_idx =StrFileAdd(tempt->b.debit,&num,table);
tempt->b.desc_idx =StrFileAdd(tempt->b.desc,&num,table);
while (tmpt!=&t_head) {
tmpt->b.credit_idx =StrFileAdd(tmpt->b.credit,&num,table);
tmpt->b.debit_idx =StrFileAdd(tmpt->b.debit,&num,table);
tmpt->b.desc_idx =StrFileAdd(tmpt->b.desc,&num,table);
cnt2++;
tempt=tempt->next;
tmpt=tmpt->next;
}
StrFileWrite(BGT_STRINGS_FILE,table);
StrFileDel(table);
@@ -92,24 +92,24 @@ U0 BgtDataWrite()
MemCpy(ptr,&cnt1,sizeof(I64));
ptr+=sizeof(I64);
tempb=b_head.next;
while (tempb!=&b_head) {
if (tempb->type!=BE_TEMPLATE_COPY) {
MemCpy(ptr,&tempb->start,BE_SIZE);
tmpb=b_head.next;
while (tmpb!=&b_head) {
if (tmpb->type!=BE_TEMPLATE_COPY) {
MemCpy(ptr,&tmpb->start,BE_SIZE);
ptr+=BE_SIZE;
}
tempb=tempb->next;
tmpb=tmpb->next;
}
MemCpy(ptr,&cnt2,sizeof(I64));
ptr+=sizeof(I64);
tempt=t_head.next;
while (tempt!=&t_head) {
MemCpy(ptr,&tempt->start,BT_SIZE);
tmpt=t_head.next;
while (tmpt!=&t_head) {
MemCpy(ptr,&tmpt->start,BT_SIZE);
ptr+=BT_SIZE;
MemCpy(ptr,&tempt->b.start,BE_SIZE);
MemCpy(ptr,&tmpt->b.start,BE_SIZE);
ptr+=BE_SIZE;
tempt=tempt->next;
tmpt=tmpt->next;
}
FileWrite(BGT_DATA_FILE,buf,size);
@@ -118,21 +118,21 @@ U0 BgtDataWrite()
U0 BgtDel()
{
CBgtEntry *tempb,*tempb1;
CBgtTemplate *tempt,*tempt1;
tempb=b_head.next;
while (tempb!=&b_head) {
tempb1=tempb->next;
BgtEntryDel2(tempb);
Free(tempb);
tempb=tempb1;
CBgtEntry *tmpb,*tmpb1;
CBgtTemplate *tmpt,*tmpt1;
tmpb=b_head.next;
while (tmpb!=&b_head) {
tmpb1=tmpb->next;
BgtEntryDel2(tmpb);
Free(tmpb);
tmpb=tmpb1;
}
tempt=t_head.next;
while (tempt!=&t_head) {
tempt1=tempt->next;
BgtEntryDel2(&tempt->b);
Free(tempt);
tempt=tempt1;
tmpt=t_head.next;
while (tmpt!=&t_head) {
tmpt1=tmpt->next;
BgtEntryDel2(&tmpt->b);
Free(tmpt);
tmpt=tmpt1;
}
StrFileDel(accts_table);
accts_table=NULL;
+49 -49
View File
@@ -3,30 +3,30 @@ extern U0 BgtRegen();
Bool BgtPutKey(CDoc *doc,U8 *,I64 ch,I64 sc)
{//ch=ASCII; sc=scan_code
no_warn sc;
CBgtEntry *tempb,*tempb1;
CBgtTemplate *tempt,*tempt1;
CBgtEntry *tmpb,*tmpb1;
CBgtTemplate *tmpt,*tmpt1;
CDocEntry *doc_ce;
U8 *st;
switch (ch) {
case '\n':
if ((doc_ce=doc->cur_entry) && doc_ce!=doc &&
doc_ce->type_u8==DOCT_MENU_VAL) {
tempb=doc_ce->user_data;
if (tempt=tempb->template) {
if (tempt1=BgtTemplatePmt(tempt)) {
QueRem(tempt);
BgtTemplatePurge(tempt);
BgtEntryDel2(&tempt->b);
Free(tempt);
QueIns(tempt1,t_head.last);
BgtTemplateExpand(tempt1);
tmpb=doc_ce->user_data;
if (tmpt=tmpb->template) {
if (tmpt1=BgtTemplatePmt(tmpt)) {
QueRem(tmpt);
BgtTemplatePurge(tmpt);
BgtEntryDel2(&tmpt->b);
Free(tmpt);
QueIns(tmpt1,t_head.last);
BgtTemplateExpand(tmpt1);
BgtRegen;
}
} else {
if (tempb1=BgtEntryPmt(tempb)) {
QueRem(tempb);
BgtEntryDel(tempb);
BgtIns(tempb1);
if (tmpb1=BgtEntryPmt(tmpb)) {
QueRem(tmpb);
BgtEntryDel(tmpb);
BgtIns(tmpb1);
BgtRegen;
}
}
@@ -35,15 +35,15 @@ Bool BgtPutKey(CDoc *doc,U8 *,I64 ch,I64 sc)
case CH_CTRLY:
if ((doc_ce=doc->cur_entry) && doc_ce!=doc &&
doc_ce->type_u8==DOCT_MENU_VAL) {
tempb=doc_ce->user_data;
if (tempt=tempb->template) {
QueRem(tempt);
BgtTemplatePurge(tempt);
BgtEntryDel2(&tempt->b);
Free(tempt);
tmpb=doc_ce->user_data;
if (tmpt=tmpb->template) {
QueRem(tmpt);
BgtTemplatePurge(tmpt);
BgtEntryDel2(&tmpt->b);
Free(tmpt);
} else {
QueRem(tempb);
BgtEntryDel(tempb);
QueRem(tmpb);
BgtEntryDel(tmpb);
}
BgtRegen;
}
@@ -64,26 +64,26 @@ Bool BgtPutKey(CDoc *doc,U8 *,I64 ch,I64 sc)
}
return TRUE;
case 'n':
if (tempb1=BgtEntryPmt) {
BgtIns(tempb1);
if (tmpb1=BgtEntryPmt) {
BgtIns(tmpb1);
BgtRegen;
}
return TRUE;
case 't':
if (tempt1=BgtTemplatePmt) {
QueIns(tempt1,t_head.last);
BgtTemplateExpand(tempt1);
if (tmpt1=BgtTemplatePmt) {
QueIns(tmpt1,t_head.last);
BgtTemplateExpand(tmpt1);
BgtRegen;
}
return TRUE;
case 'c':
if ((doc_ce=doc->cur_entry) && doc_ce!=doc &&
doc_ce->type_u8==DOCT_MENU_VAL)
tempb=doc_ce->user_data;
tmpb=doc_ce->user_data;
else
tempb=NULL;
if (tempb1=BgtEntryPmt(tempb)) {
BgtIns(tempb1);
tmpb=NULL;
if (tmpb1=BgtEntryPmt(tmpb)) {
BgtIns(tmpb1);
BgtRegen;
}
return TRUE;
@@ -97,24 +97,24 @@ U0 BgtRegen()
F64 balance=0;
CDoc *doc,*pdoc,*ddoc;
CDocEntry *doc_ce;
CBgtEntry *tempb=b_head.next,*tempb_ce;
CBgtEntry *tmpb=b_head.next,*tmpb_ce;
doc=DocNew;
doc->flags|=DOCF_FORM;
while (tempb!=&b_head) {
if (!StrCmp(view_acct,tempb->credit))
balance-=tempb->amount;
if (!StrCmp(view_acct,tempb->debit))
balance+=tempb->amount;
c=BgtAcctColor(tempb->credit);
while (tmpb!=&b_head) {
if (!StrCmp(view_acct,tmpb->credit))
balance-=tmpb->amount;
if (!StrCmp(view_acct,tmpb->debit))
balance+=tmpb->amount;
c=BgtAcctColor(tmpb->credit);
if (c!=color) {
color=c;
DocPrint(doc,"$$FG,%d$$",color);
}
tempb->doc_e=DocPrint(doc,
tmpb->doc_e=DocPrint(doc,
"$$MU-UL,\"%D %8ts %8ts:%8.2f %8.2f:%$$Q\",U=0x%X$$\n",
tempb->date,tempb->credit,tempb->debit,balance,
tempb->amount,tempb->desc,tempb);
tempb=tempb->next;
tmpb->date,tmpb->credit,tmpb->debit,balance,
tmpb->amount,tmpb->desc,tmpb);
tmpb=tmpb->next;
}
DocRecalc(doc);
@@ -130,19 +130,19 @@ U0 BgtRegen()
doc_ce=pdoc->cur_entry;
timeout_jiffy=cnts.jiffies+JIFFY_FREQ; //Max one second.
while (doc_ce!=pdoc && cnts.jiffies<timeout_jiffy) {
while (doc_ce->type_u8!=DOCT_MENU_VAL || !(tempb_ce=doc_ce->user_data)) {
while (doc_ce->type_u8!=DOCT_MENU_VAL || !(tmpb_ce=doc_ce->user_data)) {
doc_ce=doc_ce->next;
if (doc_ce==pdoc) goto br_cont;
}
tempb=b_head.next;
while (tempb!=&b_head) {
if (tempb==tempb_ce) {
doc->cur_entry=tempb->doc_e;
tmpb=b_head.next;
while (tmpb!=&b_head) {
if (tmpb==tmpb_ce) {
doc->cur_entry=tmpb->doc_e;
doc->cur_col=0;
DocCenter(doc);
goto br_cont;
}
tempb=tempb->next;
tmpb=tmpb->next;
}
doc_ce=doc_ce->next;
}
+27 -27
View File
@@ -57,18 +57,18 @@ public U0 StrFileArrDel(U8 **a,I64 max_num)
public I64 StrFileAdd(U8 *st,I64 *_num,
CHashTable *table,I64 color=COLOR_INVALID)
{
CHashGeneric *temph;
CHashGeneric *tmph;
if (!st) return 0;
if (!(temph=HashFind(st,table,SFT_GENERIC))) {
temph=CAlloc(sizeof(CHashGeneric));
temph->type=SFT_GENERIC;
temph->str=StrNew(st);
temph->user_data0=(*_num)++;
HashAdd(temph,table);
if (!(tmph=HashFind(st,table,SFT_GENERIC))) {
tmph=CAlloc(sizeof(CHashGeneric));
tmph->type=SFT_GENERIC;
tmph->str=StrNew(st);
tmph->user_data0=(*_num)++;
HashAdd(tmph,table);
}
if (color!=COLOR_INVALID)
temph->user_data1=color;
return temph->user_data0;
tmph->user_data1=color;
return tmph->user_data0;
}
I64 StrEntriesCompare(CHashGeneric *h1,CHashGeneric *h2)
@@ -80,7 +80,7 @@ public U0 StrFileWrite(U8 *name,CHashTable *table,Bool no_nums=FALSE)
{
I64 i,j,cnt,color=BLACK;
CDoc *doc=DocNew(name);
CHashGeneric *temph,**a;
CHashGeneric *tmph,**a;
if (table) {
cnt=0; //Count Strings
for (i=0;i<=table->mask;i++)
@@ -88,23 +88,23 @@ public U0 StrFileWrite(U8 *name,CHashTable *table,Bool no_nums=FALSE)
a=MAlloc(cnt*sizeof(CHashGeneric *));
j=0; //Load Strings
for (i=0;i<=table->mask;i++) {
temph=table->body[i];
while (temph) {
a[j++]=temph;
temph=temph->next;
tmph=table->body[i];
while (tmph) {
a[j++]=tmph;
tmph=tmph->next;
}
}
QSortI64(a,cnt,&StrEntriesCompare);
for (i=0;i<cnt;i++) {
temph=a[i];
if (temph->user_data1&15!=color) {
DocPrint(doc,"$$FG,%d$$",temph->user_data1&15);
color=temph->user_data1&15;
tmph=a[i];
if (tmph->user_data1&15!=color) {
DocPrint(doc,"$$FG,%d$$",tmph->user_data1&15);
color=tmph->user_data1&15;
}
if (no_nums)
DocPrint(doc,"%s\n",temph->str);
DocPrint(doc,"%s\n",tmph->str);
else
DocPrint(doc,"%d,%s\n",temph->user_data0,temph->str);
DocPrint(doc,"%d,%s\n",tmph->user_data0,tmph->str);
}
Free(a);
}
@@ -116,15 +116,15 @@ public U0 StrFileWrite(U8 *name,CHashTable *table,Bool no_nums=FALSE)
public U0 StrFileDel(CHashTable *table)
{
I64 i;
CHashGeneric *temph,*temph1;
CHashGeneric *tmph,*tmph1;
if (!table) return;
for (i=0;i<=table->mask;i++) {
temph=table->body[i];
while (temph) {
temph1=temph->next;
Free(temph->str);
Free(temph);
temph=temph1;
tmph=table->body[i];
while (tmph) {
tmph1=tmph->next;
Free(tmph->str);
Free(tmph);
tmph=tmph1;
}
}
Free(table->body);
+54 -54
View File
@@ -1,37 +1,37 @@
U0 BgtTemplatePurge(CBgtTemplate *tempt)
U0 BgtTemplatePurge(CBgtTemplate *tmpt)
{
CBgtEntry *tempb,*tempb1;
tempb=b_head.next;
while (tempb!=&b_head) {
tempb1=tempb->next;
if (tempb->template==tempt) {
QueRem(tempb);
BgtEntryDel2(tempb);
Free(tempb);
CBgtEntry *tmpb,*tmpb1;
tmpb=b_head.next;
while (tmpb!=&b_head) {
tmpb1=tmpb->next;
if (tmpb->template==tmpt) {
QueRem(tmpb);
BgtEntryDel2(tmpb);
Free(tmpb);
}
tempb=tempb1;
tmpb=tmpb1;
}
}
U0 BgtTemplateExpand(CBgtTemplate *tempt)
U0 BgtTemplateExpand(CBgtTemplate *tmpt)
{
CDate d,start,end;
CDateStruct ds;
CBgtEntry *tempb;
CBgtEntry *tmpb;
start=MyStr2Date(tempt->start_date);
end =MyStr2Date(tempt->end_date);
tempt->b.template=tempt;
switch (tempt->type) {
start=MyStr2Date(tmpt->start_date);
end =MyStr2Date(tmpt->end_date);
tmpt->b.template=tmpt;
switch (tmpt->type) {
case BT_INTERVAL:
d=start;
while (d<=end) {
tempb=CAlloc(sizeof(CBgtEntry));
MemCpy(tempb,&tempt->b,sizeof(CBgtEntry));
tempb->date=d;
tempb->type=BE_TEMPLATE_COPY;
BgtIns(tempb);
d+=tempt->period*0x100000000;
tmpb=CAlloc(sizeof(CBgtEntry));
MemCpy(tmpb,&tmpt->b,sizeof(CBgtEntry));
tmpb->date=d;
tmpb->type=BE_TEMPLATE_COPY;
BgtIns(tmpb);
d+=tmpt->period*0x100000000;
}
break;
case BT_MONTHLY:
@@ -39,11 +39,11 @@ U0 BgtTemplateExpand(CBgtTemplate *tempt)
while (TRUE) {
d=Struct2Date(&ds);
if (d<=end) {
tempb=CAlloc(sizeof(CBgtEntry));
MemCpy(tempb,&tempt->b,sizeof(CBgtEntry));
tempb->date=d;
tempb->type=BE_TEMPLATE_COPY;
BgtIns(tempb);
tmpb=CAlloc(sizeof(CBgtEntry));
MemCpy(tmpb,&tmpt->b,sizeof(CBgtEntry));
tmpb->date=d;
tmpb->type=BE_TEMPLATE_COPY;
BgtIns(tmpb);
} else
break;
if (++ds.mon>11) {
@@ -57,11 +57,11 @@ U0 BgtTemplateExpand(CBgtTemplate *tempt)
while (TRUE) {
d=Struct2Date(&ds);
if (d<=end) {
tempb=CAlloc(sizeof(CBgtEntry));
MemCpy(tempb,&tempt->b,sizeof(CBgtEntry));
tempb->date=d;
tempb->type=BE_TEMPLATE_COPY;
BgtIns(tempb);
tmpb=CAlloc(sizeof(CBgtEntry));
MemCpy(tmpb,&tmpt->b,sizeof(CBgtEntry));
tmpb->date=d;
tmpb->type=BE_TEMPLATE_COPY;
BgtIns(tmpb);
} else
break;
ds.mon+=2;
@@ -76,11 +76,11 @@ U0 BgtTemplateExpand(CBgtTemplate *tempt)
while (TRUE) {
d=Struct2Date(&ds);
if (d<=end) {
tempb=CAlloc(sizeof(CBgtEntry));
MemCpy(tempb,&tempt->b,sizeof(CBgtEntry));
tempb->date=d;
tempb->type=BE_TEMPLATE_COPY;
BgtIns(tempb);
tmpb=CAlloc(sizeof(CBgtEntry));
MemCpy(tmpb,&tmpt->b,sizeof(CBgtEntry));
tmpb->date=d;
tmpb->type=BE_TEMPLATE_COPY;
BgtIns(tmpb);
} else
break;
ds.mon+=6;
@@ -95,11 +95,11 @@ U0 BgtTemplateExpand(CBgtTemplate *tempt)
while (TRUE) {
d=Struct2Date(&ds);
if (d<=end) {
tempb=CAlloc(sizeof(CBgtEntry));
MemCpy(tempb,&tempt->b,sizeof(CBgtEntry));
tempb->date=d;
tempb->type=BE_TEMPLATE_COPY;
BgtIns(tempb);
tmpb=CAlloc(sizeof(CBgtEntry));
MemCpy(tmpb,&tmpt->b,sizeof(CBgtEntry));
tmpb->date=d;
tmpb->type=BE_TEMPLATE_COPY;
BgtIns(tmpb);
} else
break;
ds.year++;
@@ -110,17 +110,17 @@ U0 BgtTemplateExpand(CBgtTemplate *tempt)
U0 CBgtTemplatesExpand()
{
CBgtTemplate *tempt=t_head.next;
while (tempt!=&t_head) {
BgtTemplateExpand(tempt);
tempt=tempt->next;
CBgtTemplate *tmpt=t_head.next;
while (tmpt!=&t_head) {
BgtTemplateExpand(tmpt);
tmpt=tmpt->next;
}
}
CBgtTemplate *BgtTemplatePmt(CBgtTemplate *dft_t=NULL)
{
CBgtTemplate t,*tempt;
CBgtEntry *tempb,*dft_b;
CBgtTemplate t,*tmpt;
CBgtEntry *tmpb,*dft_b;
MemSet(&t,0,sizeof(CBgtTemplate));
if (dft_t) {
MemCpy(&t.start,&dft_t->start,BT_SIZE);
@@ -134,12 +134,12 @@ CBgtTemplate *BgtTemplatePmt(CBgtTemplate *dft_t=NULL)
while (TRUE)
if (PopUpForm(&t) && ((t.type==BT_INTERVAL && t.period>0) ||
t.type>BT_INTERVAL)) {
if (tempb=BgtEntryPmt(dft_b)) {
tempt=CAlloc(sizeof(CBgtTemplate));
MemCpy(&tempt->start,&t.start,BT_SIZE);
MemCpy(&tempt->b,tempb,sizeof(CBgtEntry));
Free(tempb);
return tempt;
if (tmpb=BgtEntryPmt(dft_b)) {
tmpt=CAlloc(sizeof(CBgtTemplate));
MemCpy(&tmpt->start,&t.start,BT_SIZE);
MemCpy(&tmpt->b,tmpb,sizeof(CBgtEntry));
Free(tmpb);
return tmpt;
}
} else
break;
+1 -1
View File
@@ -1,6 +1,6 @@
#define BGT_STRINGS_FILE "~/Budget/Strs.DD.Z"
#define BGT_ACCTS_FILE "~/Budget/Accts.DD.Z"
#define BGT_DATA_FILE "~/Budget/Bgt.DAT.Z"
#define BGT_DATA_FILE "~/Budget/Bgt.DATA.Z"
#define BE_NORMAL 0
#define BE_GAS 1
+5 -5
View File
@@ -267,7 +267,7 @@ just to be different.
U0 DrawObj(CDC *dc,Obj *o,F64 tt)
{
U8 *temps;
U8 *tmps;
F64 r1=Max(9-0.1*o->z,1),r2=Max(r1/4,1);
if (o==human)
@@ -280,11 +280,11 @@ U0 DrawObj(CDC *dc,Obj *o,F64 tt)
if (o==ball)
Sprite3(dc,o->x,(o->y-o->z)/2,GR_Z_ALL-o->y,$IB,"<1>",BI=1$);
else {
temps=SpriteInterpolate((tt-o->last_t0)/(o->next_t0-o->last_t0),
tmps=SpriteInterpolate((tt-o->last_t0)/(o->next_t0-o->last_t0),
imgs[o->last_img].img[o->team],
imgs[o->next_img].img[o->team]);
SpriteY3B(dc,o->x,(o->y-o->z)/2,GR_Z_ALL-o->y,temps,o->é);
Free(temps);
SpriteY3B(dc,o->x,(o->y-o->z)/2,GR_Z_ALL-o->y,tmps,o->é);
Free(tmps);
}
}
@@ -616,7 +616,7 @@ U0 AnimateTask(CTask *parent_task)
}
}
}
WinMgrSync;
Refresh;
}
}
+1 -1
View File
@@ -580,7 +580,7 @@ U0 DigitalLogic()
Fs->draw_it=&DrawIt;
GetChar;
DocClear;
WinMgrSync(2,TRUE);
Refresh(2,TRUE);
DocBottom;
}
} catch
+24 -24
View File
@@ -18,20 +18,20 @@ CTask *SingleSong(U8 *msg,U8 *name)
Bool JBPutKey(CDoc *doc,U8 *,I64 ch,I64 sc)
{//ch=ASCII; sc=scan_code
CDocEntry *doc_ce=doc->cur_entry,*doc_e;
CDirEntry *tempde;
CDirEntry *tmpde;
CDoc *s;
if (!(sc&(SCF_ALT|SCF_CTRL|SCF_SHIFT))
&& doc_ce->type_u8==DOCT_MENU_VAL && doc_ce->left_exp>=0) {
tempde=doc_ce->left_exp;
tmpde=doc_ce->left_exp;
if (sc.u8[0]==SC_DELETE ) {
Beep;
Silent;
Del(tempde->full_name);
Del(tmpde->full_name);
Silent(OFF);
} else if ('0'<=ch<='9') {
if (StrLen(doc_ce->tag)>1)
doc_ce->tag[0]=ch;
s=DocRead(tempde->full_name);
s=DocRead(tmpde->full_name);
doc_e=s->head.next;
while (doc_e!=s && doc_e->type_u8!=DOCT_TEXT)
doc_e=doc_e->next;
@@ -42,7 +42,7 @@ Bool JBPutKey(CDoc *doc,U8 *,I64 ch,I64 sc)
DocDel(s);
return TRUE;
} else if (ch==CH_SPACE||ch==CH_ESC)
tempde->user_data++; //JB_RUN_LEVEL++
tmpde->user_data++; //JB_RUN_LEVEL++
//<SPACE> is followed by <ESC> --> JB_RUN_LEVEL_TWO
//Actual <ESC> just exits --> JB_RUN_LEVEL_ONE
}
@@ -53,7 +53,7 @@ public U0 JukeBox(U8 *dirname="~/Psalmody",U8 **_filename=NULL)
{//_filename is for using this as a song-chooser program.
I64 i=0,rating;
U8 *st,*st2;
CDirEntry *tempde,*tempde1;
CDirEntry *tmpde,*tmpde1;
CDoc *doc=DocNew,*s;
CDocEntry *doc_e;
CTask *task=NULL;
@@ -61,7 +61,7 @@ public U0 JukeBox(U8 *dirname="~/Psalmody",U8 **_filename=NULL)
*_filename=NULL;
dirname=StrNew(dirname);
st=MStrPrint("%s/*.HC.Z",dirname);
tempde=tempde1=FilesFind(st);
tmpde=tmpde1=FilesFind(st);
Free(st);
Free(dirname);
doc->user_put_key=&JBPutKey;
@@ -70,13 +70,13 @@ public U0 JukeBox(U8 *dirname="~/Psalmody",U8 **_filename=NULL)
"$$BLACK$$Incomplete $$CYAN$$Special$$FG$$\n\n"
"$$GREEN$$<DELETE>$$FG$$ to delete a song.\n"
"Press a number to rate a song.\n");
while (tempde) {
while (tmpde) {
if (!(i++%5))
DocPrint(doc,"\n");
if (FileOcc("Play(",tempde->full_name,"")) {
st=StrNew(tempde->name);
if (FileOcc("Play(",tmpde->full_name,"")) {
st=StrNew(tmpde->name);
FileExtRem(st);
s=DocRead(tempde->full_name);
s=DocRead(tmpde->full_name);
doc_e=s->head.next;
while (doc_e!=s && doc_e->type_u8!=DOCT_TEXT)
doc_e=doc_e->next;
@@ -94,7 +94,7 @@ public U0 JukeBox(U8 *dirname="~/Psalmody",U8 **_filename=NULL)
DocPrint(doc,"$$CYAN$$");
else if (StrMatch("no nothing",doc_e->tag)) {
DocPrint(doc,"$$RED$$");
if (FileOcc("\\0",tempde->full_name,"")) {
if (FileOcc("\\0",tmpde->full_name,"")) {
s->cur_entry=doc_e->next;
s->cur_col=0;
DocEntryDel(s,doc_e);
@@ -102,37 +102,37 @@ public U0 JukeBox(U8 *dirname="~/Psalmody",U8 **_filename=NULL)
DocWrite(s);
}
}
DocPrint(doc,"$$MU-UL,\"%c%-8ts\",LE=%d$$ ",rating,st,tempde);
tempde->user_data=JB_RUN_LEVEL_NULL;
DocPrint(doc,"$$MU-UL,\"%c%-8ts\",LE=%d$$ ",rating,st,tmpde);
tmpde->user_data=JB_RUN_LEVEL_NULL;
}
DocDel(s);
Free(st);
}
tempde=tempde->next;
tmpde=tmpde->next;
}
DocPrint(doc,"\n$$CYAN$$$$MU-UL,\"DONE\",LE=%d$$\n",DOCM_CANCEL);
while (TRUE) {
if (_filename)
tempde=PopUpMenu(doc,DOF_INTERCEPT_TASK_END);
tmpde=PopUpMenu(doc,DOF_INTERCEPT_TASK_END);
else
tempde=PopUpMenu(doc);
tmpde=PopUpMenu(doc);
if (task)
Kill(task);
if (tempde<=0) break;
st2=StrNew(tempde->name);
if (tmpde<=0) break;
st2=StrNew(tmpde->name);
if (_filename) {
Free(*_filename);
*_filename=StrNew(tempde->full_name);
*_filename=StrNew(tmpde->full_name);
}
if (tempde->user_data==JB_RUN_LEVEL_ONE) break; //<ESC>
tempde->user_data=JB_RUN_LEVEL_NULL; //Rst from <SPACE>
if (tmpde->user_data==JB_RUN_LEVEL_ONE) break; //<ESC>
tmpde->user_data=JB_RUN_LEVEL_NULL; //Rst from <SPACE>
FileExtRem(st2);
st=MStrPrint("ExeFile(\"%s\");",tempde->full_name);
st=MStrPrint("ExeFile(\"%s\");",tmpde->full_name);
MusicSettingsRst;
task=SingleSong(st,st2);
Free(st2);
Free(st);
}
DocDel(doc);
DirTreeDel(tempde1);
DirTreeDel(tmpde1);
}
+11 -11
View File
@@ -2,13 +2,13 @@ U0 SongPuppet(CTask *task,I64 passes)
{
CDbgInfo *dbg_info;
I64 i,start,end,rip,last_rip;
CHashFun *tempf=NULL;
CHashFun *tmpf=NULL;
for (i=0;i<250 && TaskValidate(task);i++) {
if (tempf=HashFind("Song",task->hash_table,HTT_FUN))
if (tmpf=HashFind("Song",task->hash_table,HTT_FUN))
break;
Sleep(1);
}
if (tempf && (dbg_info=tempf->dbg_info)) {
if (tmpf && (dbg_info=tmpf->dbg_info)) {
start=dbg_info->body[0];
end =dbg_info->body[dbg_info->max_line+1-dbg_info->min_line];
last_rip=0;
@@ -74,16 +74,16 @@ public U0 JukeSongsPuppet(U8 *dirname="~/Psalmody",I64 passes=2,
I64 start_song=0,I64 end_song=MAX_I64)
{//Help make music video by puppeting JukeBox task.
I64 i;
CDirEntry *tempde,*tempde1;
CDirEntry *tmpde,*tmpde1;
CTask *juke_task=User("JukeBox(0x%X);\n",dirname);
Cd(dirname);
tempde1=FilesFind("*",FUF_RECURSE|FUF_JUST_TXT|FUF_JUST_FILES);
for (tempde=tempde1,i=0;tempde && i<start_song;i++)
tempde=tempde->next;
for (i=start_song;tempde && i<end_song;i++) {
JukeSongPuppet(juke_task,passes,i,tempde->name);
tempde=tempde->next;
tmpde1=FilesFind("*",FUF_RECURSE|FUF_JUST_TXT|FUF_JUST_FILES);
for (tmpde=tmpde1,i=0;tmpde && i<start_song;i++)
tmpde=tmpde->next;
for (i=start_song;tmpde && i<end_song;i++) {
JukeSongPuppet(juke_task,passes,i,tmpde->name);
tmpde=tmpde->next;
}
DirTreeDel(tempde1);
DirTreeDel(tmpde1);
Kill(juke_task);
}
+3 -10
View File
@@ -19,7 +19,7 @@ This uses four types of output
4) The Fs->next_ctrl for the tempo/stacatto sliders.
See $LK,"GrUpdateTaskWin",A="MN:GrUpdateTaskWin"$(), $LK,"GrUpdateTasks",A="MN:GrUpdateTasks"$() and $LK,"GrUpdateScreen",A="MN:GrUpdateScreen"$().
See $LK,"GrUpdateTaskWin",A="MN:GrUpdateTaskWin"$(), $LK,"GrUpdateTasks",A="MN:GrUpdateTasks"$() and $LK,"GrUpdateScrn",A="MN:GrUpdateScrn"$().
$WW,1$$WW,0$*/
#define NOTE_REST MIN_I64
@@ -62,20 +62,13 @@ class PsmCtrl
PsmNote head;
PsmNote clipboard;
CMenuEntry *incomplete_entry,*record_entry;
I64 screen_x,
I64 scrn_x,
tool;
PsmNote *cur_note;
CDC *dc2;
Bool playing;
} oc;
} psm;
U8 *psm_note_lst="A\0A#\0B\0C\0C#\0D\0D#\0E\0F\0F#\0G\0G#\0";
U8 psm_note_map[12]={6,6,5,4,4,3,3,2,1,1,0,0};
U8 psm_note_inverse_map[7]={10,8,7,5,3,2,0};
#define PSMPM_NORMAL 0
#define PSMPM_REVERB1 1
#define PSMPM_NUM_PLAY_MODES 2
I64 psm_play_mode=0;
F64 psm_play_f=0;
+84 -86
View File
@@ -63,7 +63,7 @@ Bool psm_triplet_durations[PSM_NUM_DURATIONS]={TRUE,FALSE,TRUE,
Bool PsmBlink()
{
if (Blink || oc.playing)
if (Blink || psm.playing)
return TRUE;
else
return FALSE;
@@ -88,27 +88,27 @@ Bool PsmIsDotted(I64 duration)
U0 PsmMarkSel(I64 x1,I64 x2,Bool sel)
{
PsmNote *tempo=oc.head.next;
while (tempo!=&oc.head) {
PsmNote *tmpn=psm.head.next;
while (tmpn!=&psm.head) {
if (sel) {
if (x1<=tempo->x<=x2)
tempo->flags|=PSMF_SEL;
if (x1<=tmpn->x<=x2)
tmpn->flags|=PSMF_SEL;
} else
tempo->flags&=~PSMF_SEL;
tempo=tempo->next;
tmpn->flags&=~PSMF_SEL;
tmpn=tmpn->next;
}
}
U0 PsmSetWidth(PsmNote *tempo)
U0 PsmSetWidth(PsmNote *tmpn)
{
if (tempo->type==PSMT_METER)
tempo->width=12;
if (tmpn->type==PSMT_METER)
tmpn->width=12;
else {
tempo->width=PSM_NOTE_SPACING;
if (PsmIsDotted(tempo->duration))
tempo->width+=PSM_NOTE_SPACING/2;
if (Bt(&tempo->flags,PSMf_SHARP) || Bt(&tempo->flags,PSMf_FLAT))
tempo->width+=PSM_NOTE_SPACING;
tmpn->width=PSM_NOTE_SPACING;
if (PsmIsDotted(tmpn->duration))
tmpn->width+=PSM_NOTE_SPACING/2;
if (Bt(&tmpn->flags,PSMf_SHARP) || Bt(&tmpn->flags,PSMf_FLAT))
tmpn->width+=PSM_NOTE_SPACING;
}
}
@@ -116,18 +116,16 @@ U0 PsmSetOctave(I64 octave)
{
I64 i;
U8 buf[STR_LEN];
CMenuEntry *tempse;
CMenuEntry *tmpse;
for (i=0;i<=6;i++) {
StrPrint(buf,"Snd/Octave%d",i);
if (tempse=MenuEntryFind(Fs->cur_menu,buf)) {
if (tmpse=MenuEntryFind(Fs->cur_menu,buf)) {
if (i==octave)
tempse->checked=TRUE;
tmpse->checked=TRUE;
else
tempse->checked=FALSE;
tmpse->checked=FALSE;
}
}
if (tempse=MenuEntryFind(Fs->cur_menu,"Snd/Reverb"))
tempse->checked=psm_play_mode==1;
}
U0 DrawNote(CDC *dc,I64 x,I64 y,I64 duration)
@@ -150,21 +148,21 @@ U0 DrawTimeSignature(CDC *dc,I64 x,I64 y,I64 top,I64 bottom)
U0 PsmRecalcNoteXY()
{
F64 measure_len=4,measure_left=measure_len;
PsmNote *tempo=oc.head.next;
I64 x=8-oc.screen_x,note,octave;
PsmNote *tmpn=psm.head.next;
I64 x=8-psm.scrn_x,note,octave;
while (TRUE) {
tempo->x=x;
tempo->y=50;
if (tempo==&oc.head)
tmpn->x=x;
tmpn->y=50;
if (tmpn==&psm.head)
break;
else {
if (tempo->type!=PSMT_METER) {
octave=tempo->octave;
if (tmpn->type!=PSMT_METER) {
octave=tmpn->octave;
if (octave!=OCTAVE_REST) {
note=tempo->note;
if (Bt(&tempo->flags,PSMf_SHARP))
note=tmpn->note;
if (Bt(&tmpn->flags,PSMf_SHARP))
note--;
if (Bt(&tempo->flags,PSMf_FLAT))
if (Bt(&tmpn->flags,PSMf_FLAT))
note++;
if (note<0) {
note=11;
@@ -174,27 +172,27 @@ U0 PsmRecalcNoteXY()
octave++;
}
note=music.note_map[*LstSub(note,psm_note_lst)-'A'];
tempo->y=(15+(psm_note_map[note]-7*(octave-2)))*4;
tmpn->y=(15+(psm_note_map[note]-7*(octave-2)))*4;
}
}
x+=tempo->width;
if (tempo->type==PSMT_METER) {
measure_len=tempo->meter_top*4.0/tempo->meter_bottom;
x+=tmpn->width;
if (tmpn->type==PSMT_METER) {
measure_len=tmpn->meter_top*4.0/tmpn->meter_bottom;
measure_left=0;
} else
measure_left-=psm_durations[tempo->duration];
measure_left-=psm_durations[tmpn->duration];
if (measure_left<0.001) {
x+=PSM_NOTE_SPACING;
measure_left=measure_len;
}
}
tempo=tempo->next;
tmpn=tmpn->next;
}
}
U0 DrawIt(CTask *task,CDC *dc)
{
PsmNote *tempo;
PsmNote *tmpn;
I64 i,x,y,
w=task->pix_width;
F64 measure_len=4,measure_left=measure_len;
@@ -206,63 +204,63 @@ U0 DrawIt(CTask *task,CDC *dc)
GrLine(dc,0,i*8,w,i*8);
PsmRecalcNoteXY;
if (oc.cur_note->x<64) {
oc.screen_x-=128;
if (psm.cur_note->x<64) {
psm.scrn_x-=128;
PsmRecalcNoteXY;
}
if (oc.cur_note->x>=GR_WIDTH-64) {
oc.screen_x+=128;
if (psm.cur_note->x>=GR_WIDTH-64) {
psm.scrn_x+=128;
PsmRecalcNoteXY;
}
tempo=oc.head.next;
while (tempo!=&oc.head) {
x=tempo->x;
y=tempo->y;
tmpn=psm.head.next;
while (tmpn!=&psm.head) {
x=tmpn->x;
y=tmpn->y;
if (measure_left<0.001) {
dc->color=BLACK;
GrLine(dc,x-PSM_NOTE_SPACING,8,x-PSM_NOTE_SPACING,11*8);
measure_left=measure_len;
}
if (tempo->type==PSMT_METER) {
if (tempo==oc.cur_note && PsmBlink)
if (tmpn->type==PSMT_METER) {
if (tmpn==psm.cur_note && PsmBlink)
dc->color=BROWN;
else
dc->color=BLACK;
DrawTimeSignature(dc,x,5*8,tempo->meter_top,tempo->meter_bottom);
measure_len=tempo->meter_top*4.0/tempo->meter_bottom;
DrawTimeSignature(dc,x,5*8,tmpn->meter_top,tmpn->meter_bottom);
measure_len=tmpn->meter_top*4.0/tmpn->meter_bottom;
measure_left=0;
} else {
if (tempo==oc.cur_note && PsmBlink) {
if (tmpn==psm.cur_note && PsmBlink) {
dc->color=BROWN;
GrPrint(dc,x+8,y,"%s",tempo->word);
} else if (tempo->flags&PSMF_SEL)
GrPrint(dc,x+8,y,"%s",tmpn->word);
} else if (tmpn->flags&PSMF_SEL)
dc->color=RED;
else {
if (tempo->note!=NOTE_REST)
if (tmpn->note!=NOTE_REST)
dc->color=BLACK;
else
dc->color=LTGRAY;
if (PsmHasWords(tempo->word))
if (PsmHasWords(tmpn->word))
dc->color=GREEN;
}
DrawNote(dc,x,y,tempo->duration);
if (PsmIsDotted(tempo->duration))
DrawNote(dc,x,y,tmpn->duration);
if (PsmIsDotted(tmpn->duration))
x+=PSM_NOTE_SPACING/2;
if (Bt(&tempo->flags,PSMf_SHARP))
if (Bt(&tmpn->flags,PSMf_SHARP))
Sprite3(dc,x,y,0,$IB,"<13>",BI=13$);
else if (Bt(&tempo->flags,PSMf_FLAT))
else if (Bt(&tmpn->flags,PSMf_FLAT))
Sprite3(dc,x,y,0,$IB,"<14>",BI=14$);
measure_left-=psm_durations[tempo->duration];
measure_left-=psm_durations[tmpn->duration];
}
tempo=tempo->next;
tmpn=tmpn->next;
}
if (oc.cur_note==&oc.head && PsmBlink)
if (psm.cur_note==&psm.head && PsmBlink)
dc->color=BROWN;
else
dc->color=BLACK;
Sprite3(dc,oc.head.x,50,0,$IB,"<12>",BI=12$);
Sprite3(dc,psm.head.x,50,0,$IB,"<12>",BI=12$);
}
#define PSM_NOTE_BOX_X 220
@@ -298,12 +296,12 @@ U0 DrawPickNoteBox()
for (i=0;i<PSM_NUM_DURATIONS;i++) {
PsmSetPickNoteBoxX(i,&x);
if (PsmIsDotted(i))
oc.dc2->color=RED;
psm.dc2->color=RED;
else if (psm_triplet_durations[i])
oc.dc2->color=LTRED;
psm.dc2->color=LTRED;
else
oc.dc2->color=BLACK;
DrawNote(oc.dc2,x,PSM_NOTE_BOX_Y,i);
psm.dc2->color=BLACK;
DrawNote(psm.dc2,x,PSM_NOTE_BOX_Y,i);
}
}
@@ -312,19 +310,19 @@ U0 DrawPickNoteBox()
U0 DrawPickTools()
{
if (oc.tool==PSMTT_BOX_TOOL)
oc.dc2->color=ROPF_DITHER+WHITE<<16+RED;
if (psm.tool==PSMTT_BOX_TOOL)
psm.dc2->color=ROPF_DITHER+WHITE<<16+RED;
else
oc.dc2->color=ROPF_DITHER+WHITE<<16+BLACK;
GrBorder(oc.dc2,PSM_TOOLS_X,PSM_TOOLS_Y,
psm.dc2->color=ROPF_DITHER+WHITE<<16+BLACK;
GrBorder(psm.dc2,PSM_TOOLS_X,PSM_TOOLS_Y,
PSM_TOOLS_X+10,PSM_TOOLS_Y+10);
if (oc.tool==PSMTT_PTR_TOOL)
oc.dc2->color=RED;
if (psm.tool==PSMTT_PTR_TOOL)
psm.dc2->color=RED;
else
oc.dc2->color=BLACK;
(*gr.fp_draw_input_ptr)(oc.dc2,PSM_TOOLS_X+15,PSM_TOOLS_Y);
oc.dc2->color=BLACK;
psm.dc2->color=BLACK;
(*gr.fp_draw_input_ptr)(psm.dc2,PSM_TOOLS_X+15,PSM_TOOLS_Y);
psm.dc2->color=BLACK;
}
Bool PsmGetPickToolBox(I64 xx,I64 yy)
@@ -333,9 +331,9 @@ Bool PsmGetPickToolBox(I64 xx,I64 yy)
PSM_TOOLS_Y<=yy<PSM_TOOLS_Y+15) {
PsmMarkSel(0,0,FALSE);
if (xx<PSM_TOOLS_X+13)
oc.tool=PSMTT_BOX_TOOL;
psm.tool=PSMTT_BOX_TOOL;
else
oc.tool=PSMTT_PTR_TOOL;
psm.tool=PSMTT_PTR_TOOL;
return TRUE;
} else
return FALSE;
@@ -364,9 +362,9 @@ Bool PsmGetPickMeterBox(I64 xx,I64 yy,I64 *top,I64 *bottom)
U0 DrawPickMeterBox()
{
I64 i;
oc.dc2->color=BLACK;
psm.dc2->color=BLACK;
for (i=0;i<PSM_NUM_METERS;i++)
DrawTimeSignature(oc.dc2,PSM_METER_X+i*PSM_METER_W,PSM_METER_Y,
DrawTimeSignature(psm.dc2,PSM_METER_X+i*PSM_METER_W,PSM_METER_Y,
meter_tops[i],meter_bottoms[i]);
}
@@ -398,25 +396,25 @@ U0 PsmMenu(I64 psm_octave)
"$$LTGREEN$$<BACKSPACE>$$FG$$\tDeletes Last Note\n"
"$$LTGREEN$$Left Mouse$$FG$$\tDrag note or shift word\n"
"$$LTGREEN$$Right Mouse$$FG$$\tChange duration or set word\n";
Sprite($IB,"<6>",BI=6$,"$$SP+LA,\"\","
Sprite($IB,"<6>",BI=6$,"$$SP+LIS,\"\","
"LM=\"Msg(MSG_KEY_DOWN,0,SCF_CTRL|SC_CURSOR_LEFT);\",BI=%d$$");
" ";
if (oc.playing)
if (psm.playing)
Sprite($IB,"<9>",BI=9$,"$$SP,\"\",LM=\"x\",BI=%d$$");
else
Sprite($IB,"<8>",BI=8$,"$$SP,\"\",LM=\"x\",BI=%d$$");
" ";
if (oc.record_entry->checked) {
oc.record_entry->checked=TRUE;
if (psm.record_entry->checked) {
psm.record_entry->checked=TRUE;
Sprite($IB,"<10>",BI=10$,"$$SP,\"\",LM=\"z\",BI=%d$$");
} else
Sprite($IB,"<11>",BI=11$,"$$SP,\"\",LM=\"z\",BI=%d$$");
" ";
Sprite($IB,"<7>",BI=7$,"$$SP+LA,\"\","
Sprite($IB,"<7>",BI=7$,"$$SP+LIS,\"\","
"LM=\"Msg(MSG_KEY_DOWN,0,SCF_CTRL|SC_CURSOR_RIGHT);\",BI=%d$$");
"$$CM+LX,0,6$$";
PsmSetOctave(psm_octave);
WinMgrSync(2);
Refresh(2);
}
"
òÿÿÿñÿÿÿ
+129 -129
View File
@@ -1,83 +1,83 @@
U0 PsmNoteDel(PsmNote *tempo)
U0 PsmNoteDel(PsmNote *tmpn)
{
Free(tempo->word);
Free(tempo);
Free(tmpn->word);
Free(tmpn);
}
PsmNote *PsmNoteCopy(PsmNote *tempo)
PsmNote *PsmNoteCopy(PsmNote *tmpn)
{
PsmNote *tempo1=MAllocIdent(tempo);
if (tempo->word)
tempo1->word=StrNew(tempo->word);
PsmNote *tmpn1=MAllocIdent(tmpn);
if (tmpn->word)
tmpn1->word=StrNew(tmpn->word);
else
tempo1->word=NULL;
return tempo1;
tmpn1->word=NULL;
return tmpn1;
}
U0 PsmSongDel(PsmNote *head)
{
PsmNote *tempo,*tempo1;
tempo=head->next;
while (tempo!=head) {
tempo1=tempo->next;
PsmNoteDel(tempo);
tempo=tempo1;
PsmNote *tmpn,*tmpn1;
tmpn=head->next;
while (tmpn!=head) {
tmpn1=tmpn->next;
PsmNoteDel(tmpn);
tmpn=tmpn1;
}
QueInit(head);
}
U0 PsmCutToClipboard()
{
PsmNote *tempo,*tempo1;
PsmSongDel(&oc.clipboard);
tempo=oc.head.next;
while (tempo!=&oc.head) {
tempo1=tempo->next;
if (tempo->flags&PSMF_SEL) {
if (oc.cur_note==tempo)
oc.cur_note=tempo->next;
QueRem(tempo);
tempo->flags&=~PSMF_SEL;
QueIns(tempo,oc.clipboard.last);
PsmNote *tmpn,*tmpn1;
PsmSongDel(&psm.clipboard);
tmpn=psm.head.next;
while (tmpn!=&psm.head) {
tmpn1=tmpn->next;
if (tmpn->flags&PSMF_SEL) {
if (psm.cur_note==tmpn)
psm.cur_note=tmpn->next;
QueRem(tmpn);
tmpn->flags&=~PSMF_SEL;
QueIns(tmpn,psm.clipboard.last);
}
tempo=tempo1;
tmpn=tmpn1;
}
}
U0 PsmPasteClipboard()
{
PsmNote *tempo,*tempo1;
tempo=oc.clipboard.next;
while (tempo!=&oc.clipboard) {
tempo1=PsmNoteCopy(tempo);
QueIns(tempo1,oc.cur_note->last);
tempo=tempo->next;
PsmNote *tmpn,*tmpn1;
tmpn=psm.clipboard.next;
while (tmpn!=&psm.clipboard) {
tmpn1=PsmNoteCopy(tmpn);
QueIns(tmpn1,psm.cur_note->last);
tmpn=tmpn->next;
}
}
U0 PsmCopyToClipboard()
{
PsmNote *tempo,*tempo1;
PsmSongDel(&oc.clipboard);
tempo=oc.head.next;
while (tempo!=&oc.head) {
if (tempo->flags&PSMF_SEL) {
tempo->flags&=~PSMF_SEL;
tempo1=PsmNoteCopy(tempo);
QueIns(tempo1,oc.clipboard.last);
PsmNote *tmpn,*tmpn1;
PsmSongDel(&psm.clipboard);
tmpn=psm.head.next;
while (tmpn!=&psm.head) {
if (tmpn->flags&PSMF_SEL) {
tmpn->flags&=~PSMF_SEL;
tmpn1=PsmNoteCopy(tmpn);
QueIns(tmpn1,psm.clipboard.last);
}
tempo=tempo->next;
tmpn=tmpn->next;
}
}
PsmNote *PsmFindNote(I64 x,I64)
{
PsmNote *tempo=oc.head.next;
PsmNote *tmpn=psm.head.next;
PsmRecalcNoteXY;
x+=PSM_NOTE_SPACING/2;
while (x>tempo->next->x && tempo!=&oc.head)
tempo=tempo->next;
return tempo;
while (x>tmpn->next->x && tmpn!=&psm.head)
tmpn=tmpn->next;
return tmpn;
}
U8 *PsmMusicSetOctave(U8 *st,I64 *psm_octave)
@@ -109,48 +109,48 @@ U8 *PsmMusicSetNoteLen(U8 *st,F64 *psm_duration)
U0 PsmLoadSongStr(U8 *st,I64 *psm_octave,F64 *psm_duration)
{
PsmNote *tempo,*tempo1;
PsmNote *tmpn,*tmpn1;
I64 note,i=0;
while (*st) {
tempo=CAlloc(sizeof(PsmNote));
tmpn=CAlloc(sizeof(PsmNote));
while (*st && !('A'<=*st<='G') && *st!='R') {
if (*st=='M') {
tempo1=CAlloc(sizeof(PsmNote));
tempo1->type=PSMT_METER;
tmpn1=CAlloc(sizeof(PsmNote));
tmpn1->type=PSMT_METER;
st++;
if ('1'<=*st<='9')
tempo1->meter_top=*st++-'0';
tmpn1->meter_top=*st++-'0';
else
tempo1->meter_top=4;
tmpn1->meter_top=4;
if (*st=='/')
st++;
if ('1'<=*st<='9')
tempo1->meter_bottom=*st++-'0';
tmpn1->meter_bottom=*st++-'0';
else
tempo1->meter_bottom=4;
PsmSetWidth(tempo1);
QueIns(tempo1,oc.head.last);
tmpn1->meter_bottom=4;
PsmSetWidth(tmpn1);
QueIns(tmpn1,psm.head.last);
}
while (*st=='(') {
Bts(&tempo->flags,PSMf_TIE);
Bts(&tmpn->flags,PSMf_TIE);
st++;
}
st=PsmMusicSetOctave(st,psm_octave);
st=PsmMusicSetNoteLen(st,psm_duration);
}
if (!*st) {
PsmNoteDel(tempo);
PsmNoteDel(tmpn);
break;
}
note=*st++-'A';
if (note<7) {
note=music.note_map[note];
if (*st=='b') {
Bts(&tempo->flags,PSMf_FLAT);
Bts(&tmpn->flags,PSMf_FLAT);
note--;
st++;
} else if (*st=='#') {
Bts(&tempo->flags,PSMf_SHARP);
Bts(&tmpn->flags,PSMf_SHARP);
note++;
st++;
}
@@ -161,11 +161,11 @@ U0 PsmLoadSongStr(U8 *st,I64 *psm_octave,F64 *psm_duration)
note=0;
*psm_octave+=1;
}
tempo->note=note;
tempo->octave=*psm_octave;
tmpn->note=note;
tmpn->octave=*psm_octave;
} else {
tempo->note=NOTE_REST;
tempo->octave=OCTAVE_REST;
tmpn->note=NOTE_REST;
tmpn->octave=OCTAVE_REST;
}
if (*psm_duration<=2*.25/3)
i=0;
@@ -191,38 +191,38 @@ U0 PsmLoadSongStr(U8 *st,I64 *psm_octave,F64 *psm_duration)
i=10;
else
i=11;
tempo->duration=i;
tempo->type=PSMT_NOTE;
PsmSetWidth(tempo);
QueIns(tempo,oc.cur_note->last);
tmpn->duration=i;
tmpn->type=PSMT_NOTE;
PsmSetWidth(tmpn);
QueIns(tmpn,psm.cur_note->last);
}
}
U0 PsmLoadSong(U8 *filename,I64 *psm_octave,F64 *psm_duration)
{
U8 *st;
PsmNote *tempo;
PsmNote *tmpn;
CCmpCtrl *cc=CmpCtrlNew(MStrPrint("#include \"%s\"",filename));
if (FileOcc("incomplete",filename,""))
oc.incomplete_entry->checked=TRUE;
psm.incomplete_entry->checked=TRUE;
else
oc.incomplete_entry->checked=FALSE;
psm.incomplete_entry->checked=FALSE;
while (Lex(cc)) {
if (cc->token==TK_IDENT)
if (!StrCmp(cc->cur_str,"Play")) {
if (Lex(cc)=='(')
if (Lex(cc)==TK_STR) {
tempo=oc.head.last;
tmpn=psm.head.last;
st=LexExtStr(cc);
PsmLoadSongStr(st,psm_octave,psm_duration);
if (cc->token==',') {
if (Lex(cc)==TK_STR) {
st=LexExtStr(cc);
do {
do tempo=tempo->next;
while (tempo!=&oc.head && tempo->type==PSMT_METER);
if (tempo!=&oc.head)
tempo->word=StrNew(st);
do tmpn=tmpn->next;
while (tmpn!=&psm.head && tmpn->type==PSMT_METER);
if (tmpn!=&psm.head)
tmpn->word=StrNew(st);
st+=StrLen(st)+1;
} while (*st);
}
@@ -249,28 +249,28 @@ U0 PsmLoadSong(U8 *filename,I64 *psm_octave,F64 *psm_duration)
U8 *PsmCvtSong()
{
PsmNote *tempo;
PsmNote *tmpn;
U8 *st,*src,*dst;
I64 i,note,octave,last_octave,last_duration;
i=0;
tempo=oc.head.next;
tmpn=psm.head.next;
last_octave=OCTAVE_REST;
last_duration=-1;
while (tempo!=&oc.head) {
dst=&tempo->ascii;
if (tempo->type==PSMT_METER) {
while (tmpn!=&psm.head) {
dst=&tmpn->ascii;
if (tmpn->type==PSMT_METER) {
*dst++='M';
*dst++=tempo->meter_top+'0';
*dst++=tmpn->meter_top+'0';
*dst++='/';
*dst++=tempo->meter_bottom+'0';
*dst++=tmpn->meter_bottom+'0';
} else {
octave=tempo->octave;
note=tempo->note;
octave=tmpn->octave;
note=tmpn->note;
if (note!=NOTE_REST) {
if (Bt(&tempo->flags,PSMf_SHARP))
if (Bt(&tmpn->flags,PSMf_SHARP))
note--;
if (Bt(&tempo->flags,PSMf_FLAT))
if (Bt(&tmpn->flags,PSMf_FLAT))
note++;
if (note<0) {
note=11;
@@ -281,43 +281,43 @@ U8 *PsmCvtSong()
}
note=music.note_map[*LstSub(note,psm_note_lst)-'A'];
}
if (Bt(&tempo->flags,PSMf_TIE))
if (Bt(&tmpn->flags,PSMf_TIE))
*dst++='(';
if (octave!=last_octave && note!=NOTE_REST) {
*dst++=octave+'0';
last_octave=octave;
}
if (tempo->duration!=last_duration) {
src=LstSub(tempo->duration,psm_duration_lst);
if (tmpn->duration!=last_duration) {
src=LstSub(tmpn->duration,psm_duration_lst);
*dst++=src[0];
if (src[1])
*dst++=src[1];
last_duration=tempo->duration;
last_duration=tmpn->duration;
}
if (note!=NOTE_REST) {
src=LstSub(note,psm_note_lst);
*dst++=src[0];
if (src[1])
*dst++=src[1];
else if (Bt(&tempo->flags,PSMf_FLAT))
else if (Bt(&tmpn->flags,PSMf_FLAT))
*dst++='b';
else if (Bt(&tempo->flags,PSMf_SHARP))
else if (Bt(&tmpn->flags,PSMf_SHARP))
*dst++='#';
} else
*dst++='R';
}
*dst++=0;
i+=StrLen(tempo->ascii);
tempo=tempo->next;
i+=StrLen(tmpn->ascii);
tmpn=tmpn->next;
}
st=MAlloc(i+1);
dst=st;
tempo=oc.head.next;
while (tempo!=&oc.head) {
StrCpy(dst,tempo->ascii);
dst+=StrLen(tempo->ascii);
tempo=tempo->next;
tmpn=psm.head.next;
while (tmpn!=&psm.head) {
StrCpy(dst,tmpn->ascii);
dst+=StrLen(tmpn->ascii);
tmpn=tmpn->next;
}
*dst++=0;
return st;
@@ -327,23 +327,23 @@ U8 *PsmSaveSong(U8 *dirname,U8 *full_filename)
{
CDoc *doc=DocNew(full_filename);
Bool has_words;
PsmNote *tempo,*tempo1;
PsmNote *tmpn,*tmpn1;
F64 measure_len=4,two_measure_left=2*measure_len;
I64 ch;
U8 *ptr;
Free(PsmCvtSong); //set tempo->ascii;
Free(PsmCvtSong); //set tmpn->ascii;
music.tempo=4.4*tempo_state.tempo/TEMPO_RANGE+0.5;
music.stacatto_factor=0.88*tempo_state.stacatto/TEMPO_RANGE+0.12;
has_words=FALSE;
tempo=oc.head.next;
while (tempo!=&oc.head) {
if (PsmHasWords(tempo->word)) has_words=TRUE;
tempo=tempo->next;
tmpn=psm.head.next;
while (tmpn!=&psm.head) {
if (PsmHasWords(tmpn->word)) has_words=TRUE;
tmpn=tmpn->next;
}
if (oc.incomplete_entry->checked)
if (psm.incomplete_entry->checked)
DocPrint(doc,"//0 incomplete\n");
else if (has_words)
DocPrint(doc,"//0 has words\n");
@@ -361,58 +361,58 @@ U8 *PsmSaveSong(U8 *dirname,U8 *full_filename)
" while (!ScanKey) {\n"
"\tPlay(\"",music.tempo+0.0005,music.stacatto_factor+0.0005);
tempo=oc.head.next;
tempo1=tempo;
tmpn=psm.head.next;
tmpn1=tmpn;
has_words=FALSE;
while (tempo!=&oc.head) {
DocPrint(doc,"%s",tempo->ascii);
if (PsmHasWords(tempo->word)) has_words=TRUE;
if (tempo->type==PSMT_METER) {
measure_len=tempo->meter_top*4.0/tempo->meter_bottom;
while (tmpn!=&psm.head) {
DocPrint(doc,"%s",tmpn->ascii);
if (PsmHasWords(tmpn->word)) has_words=TRUE;
if (tmpn->type==PSMT_METER) {
measure_len=tmpn->meter_top*4.0/tmpn->meter_bottom;
two_measure_left=0;
} else
two_measure_left-=psm_durations[tempo->duration];
tempo=tempo->next;
if (two_measure_left<0.001 && tempo!=&oc.head) {
two_measure_left-=psm_durations[tmpn->duration];
tmpn=tmpn->next;
if (two_measure_left<0.001 && tmpn!=&psm.head) {
if (has_words) {
DocPrint(doc,"\",\n\t\t\"");
while (tempo1!=tempo) {
if (tempo1->type!=PSMT_METER) {
if (ptr=tempo1->word) {
while (tmpn1!=tmpn) {
if (tmpn1->type!=PSMT_METER) {
if (ptr=tmpn1->word) {
while (ch=*ptr) {
if (ch==CH_SPACE)
*ptr=CH_SHIFT_SPACE;
ptr++;
}
DocPrint(doc,"%Q\\0",tempo1->word);
DocPrint(doc,"%Q\\0",tmpn1->word);
} else
DocPrint(doc,"%c\\0",CH_SHIFT_SPACE);
}
tempo1=tempo1->next;
tmpn1=tmpn1->next;
}
}
DocPrint(doc,"\");\n"
"\tPlay(\"");
two_measure_left=2*measure_len;
tempo1=tempo;
tmpn1=tmpn;
has_words=FALSE;
}
}
if (has_words) {
DocPrint(doc,"\",\n\t\t\"");
while (tempo1!=tempo) {
if (tempo1->type!=PSMT_METER) {
if (ptr=tempo1->word) {
while (tmpn1!=tmpn) {
if (tmpn1->type!=PSMT_METER) {
if (ptr=tmpn1->word) {
while (ch=*ptr) {
if (ch==CH_SPACE)
*ptr=CH_SHIFT_SPACE;
ptr++;
}
DocPrint(doc,"%Q\\0",tempo1->word);
DocPrint(doc,"%Q\\0",tmpn1->word);
} else
DocPrint(doc,"%c\\0",CH_SHIFT_SPACE);
}
tempo1=tempo1->next;
tmpn1=tmpn1->next;
}
}
DocPrint(doc,"\");\n"
@@ -427,7 +427,7 @@ U8 *PsmSaveSong(U8 *dirname,U8 *full_filename)
if (full_filename)
Free(full_filename);
else
StrPrint(doc->filename.name,"%s/Temp.HC.Z",dirname);
StrPrint(doc->filename.name,"%s/Tmp.HC.Z",dirname);
DocWrite(doc,TRUE);
full_filename=StrNew(doc->filename.name);
DocDel(doc);
+179 -220
View File
@@ -28,94 +28,94 @@ F64 PopUpDuration()
U0 PsmRightClick(I64 x,I64 y)
{
U8 *st,*st2;
PsmNote *tempo,*tempo1;
PsmNote *tmpn,*tmpn1;
I64 i,old_doc_flags;
if (DocPut) old_doc_flags=DocPut->flags;
oc.cur_note=tempo=PsmFindNote(x,y);
if (tempo!=&oc.head) {
psm.cur_note=tmpn=PsmFindNote(x,y);
if (tmpn!=&psm.head) {
Fs->win_inhibit=WIG_USER_TASK_DFT;
i=PopUpDuration;
if (0<=i<PSM_NUM_DURATIONS) {
if (tempo->type==PSMT_NOTE)
tempo->duration=i;
if (tmpn->type==PSMT_NOTE)
tmpn->duration=i;
} else {
switch (i) {
case PSMR_REST:
if (tempo->type==PSMT_NOTE) {
tempo->octave=OCTAVE_REST;
tempo->note=NOTE_REST;
if (tmpn->type==PSMT_NOTE) {
tmpn->octave=OCTAVE_REST;
tmpn->note=NOTE_REST;
}
break;
case PSMR_SHARP:
if (tempo->type==PSMT_NOTE && tempo->octave!=OCTAVE_REST) {
if (Btr(&tempo->flags,PSMf_FLAT))
tempo->note++;
if (Btc(&tempo->flags,PSMf_SHARP))
tempo->note--;
if (tmpn->type==PSMT_NOTE && tmpn->octave!=OCTAVE_REST) {
if (Btr(&tmpn->flags,PSMf_FLAT))
tmpn->note++;
if (Btc(&tmpn->flags,PSMf_SHARP))
tmpn->note--;
else
tempo->note++;
if (tempo->note<0) {
tempo->note=11;
tempo->octave--;
} else if (tempo->note>11) {
tempo->note=0;
tempo->octave++;
tmpn->note++;
if (tmpn->note<0) {
tmpn->note=11;
tmpn->octave--;
} else if (tmpn->note>11) {
tmpn->note=0;
tmpn->octave++;
}
}
break;
case PSMR_FLAT:
if (tempo->type==PSMT_NOTE && tempo->octave!=OCTAVE_REST) {
if (Btr(&tempo->flags,PSMf_SHARP))
tempo->note--;
if (Btc(&tempo->flags,PSMf_FLAT))
tempo->note++;
if (tmpn->type==PSMT_NOTE && tmpn->octave!=OCTAVE_REST) {
if (Btr(&tmpn->flags,PSMf_SHARP))
tmpn->note--;
if (Btc(&tmpn->flags,PSMf_FLAT))
tmpn->note++;
else
tempo->note--;
if (tempo->note<0) {
tempo->note=11;
tempo->octave--;
} else if (tempo->note>11) {
tempo->note=0;
tempo->octave++;
tmpn->note--;
if (tmpn->note<0) {
tmpn->note=11;
tmpn->octave--;
} else if (tmpn->note>11) {
tmpn->note=0;
tmpn->octave++;
}
}
break;
case PSMR_TIE:
if (tempo->type==PSMT_NOTE)
Btc(&tempo->flags,PSMf_TIE);
if (tmpn->type==PSMT_NOTE)
Btc(&tmpn->flags,PSMf_TIE);
break;
case PSMR_SET_WORD:
if (tempo->type==PSMT_NOTE) {
if (tmpn->type==PSMT_NOTE) {
if (DocPut) DocPut->flags&=~DOCF_FORM;
if (PsmHasWords(tempo->word))
st2=MStrPrint("\nWord(\"%Q\"):",tempo->word);
if (PsmHasWords(tmpn->word))
st2=MStrPrint("\nWord(\"%Q\"):",tmpn->word);
else
st2=MStrPrint("\nWord(\"\"):");
DocBottom;
st=GetStr(st2);
Free(st2);
Free(tempo->word);
Free(tmpn->word);
if (*st) {
tempo->word=MStrPrint("%q",st);
tmpn->word=MStrPrint("%q",st);
Free(st);
} else
tempo->word=StrNew(" ");
tmpn->word=StrNew(" ");
if (DocPut) DocPut->flags=DocPut->flags&
~DOCF_FORM|old_doc_flags&DOCF_FORM;
}
break;
case PSMR_INS_NOTE:
tempo1=PsmNoteCopy(tempo);
QueIns(tempo1,tempo);
tmpn1=PsmNoteCopy(tmpn);
QueIns(tmpn1,tmpn);
break;
case PSMR_DELETE_NOTE:
oc.cur_note=tempo->next;
QueRem(tempo);
PsmNoteDel(tempo);
psm.cur_note=tmpn->next;
QueRem(tmpn);
PsmNoteDel(tmpn);
break;
}
}
PsmSetWidth(oc.cur_note);
PsmSetWidth(psm.cur_note);
Fs->win_inhibit=WIG_TASK_DFT-WIF_SELF_FOCUS
-WIF_SELF_BORDER-WIF_FOCUS_TASK_MENU-WIF_SELF_CTRLS;
}
@@ -124,23 +124,23 @@ U0 PsmRightClick(I64 x,I64 y)
U0 PsmLeftClickPickNoteBox(I64 duration)
{
I64 o,n,msg_code,a1,a2;
PsmNote *tempo,*tempo1;
PsmNote *tmpn,*tmpn1;
do {
msg_code=GetMsg(&a1,&a2,1<<MSG_IP_L_UP|1<<MSG_IP_MOVE);
if (msg_code==MSG_IP_MOVE) {
DrawDC2;
DrawNote(oc.dc2,a1,a2,duration);
DrawNote(psm.dc2,a1,a2,duration);
}
} while (msg_code!=MSG_IP_L_UP);
if (a2<13*FONT_HEIGHT) {
if (a1>oc.head.last->x)
tempo1=oc.head.last;
else if (a1<oc.head.next->x)
tempo1=&oc.head;
if (a1>psm.head.last->x)
tmpn1=psm.head.last;
else if (a1<psm.head.next->x)
tmpn1=&psm.head;
else
tempo1=PsmFindNote(a1-PSM_NOTE_SPACING/2,a2);
tempo=CAlloc(sizeof(PsmNote));
tempo->type=PSMT_NOTE;
tmpn1=PsmFindNote(a1-PSM_NOTE_SPACING/2,a2);
tmpn=CAlloc(sizeof(PsmNote));
tmpn->type=PSMT_NOTE;
a2=a2/4-15;
n=-a2%7;
o=2+a2/-7;
@@ -150,12 +150,12 @@ U0 PsmLeftClickPickNoteBox(I64 duration)
o++;
}
n=psm_note_inverse_map[n];
tempo->note=n;
tempo->octave=o;
tempo->duration=duration;
PsmSetWidth(tempo);
QueIns(tempo,tempo1);
oc.cur_note=tempo->next;
tmpn->note=n;
tmpn->octave=o;
tmpn->duration=duration;
PsmSetWidth(tmpn);
QueIns(tmpn,tmpn1);
psm.cur_note=tmpn->next;
}
DrawDC2;
}
@@ -163,53 +163,53 @@ U0 PsmLeftClickPickNoteBox(I64 duration)
U0 PsmLeftClickPickMeterBox(I64 top,I64 bottom)
{
I64 msg_code,a1,a2;
PsmNote *tempo,*tempo1;
PsmNote *tmpn,*tmpn1;
do {
msg_code=GetMsg(&a1,&a2,1<<MSG_IP_L_UP|1<<MSG_IP_MOVE);
if (msg_code==MSG_IP_MOVE) {
DrawDC2;
DrawTimeSignature(oc.dc2,a1,a2,top,bottom);
DrawTimeSignature(psm.dc2,a1,a2,top,bottom);
}
} while (msg_code!=MSG_IP_L_UP);
if (a2<13*FONT_HEIGHT) {
if (a1>=oc.head.x)
tempo1=oc.head.last;
else if (a1<oc.head.next->x)
tempo1=&oc.head;
if (a1>=psm.head.x)
tmpn1=psm.head.last;
else if (a1<psm.head.next->x)
tmpn1=&psm.head;
else
tempo1=PsmFindNote(a1-PSM_NOTE_SPACING/2,a2);
tempo=CAlloc(sizeof(PsmNote));
tempo->type=PSMT_METER;
tempo->meter_top=top;
tempo->meter_bottom=bottom;
PsmSetWidth(tempo);
QueIns(tempo,tempo1);
oc.cur_note=tempo->next;
tmpn1=PsmFindNote(a1-PSM_NOTE_SPACING/2,a2);
tmpn=CAlloc(sizeof(PsmNote));
tmpn->type=PSMT_METER;
tmpn->meter_top=top;
tmpn->meter_bottom=bottom;
PsmSetWidth(tmpn);
QueIns(tmpn,tmpn1);
psm.cur_note=tmpn->next;
}
DrawDC2;
}
U0 PsmLeftClickStaffPtr(I64 x,I64 y)
{
PsmNote *tempo,*tempo1;
PsmNote *tmpn,*tmpn1;
I64 o,n,msg_code,a1,a2,n_original,o_original;
oc.cur_note=tempo=PsmFindNote(x,y);
if (tempo!=&oc.head) {
if (tempo->type==PSMT_NOTE) {
n_original=tempo->note;
o_original=tempo->octave;
psm.cur_note=tmpn=PsmFindNote(x,y);
if (tmpn!=&psm.head) {
if (tmpn->type==PSMT_NOTE) {
n_original=tmpn->note;
o_original=tmpn->octave;
do {
msg_code=GetMsg(&a1,&a2,1<<MSG_IP_L_UP|1<<MSG_IP_MOVE);
if (msg_code==MSG_IP_L_UP) {
tempo1=PsmFindNote(a1,a2);
if (tempo1==&oc.head || tempo1==tempo)
tmpn1=PsmFindNote(a1,a2);
if (tmpn1==&psm.head || tmpn1==tmpn)
goto move_note;
else {
Free(tempo1->word);
tempo1->word=tempo->word;
tempo->word=NULL;
tempo->note=n_original;
tempo->octave=o_original;
Free(tmpn1->word);
tmpn1->word=tmpn->word;
tmpn->word=NULL;
tmpn->note=n_original;
tmpn->octave=o_original;
}
} else {
move_note:
@@ -222,11 +222,11 @@ move_note:
o++;
}
n=psm_note_inverse_map[n];
tempo->note=n;
tempo->octave=o;
tmpn->note=n;
tmpn->octave=o;
}
} while (msg_code!=MSG_IP_L_UP);
PsmSetWidth(tempo);
PsmSetWidth(tmpn);
}
}
}
@@ -237,8 +237,8 @@ U0 PsmLeftClickStaffBox(I64 x,I64 y)
do {
msg_code=GetMsg(&a1,&a2,1<<MSG_IP_L_UP|1<<MSG_IP_MOVE);
DrawDC2;
oc.dc2->color=ROPF_DITHER+WHITE<<16+BLACK;
GrBorder(oc.dc2,x,y,a1,a2);
psm.dc2->color=ROPF_DITHER+WHITE<<16+BLACK;
GrBorder(psm.dc2,x,y,a1,a2);
if (msg_code==MSG_IP_L_UP) {
if (x>a1) SwapI64(&x,&a1);
PsmMarkSel(x,a1,TRUE);
@@ -251,7 +251,7 @@ U0 PsmLeftClick(I64 x,I64 y)
{
I64 duration,top,bottom;
if (y<13*FONT_HEIGHT) {
if (oc.tool==PSMTT_PTR_TOOL)
if (psm.tool==PSMTT_PTR_TOOL)
PsmLeftClickStaffPtr(x,y);
else
PsmLeftClickStaffBox(x,y);
@@ -266,38 +266,6 @@ U0 PsmLeftClick(I64 x,I64 y)
}
}
U0 PsmPlayTask(I64)
{
I64 i=0;
F64 f=0,f2=0;
Fs->task_end_cb=&SndTaskEndCB;
while (TRUE) {
i++;
switch (psm_play_mode) {
case PSMPM_NORMAL:
if (psm_play_f!=f) {
f=psm_play_f;
Snd(f);
}
break;
case PSMPM_REVERB1:
if (psm_play_f!=f) {
if (f>0)
f2=f;
f=psm_play_f;
}
if (!(i&15)) {
if (i&16)
Snd(f);
else
Snd(f2);
}
break;
}
Sleep(1);
}
}
U8 PsmCvtDuration(F64 d)
{
F64 d1,d2;
@@ -403,8 +371,7 @@ U0 Psalmody(U8 *dirname="~/Psalmody")
note=NOTE_REST,octave=OCTAVE_REST,psm_octave=3,timeout_val,timeout_val2,
old_doc_flags;
U8 *filename=NULL,*st,*st2;
CTask *play_task=Spawn(&PsmPlayTask,NULL,"Psalmody Play",,Fs);
PsmNote *tempo;
PsmNote *tmpn;
F64 f=0,last_f=0,psm_duration=1.0,
d,evt_time=tS,note_down_time=tS;
CCtrl *c=TempoNew;
@@ -418,12 +385,12 @@ U0 Psalmody(U8 *dirname="~/Psalmody")
if (DocPut) DocPut->flags|=DOCF_FORM;
MemSet(&oc,0,sizeof(PsmCtrl));
oc.screen_x=0;
oc.head.next=oc.head.last=&oc.head;
oc.clipboard.next=oc.clipboard.last=&oc.clipboard;
oc.cur_note=&oc.head;
oc.dc2=DCAlias;
MemSet(&psm,0,sizeof(PsmCtrl));
psm.scrn_x=0;
psm.head.next=psm.head.last=&psm.head;
psm.clipboard.next=psm.clipboard.last=&psm.clipboard;
psm.cur_note=&psm.head;
psm.dc2=DCAlias;
MenuPush(
"File {"
@@ -454,7 +421,6 @@ U0 Psalmody(U8 *dirname="~/Psalmody")
" MarkIncomplete(MSG_CMD,PSMF_INCOMPLETE);"
"}"
"Snd {"
" Reverb(,'c');"
" Octave0(,'0');"
" Octave1(,'1');"
" Octave2(,'2');"
@@ -467,8 +433,8 @@ U0 Psalmody(U8 *dirname="~/Psalmody")
" Help(,,SC_F1);"
"}"
);
oc.incomplete_entry=MenuEntryFind(Fs->cur_menu,"Song/MarkIncomplete");
oc.record_entry=MenuEntryFind(Fs->cur_menu,"Song/Record");
psm.incomplete_entry=MenuEntryFind(Fs->cur_menu,"Song/MarkIncomplete");
psm.record_entry=MenuEntryFind(Fs->cur_menu,"Song/Record");
AutoComplete;
WinBorder;
@@ -522,7 +488,7 @@ mo_got_msg:
dirname=st2;
break;
case PSMF_INCOMPLETE:
oc.incomplete_entry->checked=!oc.incomplete_entry->checked;
psm.incomplete_entry->checked=!psm.incomplete_entry->checked;
break;
}
PsmPushMode(psm_octave);
@@ -569,31 +535,31 @@ mo_got_msg:
switch (a2.u8[0]) {
case SC_CURSOR_LEFT:
if (a2&SCF_CTRL) {
while (oc.cur_note->last!=&oc.head) {
oc.cur_note=oc.cur_note->last;
if (oc.cur_note!=&oc.head)
LBEqu(&oc.cur_note->flags,PSMf_SEL,a2&SCF_SHIFT);
while (psm.cur_note->last!=&psm.head) {
psm.cur_note=psm.cur_note->last;
if (psm.cur_note!=&psm.head)
LBEqu(&psm.cur_note->flags,PSMf_SEL,a2&SCF_SHIFT);
}
} else {
if (oc.cur_note->last!=&oc.head) {
oc.cur_note=oc.cur_note->last;
if (oc.cur_note!=&oc.head)
LBEqu(&oc.cur_note->flags,PSMf_SEL,a2&SCF_SHIFT);
if (psm.cur_note->last!=&psm.head) {
psm.cur_note=psm.cur_note->last;
if (psm.cur_note!=&psm.head)
LBEqu(&psm.cur_note->flags,PSMf_SEL,a2&SCF_SHIFT);
}
}
break;
case SC_CURSOR_RIGHT:
if (a2&SCF_CTRL) {
while (oc.cur_note!=&oc.head) {
if (oc.cur_note!=&oc.head)
LBEqu(&oc.cur_note->flags,PSMf_SEL,a2&SCF_SHIFT);
oc.cur_note=oc.cur_note->next;
while (psm.cur_note!=&psm.head) {
if (psm.cur_note!=&psm.head)
LBEqu(&psm.cur_note->flags,PSMf_SEL,a2&SCF_SHIFT);
psm.cur_note=psm.cur_note->next;
}
} else {
if (oc.cur_note!=&oc.head) {
if (oc.cur_note!=&oc.head)
LBEqu(&oc.cur_note->flags,PSMf_SEL,a2&SCF_SHIFT);
oc.cur_note=oc.cur_note->next;
if (psm.cur_note!=&psm.head) {
if (psm.cur_note!=&psm.head)
LBEqu(&psm.cur_note->flags,PSMf_SEL,a2&SCF_SHIFT);
psm.cur_note=psm.cur_note->next;
}
}
break;
@@ -601,11 +567,11 @@ mo_got_msg:
if (a2&SCF_SHIFT)
PsmCutToClipboard;
else {
tempo=oc.cur_note;
oc.cur_note=tempo->next;
if (tempo!=&oc.head) {
QueRem(tempo);
PsmNoteDel(tempo);
tmpn=psm.cur_note;
psm.cur_note=tmpn->next;
if (tmpn!=&psm.head) {
QueRem(tmpn);
PsmNoteDel(tmpn);
}
}
break;
@@ -647,14 +613,14 @@ mo_got_msg:
filename=NULL;
JukeBox(dirname,&filename);
if (filename) {
oc.screen_x=0;
psm.scrn_x=0;
psm_duration=1.0;
psm_octave=3;
PsmSongDel(&oc.head);
oc.cur_note=&oc.head;
PsmSongDel(&psm.head);
psm.cur_note=&psm.head;
PsmLoadSong(filename,&psm_octave,&psm_duration);
oc.record_entry->checked=FALSE;
oc.cur_note=oc.head.next;
psm.record_entry->checked=FALSE;
psm.cur_note=psm.head.next;
}
PsmPushMode(psm_octave);
col=0;
@@ -680,23 +646,23 @@ mo_got_msg:
filename=NULL;
psm_duration=1.0;
psm_octave=3;
PsmSongDel(&oc.head);
oc.cur_note=&oc.head;
oc.screen_x=0;
PsmSongDel(&psm.head);
psm.cur_note=&psm.head;
psm.scrn_x=0;
break;
case '\n':
if (oc.cur_note!=&oc.head)
PsmRightClick(oc.cur_note->x,oc.cur_note->y);
if (psm.cur_note!=&psm.head)
PsmRightClick(psm.cur_note->x,psm.cur_note->y);
break;
case 'x':
if (was_playing)
break;
col=0;
oc.playing=TRUE;
psm.playing=TRUE;
PsmMenu(psm_octave);
tempo=oc.cur_note;
while (tempo!=&oc.head) {
if (tempo->type!=PSMT_METER) {
tmpn=psm.cur_note;
while (tmpn!=&psm.head) {
if (tmpn->type!=PSMT_METER) {
timeout_val=cnts.jiffies;
if (ip.pos_text.y-Fs->win_top<18)
msg_code=ScanMsg(&a1,&a2,1<<MSG_KEY_DOWN|
@@ -706,8 +672,8 @@ mo_got_msg:
1<<MSG_IP_L_DOWN|1<<MSG_CMD);
if (msg_code) {
f=0;
psm_play_f=0;
oc.playing=FALSE;
Snd(0);
psm.playing=FALSE;
was_playing=TRUE;
if (ip.pos_text.y-Fs->win_top>=18 &&
msg_code==MSG_IP_L_DOWN)
@@ -715,26 +681,26 @@ mo_got_msg:
else
goto mo_got_msg;
}
oc.cur_note=tempo;
oc.screen_x+=tempo->x-0.33*GR_WIDTH;
if (PsmHasWords(tempo->word))
"%s",tempo->word;
note=tempo->note;
octave=tempo->octave;
psm.cur_note=tmpn;
psm.scrn_x+=tmpn->x-0.33*GR_WIDTH;
if (PsmHasWords(tmpn->word))
"%s",tmpn->word;
note=tmpn->note;
octave=tmpn->octave;
if (note!=NOTE_REST)
f=Note2Freq(note,octave);
else
f=-1; //rest
if (f>0)
psm_play_f=f;
Snd(f);
else
psm_play_f=0;
Snd(0);
music.tempo=4.4*tempo_state.tempo/TEMPO_RANGE+0.5;
music.stacatto_factor=
0.88*tempo_state.stacatto/TEMPO_RANGE+0.12;
d=JIFFY_FREQ*psm_durations[tempo->duration]/music.tempo;
if (Bt(&tempo->flags,PSMf_TIE)) {
d=JIFFY_FREQ*psm_durations[tmpn->duration]/music.tempo;
if (Bt(&tmpn->flags,PSMf_TIE)) {
timeout_val+=d;
timeout_val2=timeout_val;
} else {
@@ -743,44 +709,38 @@ mo_got_msg:
d*(1.0-music.stacatto_factor);
}
SleepUntil(timeout_val);
psm_play_f=0;
Snd(0);
SleepUntil(timeout_val2);
}
tempo=tempo->next;
tmpn=tmpn->next;
}
oc.cur_note=&oc.head;
oc.screen_x+=oc.cur_note->x-GR_WIDTH/2;
oc.playing=FALSE;
psm.cur_note=&psm.head;
psm.scrn_x+=psm.cur_note->x-GR_WIDTH/2;
psm.playing=FALSE;
PsmMenu(psm_octave);
col=0;
f=0;
psm_play_f=0;
Snd(0);
break;
case CH_BACKSPACE:
tempo=oc.cur_note->last;
if (tempo!=&oc.head) {
QueRem(tempo);
PsmNoteDel(tempo);
tmpn=psm.cur_note->last;
if (tmpn!=&psm.head) {
QueRem(tmpn);
PsmNoteDel(tmpn);
}
if (col) {
'' CH_BACKSPACE;
col--;
}
break;
case 'c':
psm_play_mode++;
if (psm_play_mode>=PSMPM_NUM_PLAY_MODES) psm_play_mode=0;
PsmMenu(psm_octave);
col=0;
break;
case 'z':
if (oc.record_entry->checked)
oc.record_entry->checked=FALSE;
if (psm.record_entry->checked)
psm.record_entry->checked=FALSE;
else {
oc.record_entry->checked=TRUE;
psm.record_entry->checked=TRUE;
psm_duration=1.0;
psm_octave=3;
oc.screen_x=0;
psm.scrn_x=0;
}
PsmMenu(psm_octave);
col=0;
@@ -818,32 +778,32 @@ mo_got_msg:
if (f!=last_f) {
if (f>0) {
st=LstSub(note,psm_note_lst);
psm_play_f=f;
Snd(f);
} else {
if (f<0)
st="R";
else
st="";
psm_play_f=0;
Snd(0);
}
if (oc.record_entry->checked) {
if (psm.record_entry->checked) {
if (last_f) {
music.tempo=4.4*tempo_state.tempo/TEMPO_RANGE+0.5;
music.stacatto_factor=0.88*tempo_state.stacatto/TEMPO_RANGE+0.12;
tempo->duration=PsmCvtDuration(
tmpn->duration=PsmCvtDuration(
music.tempo*(evt_time-note_down_time));
PsmSetWidth(tempo);
QueIns(tempo,oc.cur_note->last);
PsmSetWidth(tmpn);
QueIns(tmpn,psm.cur_note->last);
}
if (f) {
note_down_time=tS;
tempo=CAlloc(sizeof(PsmNote));
tempo->type=PSMT_NOTE;
tempo->note=note;
tempo->octave=octave;
tmpn=CAlloc(sizeof(PsmNote));
tmpn->type=PSMT_NOTE;
tmpn->note=note;
tmpn->octave=octave;
if (st[1]=='#')
Bts(&tempo->flags,PSMf_SHARP);
Bts(&tmpn->flags,PSMf_SHARP);
}
}
last_f=f;
@@ -860,12 +820,11 @@ mo_done:
} catch
PutExcept;
PsmPopMode;
PsmSongDel(&oc.head);
PsmSongDel(&oc.clipboard);
PsmSongDel(&psm.head);
PsmSongDel(&psm.clipboard);
TempoDel(c);
Kill(play_task);
DCFill;
DCDel(oc.dc2);
DCDel(psm.dc2);
DocClear;
SettingsPop;
if (DocPut) DocPut->flags=DocPut->flags&~DOCF_FORM|old_doc_flags&DOCF_FORM;
+27 -27
View File
@@ -21,27 +21,27 @@ U0 SpanBridge1Init(CMathODE *)
{
I64 i;
MyMass *tempm;
tempm=PlaceMass(GR_WIDTH-FIXED_X1,FIXED_Y1);
tempm->flags|=MSF_FIXED;
tempm=PlaceMass(GR_WIDTH-FIXED_X2,FIXED_Y1);
tempm->flags|=MSF_FIXED;
tempm=PlaceMass(GR_WIDTH-FIXED_X1,FIXED_Y2);
tempm->flags|=MSF_FIXED;
tempm=PlaceMass(FIXED_X1,FIXED_Y1);
tempm->flags|=MSF_FIXED;
tempm=PlaceMass(FIXED_X2,FIXED_Y1);
tempm->flags|=MSF_FIXED;
tempm=PlaceMass(FIXED_X1,FIXED_Y2);
tempm->flags|=MSF_FIXED;
tempm=PlaceMass(FIXED_X3,FIXED_Y3);
tempm->flags|=MSF_FIXED;
MyMass *tmpm;
tmpm=PlaceMass(GR_WIDTH-FIXED_X1,FIXED_Y1);
tmpm->flags|=MSF_FIXED;
tmpm=PlaceMass(GR_WIDTH-FIXED_X2,FIXED_Y1);
tmpm->flags|=MSF_FIXED;
tmpm=PlaceMass(GR_WIDTH-FIXED_X1,FIXED_Y2);
tmpm->flags|=MSF_FIXED;
tmpm=PlaceMass(FIXED_X1,FIXED_Y1);
tmpm->flags|=MSF_FIXED;
tmpm=PlaceMass(FIXED_X2,FIXED_Y1);
tmpm->flags|=MSF_FIXED;
tmpm=PlaceMass(FIXED_X1,FIXED_Y2);
tmpm->flags|=MSF_FIXED;
tmpm=PlaceMass(FIXED_X3,FIXED_Y3);
tmpm->flags|=MSF_FIXED;
for (i=0;i<LOAD_WEIGHTS;i++) {
tempm=PlaceMass(FIXED_X1+(i+1)*(GR_WIDTH-2*FIXED_X1)/(LOAD_WEIGHTS+1),
tmpm=PlaceMass(FIXED_X1+(i+1)*(GR_WIDTH-2*FIXED_X1)/(LOAD_WEIGHTS+1),
FIXED_Y1);
tempm->load_t=(i+1.0)/LOAD_WEIGHTS;
tempm->color=RED;
tmpm->load_t=(i+1.0)/LOAD_WEIGHTS;
tmpm->color=RED;
}
DocClear;
@@ -62,19 +62,19 @@ U0 SpanBridge1Init(CMathODE *)
U0 AdjustLoads(CMathODE *ode)
{
MyMass *tempm=ode->next_mass;
MyMass *tmpm=ode->next_mass;
F64 d,tt=SpanTime/10.0;
while (tempm!=&ode->next_mass) {
if (tempm->load_t) {
while (tmpm!=&ode->next_mass) {
if (tmpm->load_t) {
if (tt) {
d=Abs(Sin(tempm->load_t*ã+tt)); //0.0<=d<=1.0
tempm->mass=100.0*Sqr(Sqr(d+1.0));
tempm->radius=7.0*d+2.0;
d=Abs(Sin(tmpm->load_t*ã+tt)); //0.0<=d<=1.0
tmpm->mass=100.0*Sqr(Sqr(d+1.0));
tmpm->radius=7.0*d+2.0;
} else {
tempm->mass=MASS_MASS;
tempm->radius=MASS_RADIUS;
tmpm->mass=MASS_MASS;
tmpm->radius=MASS_RADIUS;
}
}
tempm=tempm->next;
tmpm=tmpm->next;
}
}
+17 -17
View File
@@ -7,32 +7,32 @@ U0 MyDerivative(CMathODE *ode,F64,COrder2D3 *,COrder2D3 *)
CTask *task=ode->win_task;
F64 d,dd;
CD3 p,p2;
MyMass *tempm1,*tempm2;
MyMass *tmpm1,*tmpm2;
//Collisions
tempm1=ode->next_mass;
while (tempm1!=&ode->next_mass) {
tempm2=tempm1->next;
while (tempm2!=&ode->next_mass) {
D3Sub(&p,&tempm2->state->x,&tempm1->state->x);
tmpm1=ode->next_mass;
while (tmpm1!=&ode->next_mass) {
tmpm2=tmpm1->next;
while (tmpm2!=&ode->next_mass) {
D3Sub(&p,&tmpm2->state->x,&tmpm1->state->x);
dd=D3NormSqr(&p);
if (dd<=Sqr(tempm1->radius+tempm2->radius)) {
if (dd<=Sqr(tmpm1->radius+tmpm2->radius)) {
d=Sqrt(dd)+0.0001;
dd=10.0*Sqr(Sqr(Sqr(tempm1->radius+tempm2->radius)-dd));
dd=10.0*Sqr(Sqr(Sqr(tmpm1->radius+tmpm2->radius)-dd));
D3MulEqu(&p,dd/d);
D3AddEqu(&tempm2->DstateDt->DxDt,&p);
D3SubEqu(&tempm1->DstateDt->DxDt,&p);
D3AddEqu(&tmpm2->DstateDt->DxDt,&p);
D3SubEqu(&tmpm1->DstateDt->DxDt,&p);
}
tempm2=tempm2->next;
tmpm2=tmpm2->next;
}
tempm1=tempm1->next;
tmpm1=tmpm1->next;
}
tempm1=ode->next_mass;
while (tempm1!=&ode->next_mass) {
if (!(tempm1->flags&MSF_FIXED))
tempm1->DstateDt->DyDt+=10.0*tempm1->mass; //Gravity
tempm1=tempm1->next;
tmpm1=ode->next_mass;
while (tmpm1!=&ode->next_mass) {
if (!(tmpm1->flags&MSF_FIXED))
tmpm1->DstateDt->DyDt+=10.0*tmpm1->mass; //Gravity
tmpm1=tmpm1->next;
}
if (cursor_mass) {
+137 -137
View File
@@ -8,36 +8,36 @@ F64 SpanTime()
F64 Cost(CMathODE *ode)
{
MyMass *tempm;
MySpring *temps;
MyMass *tmpm;
MySpring *tmps;
F64 res=0;
tempm=ode->next_mass;
while (tempm!=&ode->next_mass) {
res+=tempm->cost;
tempm=tempm->next;
tmpm=ode->next_mass;
while (tmpm!=&ode->next_mass) {
res+=tmpm->cost;
tmpm=tmpm->next;
}
temps=ode->next_spring;
while (temps!=&ode->next_spring) {
res+=temps->cost;
temps=temps->next;
tmps=ode->next_spring;
while (tmps!=&ode->next_spring) {
res+=tmps->cost;
tmps=tmps->next;
}
return res;
}
U0 DrawIt(CTask *task,CDC *dc)
{
MyMass *tempm;
MySpring *temps;
MyMass *tmpm;
MySpring *tmps;
temps=ode->next_spring;
while (temps!=&ode->next_spring) {
if (!(temps->flags&SSF_INACTIVE)) {
dc->color=temps->color;
dc->pen_width=temps->pen_width;
GrLine3(dc,temps->end1->x,temps->end1->y,0,
temps->end2->x,temps->end2->y,0);
tmps=ode->next_spring;
while (tmps!=&ode->next_spring) {
if (!(tmps->flags&SSF_INACTIVE)) {
dc->color=tmps->color;
dc->pen_width=tmps->pen_width;
GrLine3(dc,tmps->end1->x,tmps->end1->y,0,
tmps->end2->x,tmps->end2->y,0);
}
temps=temps->next;
tmps=tmps->next;
}
if (cursor_mass) {
@@ -48,19 +48,19 @@ U0 DrawIt(CTask *task,CDC *dc)
cursor_mass->x,cursor_mass->y,0);
}
tempm=ode->next_mass;
while (tempm!=&ode->next_mass) {
if (!(tempm->flags&MSF_INACTIVE)) {
tmpm=ode->next_mass;
while (tmpm!=&ode->next_mass) {
if (!(tmpm->flags&MSF_INACTIVE)) {
dc->color=BLACK;
GrCircle(dc,tempm->x,tempm->y,tempm->radius);
GrFloodFill(dc,tempm->x,tempm->y,TRUE);
dc->color=tempm->color;
GrCircle(dc,tempm->x,tempm->y,tempm->radius);
GrFloodFill(dc,tempm->x,tempm->y,TRUE);
GrCircle(dc,tmpm->x,tmpm->y,tmpm->radius);
GrFloodFill(dc,tmpm->x,tmpm->y,TRUE);
dc->color=tmpm->color;
GrCircle(dc,tmpm->x,tmpm->y,tmpm->radius);
GrFloodFill(dc,tmpm->x,tmpm->y,TRUE);
dc->color=BLACK;
GrCircle(dc,tempm->x,tempm->y,tempm->radius);
GrCircle(dc,tmpm->x,tmpm->y,tmpm->radius);
}
tempm=tempm->next;
tmpm=tmpm->next;
}
dc->color=BLACK;
@@ -70,69 +70,69 @@ U0 DrawIt(CTask *task,CDC *dc)
MyMass *PlaceMass(I64 x, I64 y)
{
MyMass *tempm=CAlloc(sizeof(MyMass));
tempm->drag_profile_factor=1.0;
tempm->x=x;
tempm->y=y;
tempm->mass=MASS_MASS;
tempm->radius=MASS_RADIUS;
tempm->cost=25.0*COST_SCALE;
tempm->color=YELLOW;
QueIns(tempm,ode->last_mass);
return tempm;
MyMass *tmpm=CAlloc(sizeof(MyMass));
tmpm->drag_profile_factor=1.0;
tmpm->x=x;
tmpm->y=y;
tmpm->mass=MASS_MASS;
tmpm->radius=MASS_RADIUS;
tmpm->cost=25.0*COST_SCALE;
tmpm->color=YELLOW;
QueIns(tmpm,ode->last_mass);
return tmpm;
}
U0 NullSpring(MySpring *temps,F64 scale)
U0 NullSpring(MySpring *tmps,F64 scale)
{
F64 d=D3Dist(&temps->end1->x,&temps->end2->x);
temps->rest_len=d*scale;
temps->compression_strength=
temps->base_compression_strength/(temps->rest_len+1.0);
temps->tensile_strength=temps->base_tensile_strength/(temps->rest_len+1.0);
temps->const=temps->base_const/(temps->rest_len+1.0);
temps->cost=temps->base_cost*temps->rest_len;
F64 d=D3Dist(&tmps->end1->x,&tmps->end2->x);
tmps->rest_len=d*scale;
tmps->compression_strength=
tmps->base_compression_strength/(tmps->rest_len+1.0);
tmps->tensile_strength=tmps->base_tensile_strength/(tmps->rest_len+1.0);
tmps->const=tmps->base_const/(tmps->rest_len+1.0);
tmps->cost=tmps->base_cost*tmps->rest_len;
}
U0 MoveMass(MyMass *tempm,I64 x, I64 y)
U0 MoveMass(MyMass *tmpm,I64 x, I64 y)
{
MySpring *temps;
tempm->x=x;
tempm->y=y;
tempm->DxDt=0;
tempm->DyDt=0;
temps=ode->next_spring;
while (temps!=&ode->next_spring) {
if (temps->end1==tempm || temps->end2==tempm) {
if (temps->flags&SSF_NO_COMPRESSION)
NullSpring(temps,WIRE_PERCENT);
MySpring *tmps;
tmpm->x=x;
tmpm->y=y;
tmpm->DxDt=0;
tmpm->DyDt=0;
tmps=ode->next_spring;
while (tmps!=&ode->next_spring) {
if (tmps->end1==tmpm || tmps->end2==tmpm) {
if (tmps->flags&SSF_NO_COMPRESSION)
NullSpring(tmps,WIRE_PERCENT);
else
NullSpring(temps,1.0);
NullSpring(tmps,1.0);
}
temps=temps->next;
tmps=tmps->next;
}
}
U0 DelSpring(MySpring *temps)
U0 DelSpring(MySpring *tmps)
{
QueRem(temps);
Free(temps);
QueRem(tmps);
Free(tmps);
}
U0 DelMass(MyMass *tempm)
U0 DelMass(MyMass *tmpm)
{
MySpring *temps,*temps1;
temps=ode->next_spring;
while (temps!=&ode->next_spring) {
temps1=temps->next;
if (temps->end1==tempm || temps->end2==tempm)
DelSpring(temps);
temps=temps1;
MySpring *tmps,*tmps1;
tmps=ode->next_spring;
while (tmps!=&ode->next_spring) {
tmps1=tmps->next;
if (tmps->end1==tmpm || tmps->end2==tmpm)
DelSpring(tmps);
tmps=tmps1;
}
QueRem(tempm);
Free(tempm);
QueRem(tmpm);
Free(tmpm);
}
U0 DrawSpring(CDC *dc,MyMass *tempm,I64 x,I64 y)
U0 DrawSpring(CDC *dc,MyMass *tmpm,I64 x,I64 y)
{
switch (mode_button.state) {
case MD_CONCRETE:
@@ -148,66 +148,66 @@ U0 DrawSpring(CDC *dc,MyMass *tempm,I64 x,I64 y)
dc->pen_width=1;
break;
}
GrLine3(dc,tempm->x,tempm->y,0,x,y,0);
GrLine3(dc,tmpm->x,tmpm->y,0,x,y,0);
}
U0 PlaceSpring(MyMass *tempm1,MyMass *tempm2)
U0 PlaceSpring(MyMass *tmpm1,MyMass *tmpm2)
{
MySpring *temps=CAlloc(sizeof(MySpring));
temps->end1=tempm1;
temps->end2=tempm2;
MySpring *tmps=CAlloc(sizeof(MySpring));
tmps->end1=tmpm1;
tmps->end2=tmpm2;
switch (mode_button.state) {
case MD_CONCRETE:
temps->base_const = 3.00*SPRING_SCALE;
temps->base_compression_strength=10.00*STRENGTH_SCALE;
temps->base_tensile_strength = 0.35*STRENGTH_SCALE;
temps->base_cost = 0.30*COST_SCALE;
NullSpring(temps,1.0);
temps->color=LTGRAY;
temps->pen_width=2;
tmps->base_const = 3.00*SPRING_SCALE;
tmps->base_compression_strength=10.00*STRENGTH_SCALE;
tmps->base_tensile_strength = 0.35*STRENGTH_SCALE;
tmps->base_cost = 0.30*COST_SCALE;
NullSpring(tmps,1.0);
tmps->color=LTGRAY;
tmps->pen_width=2;
break;
case MD_STEEL:
temps->base_const = 1.00*SPRING_SCALE;
temps->base_compression_strength= 1.00*STRENGTH_SCALE;
temps->base_tensile_strength = 1.00*STRENGTH_SCALE;
temps->base_cost = 1.00*COST_SCALE;
NullSpring(temps,1.0);
temps->color=DKGRAY;
temps->pen_width=2;
tmps->base_const = 1.00*SPRING_SCALE;
tmps->base_compression_strength= 1.00*STRENGTH_SCALE;
tmps->base_tensile_strength = 1.00*STRENGTH_SCALE;
tmps->base_cost = 1.00*COST_SCALE;
NullSpring(tmps,1.0);
tmps->color=DKGRAY;
tmps->pen_width=2;
break;
case MD_WIRE:
temps->base_const = 0.25*SPRING_SCALE;
temps->base_compression_strength= 0.00;
temps->base_tensile_strength = 0.50*STRENGTH_SCALE;
temps->base_cost = 0.10*COST_SCALE;
NullSpring(temps,WIRE_PERCENT);
temps->color=RED;
temps->pen_width=1;
temps->flags|=SSF_NO_COMPRESSION;
tmps->base_const = 0.25*SPRING_SCALE;
tmps->base_compression_strength= 0.00;
tmps->base_tensile_strength = 0.50*STRENGTH_SCALE;
tmps->base_cost = 0.10*COST_SCALE;
NullSpring(tmps,WIRE_PERCENT);
tmps->color=RED;
tmps->pen_width=1;
tmps->flags|=SSF_NO_COMPRESSION;
break;
}
QueIns(temps,ode->last_spring);
QueIns(tmps,ode->last_spring);
}
U0 AnimateTask(SpanAnimateStruct *a)
{
MySpring *temps,*temps1;
MySpring *tmps,*tmps1;
Bool old_run=FALSE;
F64 f;
while (TRUE) {
temps=ode->next_spring;
while (temps!=&ode->next_spring) {
temps1=temps->next;
f=temps->f;
if (f>0 && f>temps->compression_strength &&
!(temps->flags&SSF_NO_COMPRESSION)||
f<0 && -f>temps->tensile_strength &&
!(temps->flags&SSF_NO_TENSION))
temps->flags|=SSF_INACTIVE;
temps=temps1;
tmps=ode->next_spring;
while (tmps!=&ode->next_spring) {
tmps1=tmps->next;
f=tmps->f;
if (f>0 && f>tmps->compression_strength &&
!(tmps->flags&SSF_NO_COMPRESSION)||
f<0 && -f>tmps->tensile_strength &&
!(tmps->flags&SSF_NO_TENSION))
tmps->flags|=SSF_INACTIVE;
tmps=tmps1;
}
AdjustLoads(ode);
WinMgrSync; //CMathODE updated once per refresh.
Refresh; //CMathODE updated once per refresh.
if (old_run!=run_button.state) {
if (run_button.state) {
if (!a->elapsed_t || !a->saved_ode) {
@@ -231,7 +231,7 @@ U0 Init(SpanAnimateStruct *a)
ode=SpanNew;
run_button.state=0;
WinMgrSync(2); //Allow stop to reg in animate task.
Refresh(2); //Allow stop to reg in animate task.
if (a->saved_ode)
SpanLoad(ode,a->saved_ode);
@@ -258,8 +258,8 @@ U0 SongTask(I64)
U0 Span()
{
I64 msg_code,a1,a2;
MyMass *tempm1=NULL,*tempm2=NULL;
MySpring *temps;
MyMass *tmpm1=NULL,*tmpm2=NULL;
MySpring *tmps;
CCtrl *bt_run,*bt_mode;
U8 *src;
CDC *dc=DCAlias;
@@ -328,7 +328,7 @@ U0 Span()
DCFill(dc);
switch (msg_code) {
case MSG_IP_L_DOWN:
cursor_mass=tempm1=tempm2=NULL;
cursor_mass=tmpm1=tmpm2=NULL;
switch (mode_button.state) {
case MD_MASS:
PlaceMass(a1,a2);
@@ -336,21 +336,21 @@ U0 Span()
case MD_CONCRETE:
case MD_STEEL:
case MD_WIRE:
tempm1=MassFind(ode,a1,a2);
tmpm1=MassFind(ode,a1,a2);
break;
case MD_MOVE:
if (run_button.state)
cursor_mass=MassFind(ode,a1,a2);
else
if (tempm1=MassFind(ode,a1,a2))
MoveMass(tempm1,a1,a2);
if (tmpm1=MassFind(ode,a1,a2))
MoveMass(tmpm1,a1,a2);
break;
case MD_DELETE:
MassOrSpringFind(ode,&tempm1,&temps,a1,a2);
if (tempm1)
DelMass(tempm1);
if (temps)
DelSpring(temps);
MassOrSpringFind(ode,&tmpm1,&tmps,a1,a2);
if (tmpm1)
DelMass(tmpm1);
if (tmps)
DelSpring(tmps);
break;
}
break;
@@ -359,27 +359,27 @@ U0 Span()
case MD_CONCRETE:
case MD_STEEL:
case MD_WIRE:
if (tempm1 && (tempm2=MassFind(ode,a1,a2)) && tempm1!=tempm2)
PlaceSpring(tempm1,tempm2);
if (tmpm1 && (tmpm2=MassFind(ode,a1,a2)) && tmpm1!=tmpm2)
PlaceSpring(tmpm1,tmpm2);
break;
case MD_MOVE:
if (!run_button.state && tempm1)
MoveMass(tempm1,a1,a2);
if (!run_button.state && tmpm1)
MoveMass(tmpm1,a1,a2);
break;
}
cursor_mass=tempm1=tempm2=NULL;
cursor_mass=tmpm1=tmpm2=NULL;
break;
case MSG_IP_MOVE:
switch (mode_button.state) {
case MD_MOVE:
if (!run_button.state && tempm1)
MoveMass(tempm1,a1,a2);
if (!run_button.state && tmpm1)
MoveMass(tmpm1,a1,a2);
break;
case MD_CONCRETE:
case MD_STEEL:
case MD_WIRE:
if (tempm1) {
DrawSpring(dc,tempm1,a1,a2);
if (tmpm1) {
DrawSpring(dc,tmpm1,a1,a2);
}
break;
}
@@ -388,7 +388,7 @@ U0 Span()
mode_button.state++;
if (mode_button.state>=MD_NUM_MODES)
mode_button.state=0;
cursor_mass=tempm1=tempm2=NULL;
cursor_mass=tmpm1=tmpm2=NULL;
break;
case MSG_KEY_DOWN:
switch (a1) {
+21 -21
View File
@@ -26,8 +26,8 @@ U8 *SpanSave(CMathODE *ode,I64 *_size=NULL)
{
I64 cnt;
U8 *res,*ptr;
MyMass *tempm;
MySpring *temps;
MyMass *tmpm;
MySpring *tmps;
SpanHeader h;
ODERenum(ode);
@@ -47,18 +47,18 @@ U8 *SpanSave(CMathODE *ode,I64 *_size=NULL)
MemCpy(ptr,&h,sizeof(SpanHeader));
ptr+=sizeof(SpanHeader);
tempm=ode->next_mass;
while (tempm!=&ode->next_mass) {
MemCpy(ptr,&tempm->start,M_SIZE);
tmpm=ode->next_mass;
while (tmpm!=&ode->next_mass) {
MemCpy(ptr,&tmpm->start,M_SIZE);
ptr+=M_SIZE;
tempm=tempm->next;
tmpm=tmpm->next;
}
temps=ode->next_spring;
while (temps!=&ode->next_spring) {
MemCpy(ptr,&temps->start,S_SIZE);
tmps=ode->next_spring;
while (tmps!=&ode->next_spring) {
MemCpy(ptr,&tmps->start,S_SIZE);
ptr+=S_SIZE;
temps=temps->next;
tmps=tmps->next;
}
if (_size) *_size=cnt;
return res;
@@ -71,7 +71,7 @@ Bool SpanWrite(CMathODE *ode)
Bool res=FALSE,old_silent=Silent;
MkDir("~/Span");
Silent(old_silent);
if (name=PopUpFileName("~/Span/Game.DAT")) {
if (name=PopUpFileName("~/Span/Game.DATA")) {
if (buf=SpanSave(ode,&size)) {
FileWrite(name,buf,size);
Free(buf);
@@ -85,8 +85,8 @@ Bool SpanWrite(CMathODE *ode)
U0 SpanLoad(CMathODE *ode,U8 *src)
{
I64 i;
MyMass *tempm;
MySpring *temps;
MyMass *tmpm;
MySpring *tmps;
SpanHeader h;
if (!src) return;
@@ -95,19 +95,19 @@ U0 SpanLoad(CMathODE *ode,U8 *src)
src+=sizeof(SpanHeader);
for (i=0;i<h.num_masses;i++) {
tempm=CAlloc(sizeof(MyMass));
MemCpy(&tempm->start,src,M_SIZE);
tmpm=CAlloc(sizeof(MyMass));
MemCpy(&tmpm->start,src,M_SIZE);
src+=M_SIZE;
QueIns(tempm,ode->last_mass);
QueIns(tmpm,ode->last_mass);
}
for (i=0;i<h.num_springs;i++) {
temps=CAlloc(sizeof(MySpring));
MemCpy(&temps->start,src,S_SIZE);
tmps=CAlloc(sizeof(MySpring));
MemCpy(&tmps->start,src,S_SIZE);
src+=S_SIZE;
QueIns(temps,ode->last_spring);
temps->end1=MassFindNum(ode,temps->end1_num);
temps->end2=MassFindNum(ode,temps->end2_num);
QueIns(tmps,ode->last_spring);
tmps->end1=MassFindNum(ode,tmps->end1_num);
tmps->end2=MassFindNum(ode,tmps->end2_num);
}
}
+108 -108
View File
@@ -80,13 +80,13 @@ U0 DrawIt(CTask *,CDC *dc)
{
I64 i;
F64 é,d,x1,y1,x2,y2;
MyMass *tempm;
MySpring *temps;
MyMass *tmpm;
MySpring *tmps;
tempm=ode->next_mass;
if (tempm!=&ode->next_mass) {
task->scroll_x=-tempm->x*zoom+task->pix_width >>1;
task->scroll_y=-tempm->y*zoom+task->pix_height>>1;
tmpm=ode->next_mass;
if (tmpm!=&ode->next_mass) {
task->scroll_x=-tmpm->x*zoom+task->pix_width >>1;
task->scroll_y=-tmpm->y*zoom+task->pix_height>>1;
}
dc->flags|=DCF_TRANSFORMATION;
@@ -117,34 +117,34 @@ U0 DrawIt(CTask *,CDC *dc)
}
}
temps=ode->next_spring;
while (temps!=&ode->next_spring) {
if (temps->type==EMD_SPRING) {
tmps=ode->next_spring;
while (tmps!=&ode->next_spring) {
if (tmps->type==EMD_SPRING) {
dc->color=LTCYAN;
GrLine3(dc,temps->end1->x,temps->end1->y,0,
temps->end2->x,temps->end2->y,0);
} else if (temps->type==EMD_CONNECTOR) {
GrLine3(dc,tmps->end1->x,tmps->end1->y,0,
tmps->end2->x,tmps->end2->y,0);
} else if (tmps->type==EMD_CONNECTOR) {
dc->color=CYAN;
GrLine3(dc,temps->end1->x,temps->end1->y,0,
temps->end2->x,temps->end2->y,0);
GrLine3(dc,tmps->end1->x,tmps->end1->y,0,
tmps->end2->x,tmps->end2->y,0);
}
temps=temps->next;
tmps=tmps->next;
}
dc->color=LTGRAY;
tempm=ode->next_mass;
while (tempm!=&ode->next_mass) {
Sprite3(dc,tempm->x,tempm->y,0,tempm->img);
tempm=tempm->next;
tmpm=ode->next_mass;
while (tmpm!=&ode->next_mass) {
Sprite3(dc,tmpm->x,tmpm->y,0,tmpm->img);
tmpm=tmpm->next;
}
temps=ode->next_spring;
while (temps!=&ode->next_spring) {
x1=temps->end1->x; y1=temps->end1->y;
x2=temps->end2->x; y2=temps->end2->y;
if (temps->type==EMD_THRUSTER) {
tmps=ode->next_spring;
while (tmps!=&ode->next_spring) {
x1=tmps->end1->x; y1=tmps->end1->y;
x2=tmps->end2->x; y2=tmps->end2->y;
if (tmps->type==EMD_THRUSTER) {
é=Arg(x2-x1,y2-y1);
if (Bt(kbd.down_bitmap,action_scan_codes[temps->action_key-'0'])) {
if (Bt(kbd.down_bitmap,action_scan_codes[tmps->action_key-'0'])) {
dc->flags|=DCF_SYMMETRY;
DCSymmetry3Set(dc,x1,y1,256,x1,y1,0,x1-256*Cos(é),y1-256*Sin(é),0);
for (i=0;i<8;i++) {
@@ -167,15 +167,15 @@ U0 DrawIt(CTask *,CDC *dc)
SpriteZ3B(dc,x1,y1,0,$IB,"<3>",BI=3$,é);
if (zoom>0.5) {
dc->color=YELLOW;
GrPutChar3(dc,(x1*7+x2)/8,(y1*7+y2)/8,0,temps->action_key);
GrPutChar3(dc,(x1*7+x2)/8,(y1*7+y2)/8,0,tmps->action_key);
}
} else if (temps->type==EMD_CONNECTOR) {
} else if (tmps->type==EMD_CONNECTOR) {
if (zoom>0.5) {
dc->color=CYAN;
GrPutChar3(dc,(x1*7+x2)/8,(y1*7+y2)/8,0,temps->action_key);
GrPutChar3(dc,(x1*7+x2)/8,(y1*7+y2)/8,0,tmps->action_key);
}
}
temps=temps->next;
tmps=tmps->next;
}
}
@@ -187,103 +187,103 @@ U0 MyDerivative(CMathODE *ode,F64,COrder2D3 *,COrder2D3 *)
//here.
F64 d,dd;
CD3 p;
MyMass *tempm1,*tempm2;
MySpring *temps;
MyMass *tmpm1,*tmpm2;
MySpring *tmps;
tempm1=ode->next_mass;
while (tempm1!=&ode->next_mass) {
tempm2=tempm1->next;
while (tempm2!=&ode->next_mass) {
D3Sub(&p,&tempm2->state->x,&tempm1->state->x);
tmpm1=ode->next_mass;
while (tmpm1!=&ode->next_mass) {
tmpm2=tmpm1->next;
while (tmpm2!=&ode->next_mass) {
D3Sub(&p,&tmpm2->state->x,&tmpm1->state->x);
dd=D3NormSqr(&p);
if (dd<=Sqr(2*RADIUS)) {
d=Sqrt(dd)+0.0001;
dd=10.0*Sqr(Sqr(Sqr(2*RADIUS)-dd));
D3MulEqu(&p,dd/d);
D3AddEqu(&tempm2->DstateDt->DxDt,&p);
D3SubEqu(&tempm1->DstateDt->DxDt,&p);
D3AddEqu(&tmpm2->DstateDt->DxDt,&p);
D3SubEqu(&tmpm1->DstateDt->DxDt,&p);
}
tempm2=tempm2->next;
tmpm2=tmpm2->next;
}
tempm1=tempm1->next;
tmpm1=tmpm1->next;
}
temps=ode->next_spring;
while (temps!=&ode->next_spring) {
if (main_mode_button.state==MMD_PLAY && temps->type==EMD_THRUSTER &&
Bt(kbd.down_bitmap,action_scan_codes[temps->action_key-'0'])) {
D3Sub(&p,&temps->end2->state->x,&temps->end1->state->x);
tmps=ode->next_spring;
while (tmps!=&ode->next_spring) {
if (main_mode_button.state==MMD_PLAY && tmps->type==EMD_THRUSTER &&
Bt(kbd.down_bitmap,action_scan_codes[tmps->action_key-'0'])) {
D3Sub(&p,&tmps->end2->state->x,&tmps->end1->state->x);
D3Unit(&p);
D3MulEqu(&p,2000);
D3AddEqu(&temps->end1->DstateDt->DxDt,&p);
D3AddEqu(&tmps->end1->DstateDt->DxDt,&p);
}
temps=temps->next;
tmps=tmps->next;
}
}
MyMass *PlaceMass(I64 x, I64 y)
{
MyMass *tempm=CAlloc(sizeof(MyMass));
tempm->mass=1.0;
tempm->drag_profile_factor=100.0;
tempm->x=x;
tempm->y=y;
QueIns(tempm,ode->last_mass);
return tempm;
MyMass *tmpm=CAlloc(sizeof(MyMass));
tmpm->mass=1.0;
tmpm->drag_profile_factor=100.0;
tmpm->x=x;
tmpm->y=y;
QueIns(tmpm,ode->last_mass);
return tmpm;
}
MySpring *PlaceSpring(MyMass *tempm1,MyMass *tempm2,I64 type)
MySpring *PlaceSpring(MyMass *tmpm1,MyMass *tmpm2,I64 type)
{
MySpring *temps=CAlloc(sizeof(MySpring));
F64 d=D3Dist(&tempm1->x,&tempm2->x);
temps->end1=tempm1;
temps->end2=tempm2;
temps->rest_len=d;
temps->type=type;
MySpring *tmps=CAlloc(sizeof(MySpring));
F64 d=D3Dist(&tmpm1->x,&tmpm2->x);
tmps->end1=tmpm1;
tmps->end2=tmpm2;
tmps->rest_len=d;
tmps->type=type;
if (type==EMD_THRUSTER)
temps->const=0;
tmps->const=0;
else
temps->const=2500000/Sqr(d);
temps->action_key=next_action_key;
QueIns(temps,ode->last_spring);
return temps;
tmps->const=2500000/Sqr(d);
tmps->action_key=next_action_key;
QueIns(tmps,ode->last_spring);
return tmps;
}
U0 CenterMasses()
{
CD3 p;
MyMass *tempm1,*tempm2;
tempm1=ode->next_mass;
if (tempm1!=&ode->next_mass) {
D3Copy(&p,&tempm1->x);
tempm2=ode->next_mass;
while (tempm2!=&ode->next_mass) {
D3SubEqu(&tempm2->x,&p);
tempm2=tempm2->next;
MyMass *tmpm1,*tmpm2;
tmpm1=ode->next_mass;
if (tmpm1!=&ode->next_mass) {
D3Copy(&p,&tmpm1->x);
tmpm2=ode->next_mass;
while (tmpm2!=&ode->next_mass) {
D3SubEqu(&tmpm2->x,&p);
tmpm2=tmpm2->next;
}
}
}
U0 NullSprings()
{
MySpring *temps=ode->next_spring;
while (temps!=&ode->next_spring) {
temps->rest_len=D3Dist(&temps->end1->x,&temps->end2->x);
temps=temps->next;
MySpring *tmps=ode->next_spring;
while (tmps!=&ode->next_spring) {
tmps->rest_len=D3Dist(&tmps->end1->x,&tmps->end2->x);
tmps=tmps->next;
}
}
U0 BreakConnectors()
{
MySpring *temps=ode->next_spring,*temps1;
while (temps!=&ode->next_spring) {
temps1=temps->next;
if (temps->type==EMD_CONNECTOR &&
Bt(kbd.down_bitmap,action_scan_codes[temps->action_key-'0'])) {
QueRem(temps);
Free(temps);
MySpring *tmps=ode->next_spring,*tmps1;
while (tmps!=&ode->next_spring) {
tmps1=tmps->next;
if (tmps->type==EMD_CONNECTOR &&
Bt(kbd.down_bitmap,action_scan_codes[tmps->action_key-'0'])) {
QueRem(tmps);
Free(tmps);
}
temps=temps1;
tmps=tmps1;
}
}
@@ -396,7 +396,7 @@ U0 PlayShip()
}
break;
}
WinMgrSync;
Refresh;
}
ps_done: //Don't goto out of try
okay=TRUE;
@@ -414,7 +414,7 @@ U0 EditShip()
I64 a1,a2;
F64 wx,wy;
Bool okay;
MyMass *tempm1=NULL,*tempm2=NULL;
MyMass *tmpm1=NULL,*tmpm2=NULL;
CCtrl *bt_edit_mode=CtrlButtonNew(0,5*FONT_HEIGHT+4,80,,EMD_NUM_MODES,
Define("ST_EDIT_MODES"),edit_mode_colors,&edit_mode_button);
ode->flags|=ODEF_PAUSED;
@@ -460,20 +460,20 @@ U0 EditShip()
switch (edit_mode_button.state) {
case EMD_MASS:
S2W(ip.pos.x,ip.pos.y,&wx,&wy);
tempm1=PlaceMass(wx,wy);
if (ode->next_mass==tempm1)
tempm1->img=$IB,"<1>",BI=1$;
tmpm1=PlaceMass(wx,wy);
if (ode->next_mass==tmpm1)
tmpm1->img=$IB,"<1>",BI=1$;
else
tempm1->img=$IB,"<2>",BI=2$;
tempm1=NULL;
tmpm1->img=$IB,"<2>",BI=2$;
tmpm1=NULL;
break;
case EMD_SPRING:
case EMD_CONNECTOR:
case EMD_THRUSTER:
case EMD_MOVE:
S2W(ip.pos.x,ip.pos.y,&wx,&wy);
tempm1=MassFind(ode,wx,wy);
tempm2=NULL;
tmpm1=MassFind(ode,wx,wy);
tmpm2=NULL;
break;
}
break;
@@ -485,19 +485,19 @@ U0 EditShip()
case EMD_CONNECTOR:
case EMD_THRUSTER:
S2W(ip.pos.x,ip.pos.y,&wx,&wy);
if (tempm1 && (tempm2=MassFind(ode,wx,wy)) && tempm1!=tempm2)
PlaceSpring(tempm1,tempm2,edit_mode_button.state);
tempm1=tempm2=NULL;
if (tmpm1 && (tmpm2=MassFind(ode,wx,wy)) && tmpm1!=tmpm2)
PlaceSpring(tmpm1,tmpm2,edit_mode_button.state);
tmpm1=tmpm2=NULL;
break;
case EMD_MOVE:
S2W(ip.pos.x,ip.pos.y,&wx,&wy);
if (tempm1) {
tempm1->x=wx;
tempm1->y=wy;
tempm1->z=0;
if (tmpm1) {
tmpm1->x=wx;
tmpm1->y=wy;
tmpm1->z=0;
NullSprings;
}
tempm1=tempm2=NULL;
tmpm1=tmpm2=NULL;
break;
}
break;
@@ -505,10 +505,10 @@ U0 EditShip()
switch (edit_mode_button.state) {
case EMD_MOVE:
S2W(ip.pos.x,ip.pos.y,&wx,&wy);
if (tempm1) {
tempm1->x=wx;
tempm1->y=wy;
tempm1->z=0;
if (tmpm1) {
tmpm1->x=wx;
tmpm1->y=wy;
tmpm1->z=0;
NullSprings;
}
break;
@@ -578,7 +578,7 @@ U0 EditShip()
}
break;
}
WinMgrSync;
Refresh;
}
es_done: //Don't goto out of try
okay=TRUE;
+48 -48
View File
@@ -1,4 +1,4 @@
#define TIME_FILENAME "~/TimeClock/TimeFile.DAT.Z"
#define TIME_FILENAME "~/TimeClock/TimeFile.DATA.Z"
#define TET_EOF 0
#define TET_PUNCH_IN 1
@@ -16,19 +16,19 @@ U0 TimeFileRead(TimeEntry *header)
{
U8 *buf,*ptr;
I64 type;
TimeEntry *tempt;
TimeEntry *tmpt;
buf=FileRead(TIME_FILENAME);
if (!buf)
buf=CAlloc(1);
QueInit(header);
ptr=buf;
while (type=*ptr++) {
tempt=CAlloc(sizeof(TimeEntry));
tempt->type=type;
tempt->datetime=*ptr(CDate *)++;
tempt->desc=StrNew(ptr);
tmpt=CAlloc(sizeof(TimeEntry));
tmpt->type=type;
tmpt->datetime=*ptr(CDate *)++;
tmpt->desc=StrNew(ptr);
ptr+=StrLen(ptr)+1;
QueIns(tempt,header->last);
QueIns(tmpt,header->last);
}
Free(buf);
}
@@ -36,24 +36,24 @@ U0 TimeFileRead(TimeEntry *header)
U0 TimeFileWrite(TimeEntry *header)
{
U8 *buf,*ptr;
TimeEntry *tempt;
TimeEntry *tmpt;
I64 size=1; //for EOF
tempt=header->next;
while (tempt!=header) {
size+=sizeof(U8)+sizeof(CDate)+StrLen(tempt->desc)+1;
tempt=tempt->next;
tmpt=header->next;
while (tmpt!=header) {
size+=sizeof(U8)+sizeof(CDate)+StrLen(tmpt->desc)+1;
tmpt=tmpt->next;
}
buf=MAlloc(size);
ptr=buf;
tempt=header->next;
while (tempt!=header) {
*ptr++=tempt->type;
*ptr(CDate *)++=tempt->datetime;
StrCpy(ptr,tempt->desc);
ptr+=StrLen(tempt->desc)+1;
tempt=tempt->next;
tmpt=header->next;
while (tmpt!=header) {
*ptr++=tmpt->type;
*ptr(CDate *)++=tmpt->datetime;
StrCpy(ptr,tmpt->desc);
ptr+=StrLen(tmpt->desc)+1;
tmpt=tmpt->next;
}
*ptr=TET_EOF;
FileWrite(TIME_FILENAME,buf,size);
@@ -62,12 +62,12 @@ U0 TimeFileWrite(TimeEntry *header)
U0 TimeEntriesDel(TimeEntry *header)
{
TimeEntry *tempt=header->next,*tempt1;
while (tempt!=header) {
tempt1=tempt->next;
Free(tempt->desc);
Free(tempt);
tempt=tempt1;
TimeEntry *tmpt=header->next,*tmpt1;
while (tmpt!=header) {
tmpt1=tmpt->next;
Free(tmpt->desc);
Free(tmpt);
tmpt=tmpt1;
}
Free(header);
}
@@ -76,12 +76,12 @@ public Bool TimeRep(TimeEntry **_header=NULL)
{
Bool is_in=FALSE,first=TRUE;
I64 week,cur_week=-1,week_total;
TimeEntry *tempt,*header=MAlloc(sizeof(TimeEntry));
TimeEntry *tmpt,*header=MAlloc(sizeof(TimeEntry));
if (_header) *_header=header;
TimeFileRead(header);
tempt=header->next;
while (tempt!=header) {
week=tempt->datetime.date/7; //TODO
tmpt=header->next;
while (tmpt!=header) {
week=tmpt->datetime.date/7; //TODO
if (week!=cur_week) {
if (!first) {
if (is_in)
@@ -92,19 +92,19 @@ public Bool TimeRep(TimeEntry **_header=NULL)
cur_week=week;
week_total=0;
}
if (tempt->type==TET_PUNCH_IN) {
if (tmpt->type==TET_PUNCH_IN) {
"$$RED$$IN ";
if (!is_in)
week_total-=tempt->datetime;
week_total-=tmpt->datetime;
is_in=TRUE;
} else {
"$$RED$$OUT";
if (is_in)
week_total+=tempt->datetime;
week_total+=tmpt->datetime;
is_in=FALSE;
}
" %D %T:$$FG$$\n%s\n",tempt->datetime,tempt->datetime,tempt->desc;
tempt=tempt->next;
" %D %T:$$FG$$\n%s\n",tmpt->datetime,tmpt->datetime,tmpt->desc;
tmpt=tmpt->next;
}
if (is_in)
week_total+=Now;
@@ -116,17 +116,17 @@ public Bool TimeRep(TimeEntry **_header=NULL)
public U0 PunchOut()
{
TimeEntry *tempt,*header;
TimeEntry *tmpt,*header;
if (!TimeRep(&header))
"$$BK,1$$Already Punched-Out$$BK,0$$\n";
else {
tempt=MAlloc(sizeof(TimeEntry));
tempt->type=TET_PUNCH_OUT;
tempt->datetime=Now;
tmpt=MAlloc(sizeof(TimeEntry));
tmpt->type=TET_PUNCH_OUT;
tmpt->datetime=Now;
"\nEnter Description.\nPress <ESC> when done.\n";
if (!(tempt->desc=GetStr(,,GSF_WITH_NEW_LINE)))
tempt->desc=CAlloc(1);
QueIns(tempt,header->last);
if (!(tmpt->desc=GetStr(,,GSF_WITH_NEW_LINE)))
tmpt->desc=CAlloc(1);
QueIns(tmpt,header->last);
TimeFileWrite(header);
}
TimeEntriesDel(header);
@@ -134,17 +134,17 @@ public U0 PunchOut()
public U0 PunchIn()
{
TimeEntry *tempt,*header;
TimeEntry *tmpt,*header;
if (TimeRep(&header))
"$$BK,1$$Already Punched-In$$BK,0$$\n";
else {
tempt=MAlloc(sizeof(TimeEntry));
tempt->type=TET_PUNCH_IN;
tempt->datetime=Now;
tmpt=MAlloc(sizeof(TimeEntry));
tmpt->type=TET_PUNCH_IN;
tmpt->datetime=Now;
"\nEnter Description.\nPress <ESC> when done.\n";
if (!(tempt->desc=GetStr(,,GSF_WITH_NEW_LINE)))
tempt->desc=CAlloc(1);
QueIns(tempt,header->last);
if (!(tmpt->desc=GetStr(,,GSF_WITH_NEW_LINE)))
tmpt->desc=CAlloc(1);
QueIns(tmpt,header->last);
TimeFileWrite(header);
}
TimeEntriesDel(header);
+62 -62
View File
@@ -172,35 +172,35 @@ U0 MPDrawMen(CDC *dc2)
CDC *dc=DCAlias(dc2,task);
I64 i,r[16],lo=Gs->num*MAX_MAN/mp_cnt,hi=(Gs->num+1)*MAX_MAN/mp_cnt,
yy,phase,scroll_y=MAP_HEIGHT-100-100*(tS-t0);
Man *tempm;
U8 *temps,**_temps;
Man *tmpm;
U8 *tmps,**_tmps;
F64 tt,ts=tS;
for (i=lo;i<hi;i++) {
tempm=&m[i];
yy=(tempm->y-scroll_y)&(MAP_HEIGHT-1);
if (-32<=yy<=task->pix_bottom+32 && !tempm->dead) {
tmpm=&m[i];
yy=(tmpm->y-scroll_y)&(MAP_HEIGHT-1);
if (-32<=yy<=task->pix_bottom+32 && !tmpm->dead) {
Mat4x4IdentEqu(r);
Mat4x4RotY(r,tempm->é+ã/2);
Mat4x4RotY(r,tmpm->é+ã/2);
Mat4x4RotX(r,ã/6);
Mat4x4Scale(r,0.3);
if (tempm->best_dd<(2*HACK_DIST)*(2*HACK_DIST)) {//It's neat so times 2.
if (tempm->friendly)
_temps=friendly_hacking_imgs;
if (tmpm->best_dd<(2*HACK_DIST)*(2*HACK_DIST)) {//It's neat so times 2.
if (tmpm->friendly)
_tmps=friendly_hacking_imgs;
else
_temps=enemy_hacking_imgs;
tt=4*Wrap(tempm->phase+20*ts,0)/(2*ã);
_tmps=enemy_hacking_imgs;
tt=4*Wrap(tmpm->phase+20*ts,0)/(2*ã);
} else {
if (tempm->friendly)
_temps=friendly_imgs;
if (tmpm->friendly)
_tmps=friendly_imgs;
else
_temps=enemy_imgs;
tt=4*Wrap(tempm->phase+5*ts,0)/(2*ã);
_tmps=enemy_imgs;
tt=4*Wrap(tmpm->phase+5*ts,0)/(2*ã);
}
phase=tt; tt%=1.0;
temps=SpriteInterpolate(tt,_temps[phase&3],_temps[(phase+1)&3]);
SpriteMat3B(dc,tempm->x,yy,GR_Z_ALL,temps,r);
Free(temps);
tmps=SpriteInterpolate(tt,_tmps[phase&3],_tmps[(phase+1)&3]);
SpriteMat3B(dc,tmpm->x,yy,GR_Z_ALL,tmps,r);
Free(tmps);
}
}
@@ -213,9 +213,9 @@ U0 DrawIt(CTask *task,CDC *dc)
{
I64 i,yy,scroll_y=MAP_HEIGHT-100-100*(tS-t0);
F64 tt,ts=tS;
Man *tempm;
Bullet *tempb;
U8 *temps;
Man *tmpm;
Bullet *tmpb;
U8 *tmps;
for (i=0;i<MAX_LANDSCAPE;i++) {
yy=(ls[i].y-scroll_y)&(MAP_HEIGHT-1);
@@ -229,11 +229,11 @@ U0 DrawIt(CTask *task,CDC *dc)
GR_WIDTH,(finish_line-scroll_y)&(MAP_HEIGHT-1),0);
dc->color=LTRED;
for (i=0,tempb=b;i<MAX_BULLETS;i++,tempb++)
if (!tempb->dead)
GrLine(dc,tempb->x>>32,tempb->y>>32,
(tempb->x+tempb->dx*BULLET_LEN)>>32,
(tempb->y+tempb->dy*BULLET_LEN)>>32);
for (i=0,tmpb=b;i<MAX_BULLETS;i++,tmpb++)
if (!tmpb->dead)
GrLine(dc,tmpb->x>>32,tmpb->y>>32,
(tmpb->x+tmpb->dx*BULLET_LEN)>>32,
(tmpb->y+tmpb->dy*BULLET_LEN)>>32);
DCDepthBufAlloc(dc);
mp_not_done_flags=1<<mp_cnt-1;
@@ -267,36 +267,36 @@ U0 DrawIt(CTask *task,CDC *dc)
U0 CheckCollisions()
{
I64 i,x,y,scroll_y=MAP_HEIGHT-100-100*(tS-t0);
Man *tempm;
Bullet *tempb;
Man *tmpm;
Bullet *tmpb;
CDC *dc2=DCNew(GR_WIDTH,GR_HEIGHT);
dc2->color=LTRED;
for (i=0,tempb=b;i<MAX_BULLETS;i++,tempb++)
if (!tempb->dead)
GrLine(dc2,tempb->x>>32,tempb->y>>32,
(tempb->x+tempb->dx*BULLET_LEN)>>32,
(tempb->y+tempb->dy*BULLET_LEN)>>32);
for (i=0,tmpb=b;i<MAX_BULLETS;i++,tmpb++)
if (!tmpb->dead)
GrLine(dc2,tmpb->x>>32,tmpb->y>>32,
(tmpb->x+tmpb->dx*BULLET_LEN)>>32,
(tmpb->y+tmpb->dy*BULLET_LEN)>>32);
dc2->color =ROP_COLLISION;
dc2->bkcolor=BLACK;
for (i=0,tempm=m;i<MAX_MAN;i++,tempm++) {
if (!tempm->dead) {
x=tempm->x;
y=(tempm->y-scroll_y)&(MAP_HEIGHT-1);
for (i=0,tmpm=m;i<MAX_MAN;i++,tmpm++) {
if (!tmpm->dead) {
x=tmpm->x;
y=(tmpm->y-scroll_y)&(MAP_HEIGHT-1);
if (0<=x<GR_WIDTH && 0<=y<GR_HEIGHT) {
dc2->collision_cnt=0;
GrRect(dc2,x-3,y-9,6,8);
if (dc2->collision_cnt) {
tempm->dead=TRUE;
tempm->corpse_timeout=tS+30.0;
if (tempm->friendly) {
tmpm->dead=TRUE;
tmpm->corpse_timeout=tS+30.0;
if (tmpm->friendly) {
friendly_fire++;
friendly_left--;
} else
enemy_left--;
if (!snd_timeout) {
snd_timeout=tS+0.01;
if (tempm->friendly)
if (tmpm->friendly)
Snd(200);
else
Snd(50);
@@ -311,7 +311,7 @@ U0 CheckCollisions()
U0 Init()
{
I64 i,xx,yy,scroll_y=MAP_HEIGHT-100;
Man *tempm;
Man *tmpm;
snd_timeout=0;
Snd(0);
@@ -337,27 +337,27 @@ U0 Init()
ls[2].img=landscape_imgs[LANDSCAPE_TYPES-1]; //castle
MemSet(m,0,sizeof(m));
for (i=0,tempm=m;i<MAX_MAN;i++,tempm++) {
for (i=0,tmpm=m;i<MAX_MAN;i++,tmpm++) {
if (i<MAX_FRIENDLY) {
tempm->friendly=TRUE;
tmpm->friendly=TRUE;
if (!(i&7)) {
xx=(Fs->pix_width-200)*RandU32/MAX_U32;
yy=(MAP_HEIGHT-200)*RandU32/MAX_U32;
}
} else {
tempm->friendly=FALSE;
tmpm->friendly=FALSE;
if (!(i&31)) {
xx=(Fs->pix_width-200)*RandU32/MAX_U32;
yy=(MAP_HEIGHT-200)*RandU32/MAX_U32;
}
}
tempm->dead=FALSE;
tempm->x=xx+64*RandI32/MAX_I32+100;
tempm->y=yy+64*RandU32/MAX_I32-64+100;
tempm->best_dd=MAX_I64;
tempm->é=0;
tempm->phase=2*ã*Rand;
tempm->corpse_timeout=0;
tmpm->dead=FALSE;
tmpm->x=xx+64*RandI32/MAX_I32+100;
tmpm->y=yy+64*RandU32/MAX_I32-64+100;
tmpm->best_dd=MAX_I64;
tmpm->é=0;
tmpm->phase=2*ã*Rand;
tmpm->corpse_timeout=0;
}
for (i=0;i<MAX_BULLETS;i++)
b[i].dead=TRUE;
@@ -374,25 +374,25 @@ U0 FireBullet()
{
I64 i,j;
F64 a;
Bullet *tempb;
Bullet *tmpb;
for (i=0;i<MAX_BULLETS-1;i++)
if (b[i].dead)
break;
tempb=&b[i];
tmpb=&b[i];
j=x+24.0*Sin(é);
tempb->x=j<<32;
tmpb->x=j<<32;
j=y-24.0*Cos(é);
tempb->y=j<<32;
tmpb->y=j<<32;
tempb->dx2=(BULLET_SPEED*Sin(é)+dx)*0x100000000;
tempb->dy2=-BULLET_SPEED*Cos(é)*0x100000000;
a=Arg(tempb->dx2,tempb->dy2);
tempb->dx=Cos(a)*0x100000000;
tempb->dy=Sin(a)*0x100000000;
tmpb->dx2=(BULLET_SPEED*Sin(é)+dx)*0x100000000;
tmpb->dy2=-BULLET_SPEED*Cos(é)*0x100000000;
a=Arg(tmpb->dx2,tmpb->dy2);
tmpb->dx=Cos(a)*0x100000000;
tmpb->dy=Sin(a)*0x100000000;
bullets_fired++;
tempb->dead=FALSE;
tmpb->dead=FALSE;
if (!snd_timeout) {
snd_timeout=tS+0.0005;
Snd(1000);
+76 -70
View File
@@ -1,158 +1,164 @@
U0 TanksPlot()
U0 PlayerIndirect()
{
Unit *tempu=NULL;
I64 msg_code,a1,a2;
Unit *tmpu=NULL;
I64 i,remaining=0,msg_code,a1,a2;
F64 target_x,target_y;
SetViewPlayer(cur_player);
while (TRUE) {
ViewPlayerSet(cur_player);
for (i=0;i<MAX_UNITS;i++) {
tmpu=&units[cur_player][i];
if (tmpu->life>0 && tmpu->indirect_fire)
remaining++;
}
while (remaining) {
if (!alive_cnt[0] || !alive_cnt[1])
throw('GameOver',TRUE);
msg_code=GetMsg(&a1,&a2,1<<MSG_KEY_DOWN|
1<<MSG_IP_L_DOWN|1<<MSG_IP_L_UP|
msg_code=GetMsg(&a1,&a2,1<<MSG_KEY_DOWN|1<<MSG_IP_L_DOWN|1<<MSG_IP_L_UP|
1<<MSG_IP_R_UP);
switch (msg_code) {
case MSG_KEY_DOWN:
HandleChar(a1);
CharDo(a1);
break;
case MSG_IP_L_DOWN:
if (CursorInWindow(Fs,a1,a2)) {
UpdateCursor(Fs,a1,a2);
if (tempu=FindUnit(cursor_row,cursor_col)) {
if (tempu->player==enemy_player || tempu->fired ||
!tempu->indirect_fire)
tempu=NULL;
if (CursorInWin(Fs,a1,a2)) {
a1-=x0; a2-=y0;
CursorUpdate(Fs,a1,a2);
if (tmpu=UnitFind(cursor_row,cursor_col)) {
if (tmpu->player==enemy_player || tmpu->fired ||
!tmpu->indirect_fire)
tmpu=NULL;
else {
RowCol2XY(&fire_radius_x,&fire_radius_y,tempu->row,tempu->col);
fire_radius=tempu->range*2*HEX_RADIUS;
RowCol2XY(&fire_radius_x,&fire_radius_y,tmpu->row,tmpu->col);
fire_radius=tmpu->range*2*HEX_RADIUS;
}
}
}
break;
case MSG_IP_L_UP:
if (CursorInWindow(Fs,a1,a2)) {
UpdateCursor(Fs,a1,a2);
if (CursorInWin(Fs,a1,a2)) {
a1-=x0; a2-=y0;
CursorUpdate(Fs,a1,a2);
RowCol2XY(&target_x,&target_y,cursor_row,cursor_col);
if (!tempu)
if (!tmpu)
Beep;
else {
if (Sqrt(Sqr(fire_radius_x-target_x)+Sqr(fire_radius_y-target_y))>
fire_radius)
Beep;
else
PlotShot(tempu,cursor_row,cursor_col);
else {
IndirectAdd(tmpu,cursor_row,cursor_col);
remaining--;
}
}
}
tempu=NULL;
tmpu=NULL;
fire_radius=0;
break;
case MSG_IP_R_UP:
if (CursorInWindow(Fs,a1,a2))
if (CursorInWin(Fs,a1,a2))
throw('PhaseOvr',TRUE);
break;
}
}
throw('PhaseOvr',TRUE);
}
U0 TanksMove()
U0 PlayerMove()
{
Unit *tempu=NULL,*target;
Unit *tmpu=NULL;
I64 msg_code,a1,a2;
SetViewPlayer(cur_player);
ViewPlayerSet(cur_player);
while (TRUE) {
if (!alive_cnt[0] || !alive_cnt[1])
throw('GameOver',TRUE);
msg_code=GetMsg(&a1,&a2,1<<MSG_KEY_DOWN|
1<<MSG_IP_L_DOWN|1<<MSG_IP_L_UP|
msg_code=GetMsg(&a1,&a2,1<<MSG_KEY_DOWN|1<<MSG_IP_L_DOWN|1<<MSG_IP_L_UP|
1<<MSG_IP_R_UP);
switch (msg_code) {
case MSG_KEY_DOWN:
HandleChar(a1);
CharDo(a1);
break;
case MSG_IP_L_DOWN:
if (CursorInWindow(Fs,a1,a2)) {
UpdateCursor(Fs,a1,a2);
if (tempu=FindUnit(cursor_row,cursor_col)) {
if (tempu->player==enemy_player || !tempu->remaining_movement)
tempu=NULL;
if (CursorInWin(Fs,a1,a2)) {
a1-=x0; a2-=y0;
CursorUpdate(Fs,a1,a2);
if (tmpu=UnitFind(cursor_row,cursor_col)) {
if (tmpu->player==enemy_player || !tmpu->remaining_movement)
tmpu=NULL;
}
}
break;
case MSG_IP_L_UP:
if (CursorInWindow(Fs,a1,a2)) {
UpdateCursor(Fs,a1,a2);
target=FindUnit(cursor_row,cursor_col);
if (!tempu)
if (CursorInWin(Fs,a1,a2)) {
a1-=x0; a2-=y0;
CursorUpdate(Fs,a1,a2);
if (!tmpu)
Beep;
else {
if (target)
Beep;
else
MoveUnit(tempu,a1+Fs->horz_scroll.pos,
a2+Fs->vert_scroll.pos);
UnitMove(tmpu,a1,a2);
break;
}
}
tempu=NULL;
tmpu=NULL;
break;
case MSG_IP_R_UP:
if (CursorInWindow(Fs,a1,a2))
if (CursorInWin(Fs,a1,a2))
throw('PhaseOvr',TRUE);
break;
}
}
}
U0 TanksFire()
U0 PlayerDirect()
{
Unit *tempu=NULL,*target;
Unit *tmpu=NULL,*target;
I64 msg_code,a1,a2;
SetViewPlayer(cur_player);
ViewPlayerSet(cur_player);
while (TRUE) {
if (!alive_cnt[0] || !alive_cnt[1])
throw('GameOver',TRUE);
msg_code=GetMsg(&a1,&a2,1<<MSG_KEY_DOWN|
1<<MSG_IP_L_DOWN|1<<MSG_IP_L_UP|
msg_code=GetMsg(&a1,&a2,1<<MSG_KEY_DOWN|1<<MSG_IP_L_DOWN|1<<MSG_IP_L_UP|
1<<MSG_IP_R_UP);
switch (msg_code) {
case MSG_KEY_DOWN:
HandleChar(a1);
CharDo(a1);
break;
case MSG_IP_L_DOWN:
if (CursorInWindow(Fs,a1,a2)) {
UpdateCursor(Fs,a1,a2);
if (tempu=FindUnit(cursor_row,cursor_col)) {
if (tempu->player==enemy_player || tempu->fired ||
tempu->indirect_fire)
tempu=NULL;
if (CursorInWin(Fs,a1,a2)) {
a1-=x0; a2-=y0;
CursorUpdate(Fs,a1,a2);
if (tmpu=UnitFind(cursor_row,cursor_col)) {
if (tmpu->player==enemy_player || tmpu->fired ||
tmpu->indirect_fire)
tmpu=NULL;
else {
RVSetUp(cur_player);
RowCol2XY(&fire_radius_x,&fire_radius_y,tempu->row,tempu->col);
fire_radius=tempu->range*2*HEX_RADIUS;
RecalcVisible(RV_ONE_FRIENDLY_UNIT,tempu);
VRSetUp(cur_player);
RowCol2XY(&fire_radius_x,&fire_radius_y,tmpu->row,tmpu->col);
fire_radius=tmpu->range*2*HEX_RADIUS;
VisRecalc(VR_ONE_FRIENDLY_UNIT,tmpu);
}
}
}
break;
case MSG_IP_L_UP:
if (CursorInWindow(Fs,a1,a2)) {
UpdateCursor(Fs,a1,a2);
target=FindUnit(cursor_row,cursor_col);
if (!tempu)
if (CursorInWin(Fs,a1,a2)) {
a1-=x0; a2-=y0;
CursorUpdate(Fs,a1,a2);
target=UnitFind(cursor_row,cursor_col);
if (!tmpu)
Beep;
else {
if (!target || target->player!=enemy_player ||
!Bt(&target->visible,0))
!Bt(&target->vis,0))
Beep;
else
FireShot(tempu,target);
RecalcVisible(RV_UPDATE_FRIENDLY_UNIT,tempu);
UnitDirectFire(tmpu,target);
VisRecalc(VR_UPDATE_FRIENDLY_UNIT,tmpu);
}
}
tempu=NULL;
tmpu=NULL;
fire_radius=0;
break;
case MSG_IP_R_UP:
if (CursorInWindow(Fs,a1,a2))
if (CursorInWin(Fs,a1,a2))
throw('PhaseOvr',TRUE);
break;
}
+27 -27
View File
@@ -1,4 +1,4 @@
Unit *FindNearestUnit(I64 row,I64 col,I64 player,Bool in_LOS,F64 range=-1)
Unit *UnitNearestFind(I64 row,I64 col,I64 player,Bool in_LOS,F64 range=-1)
{
I64 i;
F64 dd,best_dd=MAX_F64,x1,y1,x2,y2;
@@ -23,36 +23,36 @@ Unit *FindNearestUnit(I64 row,I64 col,I64 player,Bool in_LOS,F64 range=-1)
return best;
}
U0 TanksPlot()
U0 PlayerIndirect()
{
Unit *target,*tempu;
Unit *target,*tmpu;
I64 i;
for (i=0;i<MAX_UNITS;i++) {
CheckUser;
tempu=&units[cur_player][i];
if (tempu->life>0 && tempu->indirect_fire &&
(target=FindNearestUnit(tempu->row,tempu->col,enemy_player,TRUE,
tempu->range*2*HEX_RADIUS)))
PlotShot(tempu,target->row,target->col);
UserChk;
tmpu=&units[cur_player][i];
if (tmpu->life>0 && tmpu->indirect_fire &&
(target=UnitNearestFind(tmpu->row,tmpu->col,enemy_player,TRUE,
tmpu->range*2*HEX_RADIUS)))
IndirectAdd(tmpu,target->row,target->col);
}
throw('PhaseOvr',TRUE);
}
U0 TanksMove()
U0 PlayerMove()
{
Unit *target,*tempu;
Unit *target,*tmpu;
I64 i;
F64 x,y;
for (i=0;i<MAX_UNITS;i++) {
CheckUser;
tempu=&units[cur_player][i];
if (tempu->life>0) {
UserChk;
tmpu=&units[cur_player][i];
if (tmpu->life>0) {
//Cheats because it violates Line-of-Sight
if (target=FindNearestUnit(tempu->row,tempu->col,enemy_player,FALSE)) {
if (target=UnitNearestFind(tmpu->row,tmpu->col,enemy_player,FALSE)) {
RowCol2XY(&x,&y,target->row,target->col);
if (!MoveUnit(tempu,x,y)) {
RowCol2XY(&x,&y,tempu->row,tempu->col);
MoveUnit(tempu,x+RandI16,y+RandI16);
if (!UnitMove(tmpu,x,y)) {
RowCol2XY(&x,&y,tmpu->row,tmpu->col);
UnitMove(tmpu,x+RandI16,y+RandI16);
}
}
}
@@ -60,18 +60,18 @@ U0 TanksMove()
throw('PhaseOvr',TRUE);
}
U0 TanksFire()
U0 PlayerDirect()
{
Unit *target,*tempu;
Unit *target,*tmpu;
I64 i;
for (i=0;i<MAX_UNITS;i++) {
CheckUser;
tempu=&units[cur_player][i];
if (tempu->life>0 && !tempu->indirect_fire &&
(target=FindNearestUnit(tempu->row,tempu->col,enemy_player,TRUE,
tempu->range*2*HEX_RADIUS))) {
FireShot(tempu,target);
Sleep(250*ANIMATION_DELAY);
UserChk;
tmpu=&units[cur_player][i];
if (tmpu->life>0 && !tmpu->indirect_fire &&
(target=UnitNearestFind(tmpu->row,tmpu->col,enemy_player,TRUE,
tmpu->range*2*HEX_RADIUS))) {
UnitDirectFire(tmpu,target);
Sleep(250*animation_delay);
}
}
throw('PhaseOvr',TRUE);
+7
View File
@@ -1,6 +1,13 @@
#help_index "Games"
Cd(__DIR__);;
#include "TTFGlbls"
#include "TTFLib"
#include "TTFInit"
#include "TTFVis"
#include "TTFFire"
#include "TTFMove"
#include "TTFDraw"
#include "ToTheFront"
#help_index ""
Binary file not shown.
+278
View File
@@ -0,0 +1,278 @@
U0 AttackHeader(Unit *tmpu,U8 *st,Unit *target)
{
I64 i=9+StrLen(st);
if (target) {
i+=9;
if (target->armor)
i+=8;
else
i+=10;
}
'\n\n';
"$$BLACK$$%h*c$$FG$$\n",i,'-';
if (tmpu->player)
"$$PURPLE$$Player 2$$FG$$ ";
else
"$$CYAN$$Player 1$$FG$$ ";
"%s",st;
if (target) {
if (target->player)
" $$PURPLE$$Player 2";
else
" $$CYAN$$Player 1";
if (target->armor)
" Armored";
else
" Unarmored";
'$$FG$$';
}
'\n';
"$$BLACK$$%h*c$$FG$$\n",i,'-';
}
F64 HitDamage(Unit *tmpu,Unit *target,I64 facing=1,F64 range_factor=0)
{
F64 d,res=200.0*Rand;
"\nRoll Out of 200\t\t:%6.2f Damage\n",res;
if (target->armor) {
d=target->armor/100.0*(5-facing)/5.0;
if (d>=0) {
"Armor Attack\t\t:%6.2f\n",ToF64(tmpu->armored_attack);
res*=(tmpu->armored_attack/100.0)/d;
} else
res=0;
"Armor(%z) Defense\t:%6.2f\n",facing,
"Front\0FrontSide\0RearSide\0Rear\0",100*d;
} else {
d=1.0-range_factor;
if (d>0) {
"Unarmored Attack\t:%6.2f\n",ToF64(tmpu->unarmored_attack);
"Range Adjust\t\t:%6.2f%%\n",100*d;
res*=(tmpu->unarmored_attack/100.0)*d;
} else
res=0;
}
"Attack/Defense Adjusted\t:%6.2f Damage\n",res;
return Round(res);
}
Bool DamageDo(Unit *target,F64 damage)
{
if (damage>0) {
if (target->armor)
"Armor Hit Score %6.2f\t:",damage;
else
"%3d Life - %3f Damage\t=",target->life,damage;
if (damage>=target->life) {
"$$RED$$Killed$$FG$$\n";
Noise(1000*animation_delay,1000,4000);
Sleep(1000*animation_delay);
target->life=0;
VisRecalc(VR_FRIENDLY_UNIT_DIED,target);
alive_cnt[target->player]--;
return TRUE;
} else {
if (target->armor) {
if (damage>0.6*target->life) {
target->movement=0;
"$$RED$$Immobilized$$FG$$\n";
} else
"$$GREEN$$No Penetration$$FG$$\n";
} else {
target->life-=damage;
"$$RED$$%6.2f Life$$FG$$\n",ToF64(target->life);
}
return FALSE;
}
} else
return FALSE;
}
U0 IndirectAdd(Unit *tmpu,I64 row,I64 col)
{
IndirectOrders *tmpi;
if (tmpu->life<=0 || tmpu->range<=0)
return;
tmpu->fired=TRUE;
tmpi=CAlloc(sizeof(IndirectOrders));
tmpi->attacker=tmpu;
tmpi->row=row;
tmpi->col=col;
QueIns(tmpi,indirect_head.last);
}
Bool BulletPlot(U0,I64 x,I64 y,I64)
{
fire_x=x; fire_y=y;
firing=TRUE;
Sleep(3*animation_delay);
return TRUE;
}
U0 UnitDirectFire(Unit *tmpu,Unit *target)
{
I64 r,c,facing,
t1=terrain[tmpu->row][tmpu->col],t2=terrain[target->row][target->col];
F64 x1,y1,x2,y2,d,a,range_factor;
if (tmpu->life<=0 || target->life<=0 || tmpu->range<=0)
return;
AttackHeader(tmpu,"DirectFire",target);
RowCol2XY(&x1,&y1,tmpu->row,tmpu->col);
RowCol2XY(&x2,&y2,target->row,target->col);
d=100*Rand;
"+%5.2f Roll\n",d;
d+=tmpu->accuracy;
"+%2d.00 Accuracy\n",tmpu->accuracy;
range_factor=Sqrt(Sqr(x2-x1)+Sqr(y2-y1))/(tmpu->range*2*DSIN);
"-%5.2f%% of Range\n",100*range_factor;
d-=100*range_factor;
if (t2==TREES) {
"-30.00 Target in Trees Penalty\n";
d-=30;
}
if (t1==MOUNTAINS && t2!=MOUNTAINS) {
"+30.00 High Ground Bonus\n";
d+=30;
}
"_______\n";
target_unit=target;
if (d>=0) {
"+%5.2f Hit\n",d;
target_hit=TRUE;
Noise(500*animation_delay,100,150);
Sleep(500*animation_delay);
Line(NULL,x1,y1,0,x2,y2,0,&BulletPlot);
} else {
"-%5.2f Miss\n",-d;
target_hit=FALSE;
Noise(1000*animation_delay,750,1000);
Sleep(1000*animation_delay);
a=ã*2*Rand;
d=(0.5-d/100)*HEX_SIDE;
Line(NULL,x1,y1,0,x2+d*Cos(a),y2+d*Sin(a),0,&BulletPlot);
}
firing=FALSE;
tmpu->fired=TRUE;
if (target_hit) {
r=target->row;c=target->col;
if ((facing=HexMoveOne(&r,&c,x1,y1))>=0)
facing=FacingChg(facing,target->facing);
else
facing=0;
DamageDo(target,HitDamage(tmpu,target,facing,range_factor));
}
while (snd.freq) //see $LK,"Snd",A="MN:Snd"$()
Yield;
target_unit=NULL;
}
Bool HexOccupy(Bool overrun,Unit *tmpu,Unit *target)
{
I64 t2=terrain[target->row][target->col];
F64 damage;
if (tmpu->life<=0 || target->life<=0)
return FALSE;
if (overrun)
AttackHeader(tmpu,"OverRun",target);
else
AttackHeader(tmpu,"CloseAssault",target);
Noise(500*animation_delay,100,150);
Sleep(500*animation_delay);
tmpu->fired=TRUE;
target->fired=TRUE;
damage=HitDamage(tmpu,target);
if (overrun) {
damage*=2.0;
"x2 OverRun Bonus\t=%6.2f Damage\n",damage;
if (t2!=PLAINS) {
damage/=2.0;
"/2 Terrain Penalty\t=%6.2f Damage\n",damage;
}
} else {
damage*=3.0;
"x3 CloseAssault Bonus\t=%6.2f Damage\n",damage;
}
if (DamageDo(target,Round(damage))) {
"$$RED$$Success$$FG$$\n";
while (snd.freq) //see $LK,"Snd",A="MN:Snd"$()
Yield;
return TRUE;
} else {
tmpu->life=0;
VisRecalc(VR_FRIENDLY_UNIT_DIED,tmpu);
alive_cnt[tmpu->player]--;
"$$RED$$Failure$$FG$$\n";
while (snd.freq) //see $LK,"Snd",A="MN:Snd"$()
Yield;
return FALSE;
}
}
U0 IndirectResolveAll()
{
I64 i,r,c;
F64 x1,y1,x2,y2,d,range_factor;
Unit *tmpu,*target;
IndirectOrders *tmpi=indirect_head.next,*tmpi1;
while (tmpi!=*indirect_head) {
tmpi1=tmpi->next;
tmpu=tmpi->attacker;
AttackHeader(tmpu,"IndirectFire",NULL);
RowCol2XY(&x1,&y1,tmpu->row,tmpu->col);
RowCol2XY(&x2,&y2,tmpi->row,tmpi->col);
d=100*Rand;
"+%5.2f Roll\n",d;
d+=tmpu->accuracy;
"+%2d.00 Accuracy\n",tmpu->accuracy;
range_factor=Sqrt(Sqr(x2-x1)+Sqr(y2-y1))/(tmpu->range*2*DSIN);
"-%5.2f%% of Range\n",100*range_factor;
d-=100*range_factor;
'_______\n';
if (d>=0) {
"+%5.2f Hit\n",d;
Noise(500*animation_delay,100,150);
Sleep(500*animation_delay);
} else {
"-%5.2f Miss\n",-d;
Noise(1000*animation_delay,750,1000);
Sleep(1000*animation_delay);
i=RandU16%6;
if (tmpi->row&1)
tmpi->col+=col_offsets_odd[i];
else
tmpi->col+=col_offsets_even[i];
tmpi->row+=row_offsets[i];
RowCol2XY(&x2,&y2,tmpi->row,tmpi->col);
}
Line(NULL,x1,y1,0,x2,y2,0,&BulletPlot);
firing=FALSE;
tmpu->fired=TRUE;
indirect_row=tmpi->row;
indirect_col=tmpi->col;
indirect_explosion=TRUE;
for (i=0;i<7;i++) {
if (tmpi->row&1)
c=tmpi->col+col_offsets_odd[i];
else
c=tmpi->col+col_offsets_even[i];
r=tmpi->row+row_offsets[i];
if (0<=r<map_rows && 0<=c<map_cols && (target=UnitFind(r,c))) {
AttackHeader(tmpu,"IndirectFire",target);
DamageDo(target,HitDamage(tmpu,target));
}
}
Noise(2000*animation_delay,800,1000);
Sleep(2000*animation_delay);
while (snd.freq) //see $LK,"Snd",A="MN:Snd"$()
Yield;
indirect_explosion=FALSE;
QueRem(tmpi);
Free(tmpi);
tmpi=tmpi1;
}
}
+108
View File
@@ -0,0 +1,108 @@
#define MAP_WIDTH 640 //Change this, if you like.
#define MAX_UNITS 32 //Change this, if you like.
#define HEX_SIDE 11
U0 InitDefines()
{
DefinePrint("MAP_HEIGHT","%d",(GR_HEIGHT-FONT_HEIGHT*2)*MAP_WIDTH/GR_WIDTH);
DefinePrint("DCOS", "%12.9f", HEX_SIDE*Cos(60.0/180*ã));
DefinePrint("DSIN", "%12.9f", HEX_SIDE*Sin(60.0/180*ã));
DefinePrint("HEX_RADIUS","%12.9f", HEX_SIDE*Sin(60.0/180*ã)+0.01); //Slop
} InitDefines;
I64 map_cols=(MAP_WIDTH-DCOS)/(2*HEX_SIDE+2*DCOS),
map_rows=ToI64((MAP_HEIGHT-DSIN)/DSIN)&~1,
map_width=map_cols*(2*HEX_SIDE+2*DCOS)+DCOS,
map_height=map_rows*DSIN+DSIN+1,
x0,y0;
CDC *map_dc;
U8 terrain[map_rows][map_cols];
//Centers of hexes
class Pt
{
F64 x,y;
};
Pt hex_centers[map_rows][map_cols];
I64 show_vis_row,show_vis_col;
Bool roads[map_rows][map_cols],
rivers[map_rows][map_cols],
vis_map[map_rows][map_cols];
//Other options for PLAINS are WHITE or YELLOW
#define PLAINS LTGREEN
#define TREES GREEN
#define MOUNTAINS DKGRAY
//These are used to display a range circle when they player
//is firing.
F64 fire_radius,fire_radius_x,fire_radius_y;
//These display "phase", "turn" and "game over".
U8 msg_buf[STR_LEN];
I64 msg_off_timeout; //Jiffies. Goes away after a time.
//Unit types
#define UT_INFANTRY 0
#define UT_ARTILLERY 1
#define UT_LT_TANK 2
#define UT_MD_TANK 3
class Unit
{
U8 *img;
I64 num,row,col,
armored_attack,unarmored_attack,armor;
I8 type,player,facing,movement,life,
range,remaining_movement,accuracy;
Bool vis[2],fired,infantry,indirect_fire,pad[3];
};
Unit units[2][MAX_UNITS];
// Bt(vis_unit_bitmap,player1+player0*((MAX_UNITS+7)&~7))
U8 vis_unit_bitmap[2][(((MAX_UNITS+7)&~7)*MAX_UNITS)>>3];
#define PHASE_START 0
#define PHASE_INDIRECT 0
#define PHASE_INDIRECT0 0
#define PHASE_INDIRECT1 1
#define PHASE_MOVE 2
#define PHASE_MOVE0 2
#define PHASE_MOVE1 3
#define PHASE_DIRECT 4
#define PHASE_DIRECT0 4
#define PHASE_DIRECT1 5
#define PHASE_END 6
I64 phase,cur_player,enemy_player,view_player,turn,
cursor_row,cursor_col,alive_cnt[2],
player_indirect[2],player_move[2],player_direct[2];
F64 animation_delay=0.5;
Bool moving=FALSE;
I64 move_x,move_y;
F64 move_facing;
Unit *moving_unit;
extern I64 HexMoveOne(I64 *_row,I64 *_col,F64 x,F64 y);
class IndirectOrders
{
IndirectOrders *next,*last;
Unit *attacker;
I64 row,col;
} indirect_head;
Bool firing=FALSE;
I64 fire_x,fire_y;
Unit *target_unit;
Bool target_hit;
Bool indirect_explosion=FALSE;
I64 indirect_row,indirect_col;
I64 row_offsets[7]={-1,-2,-1,1,2,1,0};
I64 col_offsets_even[7]={-1, 0, 0,0,0,-1,0};
I64 col_offsets_odd [7]={ 0, 0, 1,1,0, 0,0};
+436
View File
@@ -0,0 +1,436 @@
/*I got tricky by not defining a color
right away in these $LK,"CSprite",A="MN:CSprite"$s so they can
work for both players by setting dc->color
before drawing them. I actually made these
graphics by defining a color in the <CTRL-r>
menu, drawing the unit and deleting the color.
I had to leave a gap between the tank tread
and body because of how it is rendered when rotated.
*/
$SP,"<1>",BI=1$
$SP,"<2>",BI=2$
//This is an infantry.
$SP,"<3>",BI=3$
$SP,"<4>",BI=4$
U0 DrawHexes()
{
F64 dx=2*HEX_SIDE+2*DCOS,dy=2*DSIN,
x,y,x1,y1,x2,y2;
I64 i,j;
map_dc->color=WHITE;
GrRect(map_dc,0,0,map_dc->width,map_dc->height);
map_dc->color=BLACK;
y=0;
for (j=0;j<map_rows;j+=2) {
x=DCOS;
GrLine(map_dc,x,y,x-DCOS,y+DSIN);
GrLine(map_dc,x-DCOS,y+DSIN,x,y+2*DSIN);
for (i=0;i<map_cols;i++) {
x1=x; y1=y;
x2=x1+HEX_SIDE; y2=y1;
GrLine(map_dc,x1,y1,x2,y2);
x1=x2; y1=y2;
x2+=DCOS; y2+=DSIN;
GrLine(map_dc,x1,y1,x2,y2);
GrLine(map_dc,x2,y2,x2-DCOS,y2+DSIN);
x1=x2; y1=y2;
x2+=HEX_SIDE;
GrLine(map_dc,x1,y1,x2,y2);
GrLine(map_dc,x2,y2,x2+DCOS,y2+DSIN);
x1=x2; y1=y2;
x2+=DCOS; y2-=DSIN;
if (j || i<map_cols-1)
GrLine(map_dc,x1,y1,x2,y2);
x+=dx;
}
y+=dy;
}
x=DCOS;
for (i=0;i<map_cols;i++) {
x1=x; y1=y;
x2=x1+HEX_SIDE; y2=y1;
GrLine(map_dc,x1,y1,x2,y2);
x1=x2; y1=y2;
x2+=DCOS; y2+=DSIN;
GrLine(map_dc,x1,y1,x2,y2);
x1=x2; y1=y2;
x2+=HEX_SIDE;
GrLine(map_dc,x1,y1,x2,y2);
x1=x2; y1=y2;
x2+=DCOS; y2-=DSIN;
GrLine(map_dc,x1,y1,x2,y2);
x+=dx;
}
}
U0 MakeTerrain(U8 color,I64 cnt,I64 cluster_lo,I64 cluster_hi)
{
I64 i,j,l,row,col;
for (i=0;i<cnt;i++) {
col=RandU32%map_cols;
row=RandU32%map_rows;
l=cluster_lo+RandU16%(cluster_hi-cluster_lo+1);
for (j=0;j<l;j++) {
terrain[row][col]=color;
Toward(&row,&col,RandU16%6);
col=ClampI64(col,0,map_cols-1);
row=ClampI64(row,0,map_rows-1);
}
}
}
U0 MakeRivers()
{
I64 i,row,col,direction;
for (i=0;i<4;i++) {
row=RandU32%map_rows;
col=RandU32%map_cols;
direction=RandU16%6;
while (TRUE) {
rivers[row][col]=TRUE;
Toward(&row,&col,direction);
if (!(0<=row<map_rows && 0<=col<map_cols))
break;
if (!(RandU16&3))
direction=(direction+(7-RandU16%3))%6;
}
}
}
U0 MakeRoads()
{
I64 i,row,col,direction;
for (i=0;i<5;i++) {
row=RandU32%map_rows;
col=RandU32%map_cols;
direction=RandU16%6;
while (TRUE) {
roads[row][col]=TRUE;
Toward(&row,&col,direction);
if (!(0<=row<map_rows && 0<=col<map_cols))
break;
if (!(RandU16%3))
direction=(direction+(7-RandU16%3))%6;
}
}
}
U0 DrawTerrain()
{
I64 i,j;
F64 x,y;
for (j=0;j<map_rows;j++)
for (i=0;i<map_cols;i++) {
map_dc->color=terrain[j][i];
RowCol2XY(&x,&y,j,i);
GrFloodFill(map_dc,x,y);
}
}
U0 DrawRivers()
{
I64 i,j,k,r,c;
F64 x1,y1,x2,y2;
for (j=0;j<map_rows;j++)
for (i=0;i<map_cols;i++) {
if (rivers[j][i]) {
RowCol2XY(&x1,&y1,j,i);
for (k=0;k<6;k++) {
r=j;c=i;
Toward(&r,&c,k);
if (0<=r<map_rows && 0<=c<map_cols &&
rivers[r][c]) {
RowCol2XY(&x2,&y2,r,c);
map_dc->color=LTBLUE;
map_dc->pen_width=4;
GrLine3(map_dc,x1,y1,0,x2,y2,0);
map_dc->color=BLUE;
map_dc->pen_width=2;
GrLine3(map_dc,x1,y1,0,x2,y2,0);
}
}
}
}
}
U0 DrawRoads()
{
I64 i,j,k,r,c;
F64 x1,y1,x2,y2;
map_dc->color=RED;
map_dc->pen_width=3;
for (j=0;j<map_rows;j++)
for (i=0;i<map_cols;i++) {
if (roads[j][i]) {
RowCol2XY(&x1,&y1,j,i);
for (k=0;k<6;k++) {
r=j;c=i;
Toward(&r,&c,k);
if (0<=r<map_rows && 0<=c<map_cols &&
roads[r][c]) {
RowCol2XY(&x2,&y2,r,c);
GrLine3(map_dc,x1,y1,0,x2,y2,0);
}
}
}
}
}
U0 DrawDots()
{
I64 i,j;
F64 x,y;
map_dc->color=BLACK;
for (j=0;j<map_rows;j++)
for (i=0;i<map_cols;i++) {
RowCol2XY(&x,&y,j,i);
GrPlot(map_dc,x,y);
}
}
U0 HexCentersCalc()
{
I64 i,j;
F64 x,y;
for (j=0;j<map_rows;j++)
for (i=0;i<map_cols;i++) {
x=(2*HEX_SIDE+2*DCOS)*i+HEX_SIDE/2+DCOS;
if (j&1)
x+=HEX_SIDE+DCOS;
y=DSIN*(j+1);
hex_centers[j][i].x=x;
hex_centers[j][i].y=y;
}
}
U0 InitMap()
{
HexCentersCalc;
DrawHexes;
MemSet(terrain,PLAINS,sizeof(terrain));
MemSet(roads,FALSE,sizeof(roads));
MemSet(rivers,FALSE,sizeof(rivers));
MemSet(vis_map,FALSE,sizeof(vis_map));
MakeTerrain(MOUNTAINS,0.03*map_cols*map_cols,5,35);
MakeTerrain(TREES,0.03*map_cols*map_cols,5,35);
DrawTerrain;
MakeRivers;
DrawRivers;
MakeRoads;
DrawRoads;
DrawDots;
}
U0 InitUnits()
{
I64 i,j,row,col,type;
Unit *tmpu;
MemSet(units,0,sizeof(units));
alive_cnt[0]=alive_cnt[1]=MAX_UNITS;
for (j=0;j<2;j++)
for (i=0;i<alive_cnt[j];i++) {
tmpu=&units[j][i];
tmpu->player=j;
tmpu->num=i;
tmpu->life=100;
tmpu->facing=RandU16%6;
if (!j) {
if (i>=MAX_UNITS/2) {
if (i>=15*MAX_UNITS/16)
type=UT_ARTILLERY;
else
type=UT_INFANTRY;
} else {
if (i>=MAX_UNITS/4)
type=UT_MD_TANK;
else
type=UT_LT_TANK;
}
} else {
if (i>=MAX_UNITS/2) {
if (i>=15*MAX_UNITS/16)
type=UT_ARTILLERY;
else
type=UT_INFANTRY;
} else {
if (i>=MAX_UNITS/4)
type=UT_MD_TANK;
else
type=UT_LT_TANK;
}
}
tmpu->type=type;
switch (type) {
case UT_INFANTRY:
tmpu->infantry=TRUE;
tmpu->indirect_fire=FALSE;
tmpu->armor =0;
tmpu->armored_attack =15;
tmpu->unarmored_attack=180;
tmpu->accuracy=45;
tmpu->range =5;
tmpu->movement=4;
tmpu->img =$IB,"<1>",BI=1$;
break;
case UT_ARTILLERY:
tmpu->infantry=TRUE;
tmpu->indirect_fire=TRUE;
tmpu->armor =0;
tmpu->armored_attack =60;
tmpu->unarmored_attack=180;
tmpu->accuracy=25;
tmpu->range =20;
tmpu->movement=2;
tmpu->img =$IB,"<2>",BI=2$;
break;
case UT_LT_TANK:
tmpu->infantry=FALSE;
tmpu->indirect_fire=FALSE;
tmpu->armor =30;
tmpu->armored_attack =40;
tmpu->unarmored_attack=60;
tmpu->accuracy=25;
tmpu->range =8;
tmpu->movement=24;
tmpu->img =$IB,"<3>",BI=3$;
break;
case UT_MD_TANK:
tmpu->infantry=FALSE;
tmpu->indirect_fire=FALSE;
tmpu->armor =60;
tmpu->armored_attack =60;
tmpu->unarmored_attack=80;
tmpu->accuracy=25;
tmpu->range =12;
tmpu->movement=16;
tmpu->img =$IB,"<4>",BI=4$;
break;
}
do {
row=RandU32%map_rows;
col=RandU32%(map_cols/3);
if (j)
col+=2*map_cols/3;
} while (UnitFind(row,col));
tmpu->row=row;
tmpu->col=col;
LBts(&tmpu->vis[cur_player],0);
}
}
U0 ViewPlayerSet(I8 p)
{
CMenuEntry *tmpse;
view_player=p;
if (tmpse=MenuEntryFind(Fs->cur_menu,"View/Player1"))
tmpse->checked= view_player==0;
if (tmpse=MenuEntryFind(Fs->cur_menu,"View/Player2"))
tmpse->checked= view_player==1;
}
U0 Init()
{
DocClear;
"GameSeed(0x%X)\n",Seed(PopUpGetI64("GameSeed(0x%X):",Seed));
moving_unit=NULL;
InitMap;
ViewPlayerSet(cur_player=0);
enemy_player=1;
if (map_width<GR_WIDTH) {
x0=(MAP_WIDTH-map_width)>>1;
y0=(MAP_HEIGHT-map_height)>>1+FONT_HEIGHT;
} else {
x0=0;
y0=FONT_HEIGHT;
}
InitUnits;
QueInit(&indirect_head);
turn=0;
fire_radius=0;
show_vis_row=-1;
show_vis_col=-1;
*msg_buf=0;
msg_off_timeout=0;
phase=PHASE_END;
}
U0 CleanUp()
{
QueDel(&indirect_head,TRUE);
}
U0 PlayerPick(U8 *dirname,I64 player)
{
I64 i=0;
U8 *st;
CDirEntry *tmpde,*tmpde1,*tmpde2;
CDoc *doc=DocNew;
Bool *old_silent=Silent;
st=MStrPrint("%s/*.HC*",dirname);
tmpde=FilesFind(st);
Free(st);
tmpde2=FilesFind("~/ToTheFront/*.HC*");
tmpde1=tmpde;
Silent(old_silent);
DocPrint(doc,"Player %d Type\n\n$$LTBLUE$$",player+1);
while (tmpde1) {
if (!(i++&3))
DocPrint(doc,"\n");
st=StrNew(tmpde1->name);
FileExtRem(st);
tmpde1->user_data=DocPrint(doc,"$$MU-UL,\"%-10ts\",LE=%d$$ ",st,tmpde1);
Free(st);
tmpde1=tmpde1->next;
}
tmpde1=tmpde2;
while (tmpde1) {
if (!(i++&3))
DocPrint(doc,"\n");
st=StrNew(tmpde1->name);
FileExtRem(st);
tmpde1->user_data=DocPrint(doc,"$$MU-UL,\"%-10ts\",LE=%d$$ ",st,tmpde1);
Free(st);
tmpde1=tmpde1->next;
}
DocPrint(doc,"\n\n\n$$FG$$Create your own AI in ~/ToTheFront.");
while ((tmpde1=PopUpMenu(doc))<=0);
ExeFile(tmpde1->full_name);
DocDel(doc);
DirTreeDel(tmpde);
DirTreeDel(tmpde2);
ExePrint("player_indirect[%d]=&PlayerIndirect;"
"player_move[%d]=&PlayerMove;"
"player_direct[%d]=&PlayerDirect;",
player,player,player);
}
L ÿÿÿÿüÿÿÿ úÿÿÿ üÿÿÿúÿÿÿþÿÿÿ
øÿÿÿ üÿÿÿüÿÿÿ
ûÿÿÿûÿÿÿûÿÿÿ
ûÿÿÿ
ûÿÿÿ
ûÿÿÿûÿÿÿûÿÿÿ
üÿÿÿüÿÿÿ
üÿÿÿüÿÿÿG ÿÿÿÿýÿÿÿ
üÿÿÿ
þÿÿÿüÿÿÿþÿÿÿ
úÿÿÿÏ þÿÿÿþÿÿÿ
ÿÿÿÿýÿÿÿýÿÿÿ
ÿÿÿÿüÿÿÿüÿÿÿ
üÿÿÿ
ýÿÿÿ
þÿÿÿûÿÿÿûÿÿÿ
ýÿÿÿüÿÿÿ
þÿÿÿýÿÿÿþÿÿÿüÿÿÿ
ýÿÿÿýÿÿÿýÿÿÿ
ýÿÿÿ

ÿÿÿÿÿÿÿÿ
+121
View File
@@ -0,0 +1,121 @@
U0 Toward(I64 *_row,I64 *_col,I64 direction)
{
switch (direction) {
case 0:
*_row-=2;
break;
case 1:
if (*_row&1) *_col+=1;
*_row-=1;
break;
case 2:
if (*_row&1) *_col+=1;
*_row+=1;
break;
case 3:
*_row+=2;
break;
case 4:
if (!(*_row&1)) *_col-=1;
*_row+=1;
break;
case 5:
if (!(*_row&1)) *_col-=1;
*_row-=1;
break;
}
}
I64 FacingChg(I64 f1,I64 f2)
{
I64 res=(f1+6-f2)%6;
if (res>=3)
return 6-res;
else
return res;
}
U0 RowCol2XY(F64 *_x,F64 *_y,I64 row,I64 col)
{
Pt *c;
row=ClampI64(row,0,map_rows);
col=ClampI64(col,0,map_cols);
c=&hex_centers[row][col];
*_x=c->x;
*_y=c->y;
}
U0 XY2RowCol(I64 *_row,I64 *_col,F64 x,F64 y)
{
*_col=(x-DCOS/2)/(HEX_SIDE+DCOS);
if (*_col&1)
*_row=ToI64((y-DSIN)/(2*DSIN))*2+1;
else
*_row=ToI64(y/(2*DSIN))*2;
*_col>>=1;
*_row=ClampI64(*_row,0,map_rows-1);
*_col=ClampI64(*_col,0,map_cols-1);
}
Unit *UnitFind(I64 row,I64 col)
{//Finds unit in a hexagon.
I64 i,j;
for (j=0;j<2;j++)
for (i=0;i<MAX_UNITS;i++)
if (units[j][i].life>0 &&
units[j][i].row==row &&
units[j][i].col==col)
return &units[j][i];
return NULL;
}
Bool CursorInWin(CTask *task,I64 x,I64 y)
{
if (0<=x+task->scroll_x<task->pix_width &&
0<=y+task->scroll_y<task->pix_height)
return TRUE;
else
return FALSE;
}
U0 CursorUpdate(CTask *task,I64 x,I64 y)
{
if (CursorInWin(task,x,y))
XY2RowCol(&cursor_row,&cursor_col,x,y);
}
class LOSCtrl
{
I64 r1,c1,r2,c2,distance;
};
Bool LOSPlot(LOSCtrl *l,I64 x,I64 y,I64 z)
{//We got tricky and used z as the distance from the start of the line.
I64 row,col;
XY2RowCol(&row,&col,x,y);
if ((row!=l->r1 || col!=l->c1) &&
(row!=l->r2 || col!=l->c2) &&
terrain[row][col]!=PLAINS) {
if (terrain[l->r1][l->c1]==MOUNTAINS) {
if (terrain[row][col]==MOUNTAINS || z>l->distance>>1)
return FALSE;
} else if (terrain[l->r2][l->c2]==MOUNTAINS) {
if (terrain[row][col]==MOUNTAINS || z<=l->distance>>1)
return FALSE;
} else
return FALSE;
}
return TRUE;
}
Bool LOS(I64 r1,I64 c1,I64 r2,I64 c2)
{
F64 x1,y1,x2,y2;
LOSCtrl l;
RowCol2XY(&x1,&y1,r1,c1);
RowCol2XY(&x2,&y2,r2,c2);
l.r1=r1; l.c1=c1;
l.r2=r2; l.c2=c2;
l.distance=Sqrt(SqrI64(x1-x2)+SqrI64(y1-y2));
return Line(&l,x1,y1,0,x2,y2,l.distance,&LOSPlot);
}
+129
View File
@@ -0,0 +1,129 @@
U8 movement_costs[16];
movement_costs[PLAINS]=2;
movement_costs[TREES]=6;
movement_costs[MOUNTAINS]=10;
I64 HexMoveOneCost(Unit *tmpu,I64 r,I64 c,I64 facing)
{
I64 res;
if (tmpu->infantry)
res=0;
else {
res=FacingChg(facing,tmpu->facing);
if (res>0) res--;
}
if (roads[r][c] && roads[tmpu->row][tmpu->col])
res+=1;
else {
if (tmpu->infantry)
res+=2;
else {
res+=movement_costs[terrain[r][c]];
if (rivers[r][c])
res=tmpu->movement;
}
}
return res;
}
I64 HexMoveOne(I64 *_row,I64 *_col,F64 x,F64 y)
{
I64 direction,best_direction=-1,r,c;
F64 dd,best_dd,x1,y1;
RowCol2XY(&x1,&y1,*_row,*_col);
best_dd=Sqr(x1-x)+Sqr(y1-y);
for (direction=0;direction<6;direction++) {
r=*_row; c=*_col;
Toward(&r,&c,direction);
RowCol2XY(&x1,&y1,r,c);
dd=Sqr(x1-x)+Sqr(y1-y);
if (0<=r<map_rows && 0<=c<map_cols && dd<best_dd) {
best_dd=dd;
best_direction=direction;
}
}
if (best_direction>=0) {
Toward(_row,_col,best_direction);
return best_direction;
} else
return -1;
}
Bool UnitMovePlot(U0,I64 x,I64 y,I64)
{
move_x=x; move_y=y;
Sleep(5*animation_delay);
return TRUE;
}
U0 UnitMoveAnimation(Unit *tmpu,I64 r,I64 c,I64 facing)
{
F64 x1,y1,x2,y2,f=facing*60.0*ã/180.0;
moving_unit=tmpu;
RowCol2XY(&x1,&y1,tmpu->row,tmpu->col);
move_x=x1; move_y=y1;
moving=TRUE;
if (tmpu->infantry)
Snd(300);
else {
move_facing=tmpu->facing*60.0*ã/180.0;
Snd(150);
while (Wrap(f-move_facing,-ã)<=0) {
move_facing-=0.03;
Sleep(5*animation_delay);
}
while (Wrap(f-move_facing,-ã)>0) {
move_facing+=0.03;
Sleep(5*animation_delay);
}
Snd(100);
}
move_facing=f;
RowCol2XY(&x2,&y2,r,c);
Line(NULL,x1,y1,0,x2,y2,0,&UnitMovePlot);
Snd(0);
moving_unit=NULL;
moving=FALSE;
}
Bool UnitMove(Unit *tmpu,I64 x,I64 y)
{
Unit *target;
I64 r,c,r0=tmpu->row,c0=tmpu->col,i,facing;
while (tmpu->remaining_movement>0) {
r=tmpu->row;
c=tmpu->col;
if ((facing=HexMoveOne(&r,&c,x,y))<0)
break;
else {
i=HexMoveOneCost(tmpu,r,c,facing);
if (i>tmpu->movement)
i=tmpu->movement;
if (!tmpu->fired && tmpu->remaining_movement>=i &&
tmpu->remaining_movement>=tmpu->movement>>1 &&
(target=UnitFind(r,c)) && target->player!=tmpu->player &&
tmpu->infantry!=target->infantry) {
if (!HexOccupy(ToBool(target->infantry),tmpu,target)) {
tmpu=NULL;
break;
}
i=tmpu->remaining_movement;
}
if (tmpu->remaining_movement>=i && !UnitFind(r,c)) {
UnitMoveAnimation(tmpu,r,c,facing);
tmpu->facing=facing;
tmpu->remaining_movement-=i;
tmpu->row=r;
tmpu->col=c;
VisRecalc(VR_UPDATE_FRIENDLY_UNIT,tmpu);
LBEqu(&tmpu->vis[enemy_player],0,
VisRecalc(VR_ONE_ENEMY_UNIT,tmpu));
} else
break;
}
}
if (!tmpu || tmpu->row!=r0 || tmpu->col!=c0)
return TRUE;
else
return FALSE;
}
+223
View File
@@ -0,0 +1,223 @@
#define VR_ONE_FRIENDLY_UNIT 0
#define VR_UPDATE_FRIENDLY_UNIT 1
#define VR_FRIENDLY_UNIT_DIED 3
#define VR_ONE_ENEMY_UNIT 4
#define VR_ALL_UNITS 5
class MPCtrl1
{
I64 mode,lo,hi;
Unit *tmpu;
};
class MPCtrl2
{
I64 lo,hi,row,col;
};
U0 VRSetUp(I64 player)
{
I64 i;
Unit *ut0,*ut1;
ut0=&units[player][0];
ut1=&units[player^1][0];
for (i=0;i<MAX_UNITS;i++,ut0++,ut1++) {
LBtr(&ut1->vis[player],0);
LBEqu(&ut0->vis[player],0,ut0->life>0);
}
}
U0 VRMerge(I64 player)
{
I64 i,j;
Unit *ut1;
U8 *dst,*src,*mask=CAlloc((MAX_UNITS+7)>>3);
for (j=0;j<MAX_UNITS;j++) {//p0
src=&vis_unit_bitmap[player][(((MAX_UNITS+7)&~7)*j)>>3];
dst=mask;
for (i=0;i<(MAX_UNITS+7)>>3;i++) //player1
*dst++|=*src++;
}
ut1=&units[player^1][0];
for (j=0;j<MAX_UNITS;j++,ut1++)
LBEqu(&ut1->vis[player],0,Bt(mask,j) && ut1->life>0);
Free(mask);
}
Bool MPVisRecalc(MPCtrl1 *job)
{
Bool res=FALSE,seen;
I64 i,j,row,col;
F64 x1,y1,x2,y2,dd,range;
Unit *ut0,*ut1;
ut0=&units[cur_player][job->lo];
ut1=&units[enemy_player][job->lo];
if (job->tmpu) {
row=job->tmpu->row;
col=job->tmpu->col;
range=job->tmpu->range*2*HEX_RADIUS;
range*=range;
}
switch (job->mode) {
case VR_UPDATE_FRIENDLY_UNIT:
case VR_ONE_FRIENDLY_UNIT:
if (job->mode==VR_UPDATE_FRIENDLY_UNIT)
range=MAX_F64;
RowCol2XY(&x1,&y1,row,col);
for (i=job->lo;i<job->hi;i++,ut1++) {
seen=FALSE;
if (ut1->life>0 &&
LOS(row,col,ut1->row,ut1->col)) {
RowCol2XY(&x2,&y2,ut1->row,ut1->col);
dd=Sqr(x2-x1)+Sqr(y2-y1);
if (dd<range) {
seen=TRUE;
LBts(&ut1->vis[cur_player],0);
}
}
if (job->mode==VR_UPDATE_FRIENDLY_UNIT)
LBEqu(&vis_unit_bitmap[cur_player],
i+job->tmpu->num*((MAX_UNITS+7)&~7),seen);
}
break;
case VR_ONE_ENEMY_UNIT:
RowCol2XY(&x1,&y1,row,col);
for (i=job->lo;i<job->hi;i++,ut1++)
if (ut1->life>0 &&
LOS(row,col,ut1->row,ut1->col)) {
LBts(&vis_unit_bitmap[enemy_player],
job->tmpu->num+i*((MAX_UNITS+7)&~7));
res=TRUE;
} else
LBtr(&vis_unit_bitmap[enemy_player],
job->tmpu->num+i*((MAX_UNITS+7)&~7));
break;
case VR_ALL_UNITS:
ut0=&units[cur_player][0];
for (i=0;i<MAX_UNITS;i++,ut0++)
if (ut0->life>0) {
RowCol2XY(&x1,&y1,ut0->row,ut0->col);
ut1=&units[enemy_player][job->lo];
for (j=job->lo;j<job->hi;j++,ut1++) {
if (ut1->life>0 &&
LOS(ut0->row,ut0->col,ut1->row,ut1->col)) {
LBts(&ut1->vis[cur_player],0);
LBts(&vis_unit_bitmap[cur_player],j+i*((MAX_UNITS+7)&~7));
} else
LBtr(&vis_unit_bitmap[cur_player],j+i*((MAX_UNITS+7)&~7));
}
} else
for (j=job->lo;j<job->hi;j++)
LBtr(&vis_unit_bitmap[cur_player],j+i*((MAX_UNITS+7)&~7));
ut0=&units[enemy_player][0];
for (i=0;i<MAX_UNITS;i++,ut0++)
if (ut0->life>0) {
RowCol2XY(&x1,&y1,ut0->row,ut0->col);
ut1=&units[cur_player][job->lo];
for (j=job->lo;j<job->hi;j++,ut1++) {
if (ut1->life>0 &&
LOS(ut0->row,ut0->col,ut1->row,ut1->col)) {
LBts(&ut1->vis[enemy_player],0);
LBts(&vis_unit_bitmap[enemy_player],j+i*((MAX_UNITS+7)&~7));
} else
LBtr(&vis_unit_bitmap[enemy_player],j+i*((MAX_UNITS+7)&~7));
}
} else
for (j=job->lo;j<job->hi;j++)
LBtr(&vis_unit_bitmap[enemy_player],j+i*((MAX_UNITS+7)&~7));
break;
}
return res;
}
Bool VisRecalc(I64 mode,Unit *tmpu=NULL)
{
I64 i,hi,k,cnt;
Bool res;
/*The compiler doesn't go out of it's way
to know if something is const.;-) This
just compiles with the val at compile
time, an advantage of just-in-time over
AOT binaries. TempleOS has a limited
stk size, so don't get in the habit.
$LK,"MAlloc",A="MN:MAlloc"$() would probably be the better choice.
*/
MPCtrl1 job[mp_cnt];
CSrvCmd *cmd[mp_cnt];
if (mode==VR_FRIENDLY_UNIT_DIED) {
MemSet((&vis_unit_bitmap[enemy_player])(U8 *)+
(tmpu->num*((MAX_UNITS+7)&~7))>>3,0,(MAX_UNITS+7)>>3);
VRMerge(enemy_player);
return 0; //Return any value--don't care
}
cnt=mp_cnt; //Cores
hi=MAX_UNITS;
if (mode==VR_ONE_ENEMY_UNIT) {
for (hi--;hi>=0;hi--)
if (units[enemy_player][hi].life>0)
break;
hi++;
}
k=hi;
if (hi/mp_cnt<2)
cnt=1;
for (i=0;i<cnt;i++) {
job[i].mode=mode;
job[i].tmpu=tmpu;
job[i].hi=k;
k-=hi/cnt;
if (k<0) k=0;
if (i==cnt-1) k=0;
job[i].lo=k;
}
res=FALSE;
for (i=0;i<cnt;i++)
cmd[i]=JobQue(&MPVisRecalc,&job[i],i,0);
for (i=0;i<cnt;i++)
if (JobResGet(cmd[i]))
res=TRUE;
if (mode==VR_UPDATE_FRIENDLY_UNIT)
VRMerge(cur_player);
return res;
}
U0 MPVisRecalcMap(MPCtrl2 *job)
{
I64 i,j;
for (j=job->lo;j<job->hi;j++)
for (i=0;i<map_cols;i++)
if (LOS(job->row,job->col,j,i))
vis_map[j][i]=TRUE;
else
vis_map[j][i]=FALSE;
}
U0 VisRecalcMap(I64 row,I64 col)
{
I64 i,hi,k,cnt;
MPCtrl2 job[mp_cnt];
CSrvCmd *cmd[mp_cnt];
cnt=mp_cnt; //Cores
hi=map_rows;
k=hi;
if (hi/mp_cnt<2)
cnt=1;
for (i=0;i<cnt;i++) {
job[i].row=row;
job[i].col=col;
job[i].hi=k;
k-=hi/cnt;
if (k<0) k=0;
if (i==cnt-1) k=0;
job[i].lo=k;
}
for (i=0;i<cnt;i++)
cmd[i]=JobQue(&MPVisRecalcMap,&job[i],i,0);
for (i=0;i<cnt;i++)
JobResGet(cmd[i]);
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff