MCPcopy Index your code
hub / github.com/assaultcube/AC / modifyfvar

Function modifyfvar

source/src/command.cpp:1380–1415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1378void diveq(char *name, int *arg) { modifyvar(name, *arg, '/'); } COMMANDN(div=, diveq, "si");
1379
1380void modifyfvar(const char *name, float arg, char op)
1381{
1382 ident *id = idents->access(name);
1383 if(!id) return;
1384 if(identaccessdenied(id))
1385 {
1386 conoutf("not allowed in this execution context: %s", id->name);
1387 scripterr();
1388 return;
1389 }
1390 if((id->type == ID_VAR && id->minval > id->maxval) || (id->type == ID_FVAR && id->minvalf > id->maxvalf)) { conoutf("variable %s is read-only", id->name); return; }
1391 float val = 0;
1392 switch(id->type)
1393 {
1394 case ID_VAR: val = *id->storage.i; break;
1395 case ID_FVAR: val = *id->storage.f; break;
1396 case ID_SVAR: { { if(id->getfun) ((void (__cdecl *)())id->getfun)(); } val = atof(*id->storage.s); break; }
1397 case ID_ALIAS: val = atof(id->action); break;
1398 default: return;
1399 }
1400 switch(op)
1401 {
1402 case '+': val += arg; break;
1403 case '-': val -= arg; break;
1404 case '*': val *= arg; break;
1405 case '/': val = (arg == 0.0f) ? 0 : val / arg; break;
1406 }
1407 switch(id->type)
1408 {
1409 case ID_VAR: *id->storage.i = clamp((int)val, id->minval, id->maxval); break;
1410 case ID_FVAR: *id->storage.f = clamp(val, id->minvalf, id->maxvalf); break;
1411 case ID_SVAR: *id->storage.s = exchangestr(*id->storage.s, floatstr(val)); break;
1412 case ID_ALIAS: alias(name, floatstr(val)); return;
1413 }
1414 if(id->fun) ((void (__cdecl *)())id->fun)();
1415}
1416
1417void addeqf(char *name, float *arg) { modifyfvar(name, *arg, '+'); } COMMANDN(+=f, addeqf, "sf");
1418void subeqf(char *name, float *arg) { modifyfvar(name, *arg, '-'); } COMMANDN(-=f, subeqf, "sf");

Callers 4

addeqfFunction · 0.85
subeqfFunction · 0.85
muleqfFunction · 0.85
diveqfFunction · 0.85

Calls 7

identaccessdeniedFunction · 0.85
scripterrFunction · 0.85
exchangestrFunction · 0.85
floatstrFunction · 0.85
aliasFunction · 0.85
accessMethod · 0.80
conoutfFunction · 0.70

Tested by

no test coverage detected